Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.only runs all tests with same name #299

Closed
jtlapp opened this issue Jul 17, 2016 · 6 comments
Closed

.only runs all tests with same name #299

jtlapp opened this issue Jul 17, 2016 · 6 comments
Labels

Comments

@jtlapp
Copy link
Contributor

jtlapp commented Jul 17, 2016

I have a fix for this already, just wanted to give it an issue # before PRing.

.only identifies the test to run by the name of the test. If the developer (accidentally) writes multiple tests with the same name and one of those tests is declared .only, all tests having this duplicated name are run.

There are two main approaches to solving this. We can enforce test name uniqueness, or we can generate a unique ID for each test and use that ID. The former would be helpful to the developer, but the latter is simpler, faster, and makes a good setup for a desperately needed feature whereby we can run a single test without having to muck with the code. (I'll post this feature shortly.)

@jtlapp
Copy link
Contributor Author

jtlapp commented Jul 17, 2016

Can someone make sure my fix doesn't introduce a race condition? A race condition could potentially happen if multiple test modules are loaded asynchronously AND the increment operator is not atomic. We might then have multiple tests with the same ID. See line 48 of lib/test.js.

@jtlapp
Copy link
Contributor Author

jtlapp commented Jul 17, 2016

This SO answer says that ++ is not guaranteed to be atomic, so the next question is, does tape otherwise support asynchronous loading? http://stackoverflow.com/questions/680097/ive-heard-i-isnt-thread-safe-is-i-thread-safe/680114#680114

@ljharb
Copy link
Collaborator

ljharb commented Jul 18, 2016

That's in C++ - JS is single-threaded. You don't have to worry about it.

@jtlapp
Copy link
Contributor Author

jtlapp commented Jul 18, 2016

Ah yes! Thanks for the reminder. I actually program in Java for Android too, where I have to worry about these things.

I've written a way to pass a command line -n to indicate the number of a test to run, with -n adding test numbers to the test titles. However, I'm having trouble writing the test suite. I've emulated test/require.js for my tests, but I keep getting the following:

Warning: Possible EventEmitter memory leak detected. 11 close listeners added. Use emitter.setMaxListeners() to increase limit

Any suggestions for me? Then I'll write the feature request and make its PR. Thanks!

@jtlapp
Copy link
Contributor Author

jtlapp commented Jul 18, 2016

(My end event is being called, but not the data event. Code is otherwise directly analogous to test/require.js and test/require/*.js, as far as I can tell.)

@jtlapp
Copy link
Contributor Author

jtlapp commented Jul 18, 2016

(Okay, nevermind. My -n broke streaming, so gotta look at that.)

@ljharb ljharb added the bug label Aug 2, 2016
@ljharb ljharb closed this as completed in 87ee0ac Aug 2, 2016
ljharb added a commit that referenced this issue Sep 30, 2016
 - [Fix] `throws`: only reassign “message” when it is not already non-enumerable (#320)
 - [Fix] show path for error messages on windows (#316)
 - [Fix] `.only` should not run multiple tests with the same name (#299, #303)
 - [Deps] update `glob`, `inherits`
 - [Dev Deps] update `concat-stream`, `tap`, `tap-parser`, `falafel`
 - [Tests] [Dev Deps] Update to latest version of devDependencies tap (v7) and tap-parser (v2) (#318)
 - [Tests] ensure the max_listeners test has passing output
 - [Docs] improvements (#298, #317)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants