-
Notifications
You must be signed in to change notification settings - Fork 142
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
Add support for concurrent test runners (ava)? #131
Comments
I'm not 100% sure it doesn't work, I've done some small samples with testdouble and ava and didn't hit any issues but probably because my tests didn't overlap very much. I'll have to see if I can reproduce an error in a test suite. |
Let's close for now until someone somewhere runs into a real (as opposed to speculative) problem. |
Here's an example failing test case where ava concurrency clashes with const test = require('ava');
const td = require('testdouble');
const foo = {
bar: function() {
return this.baz()
},
baz: function() {
return 'baz';
}
};
test.beforeEach(t => {
td.replace(foo, 'baz');
});
test.afterEach(t => {
td.reset();
});
test('async delay', t => {
t.plan(1);
td.when(foo.baz()).thenReturn('fake');
return new Promise((resolve, reject) => {
setTimeout(resolve(), 1000);
})
.then(() => {
t.is(foo.bar(), 'fake');
});
});
test('accidentally overwrites stub', t => {
t.plan(1);
td.when(foo.baz()).thenReturn('faketoo');
t.is(foo.bar(), 'faketoo');
}); When |
Thanks @ackerdev -- that gives me some insight to think on how (and whether) to undertake what we'd need to do to support parallel tests |
I've given more thought to this and I still don't have any good proposals. My thoughts follow. Global stateThere are several aspects of td's API design that rely on global state:
So the first two instances are examples of td.js mutating state of things it doesn't own, and the final two describe td.js's internal storage of the state of known test double functions. What can we do?If the question is "how do we use td.js with a concurrent test runner?", the answer must be in two parts:
Ava-specific advice(FWIW, this has been raised with respect to Sinon as well) Now, one thing Ava does that is interesting is that it forks each test file into a separate operating system process. If every single test were split into its own process, all these problems would go away, since there'd be a separate global state for each. Thinking more about Ava-specific fixes to this issue, these seem like one's options:
I think the above Ava-specific options are all worth thinking about, but I don't think there's anything the library can do to solve the |
See https://www.npmjs.com/package/forking-tap for inspiration ;) |
Perhaps instead of the common pattern of:
An additional pattern similar to:
Could be supported?
The text was updated successfully, but these errors were encountered: