-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Running angular-mocks tests concurrently #13971
Comments
We have no plans to support concurrent testing and so AVA is probably not something that is going to work with AngularJS. |
Hm, ok that's too bad. Concurrent tests can really speed up test runs. I guess the reason for this is that effort on new things like this is being put into Angular 2 now? |
Thanks for the suggestion for karma, but I'm trying a minimal testing setup (trying to avoid too many tools). AVA is both the test framework and the runner. I've found a workaround for the issue to still maintain concurrency - running the - global.window.afterEach = test.afterEach;
+ global.window.afterEach = test.after; |
@kentcdodds long shot but I've seen some of your projects have included AVA lately and I know you know Angular, do you have any input on this? |
I think if you try to retrofit Angular tests to work with ava, you're going to have a hard time I'm afraid. But I've never tried. |
Note, main reason for this is ava does not support running tests in the browser. And Angular 1 needs the browser APIs to be tested reliably. You could, however, write many of your services in vanilla JS, and test those in isolation..... |
I'm running Angular in jsdom to emulate the browser environment: https://gist.github.com/karlhorky/6e68101d8167be27e027 The issue is mainly just |
I'm not familiar with AVA, but is the problem really that |
I'm still learning how AVA works as well, but in my first few directive unit tests, the shared state itself doesn't appear to cause problems in the concurrent tests. I'm still able to initialize the module and inject services and providers like usual. The tests seem to run just like mocha. The issue appears to be the following sequence: window.afterEach = test.afterEach;
When I set the window.afterEach = test.after;
|
@sindresorhus @jamestalmage any feedback on running angular.js/src/ngMock/angular-mocks.js Lines 2565 to 2619 in 72b96ef
My setup: https://gist.github.com/karlhorky/6e68101d8167be27e027 |
If all concurrent tests share the same Possible issues (off the top of my head):
|
Yeah, it's these global state things that make testing complex that ava is striving to solve by isolating tests from one another. You'll probably be able to make it work with enough work, but personally, I don't know whether it's worth the effort to get ava and angular to play nice. |
My advice would be to write the majority of your services as ES2015/CommonJS modules with no Angular related dependencies, and move as much of your code in there as possible. For modules that must use Angular APIs and are affected by Angulars global state, use This advice could be adapted to apply to any app built on any framework. |
@gkalpak ah ok, thanks for the explanation. I think I'm starting to understand what the difficulties could be here. I wonder if there would be a way to isolate tests to avoid side effects like these. Maybe I'd need to move the tests needing isolation into separate files (AVA provides an isolated environment for each test file). I would just do the injection and mocking manually in an isolated way, but I don't think I quite understand Maybe @kentcdodds is right and it's not worth the effort. ...On the other hand, concurrent tests written in ES2015+ are pretty appealing... |
@jamestalmage hm, that's an interesting approach, thanks. I'll have to think about how I could rearchitect my module structure for something like that. Currently all of my ES2015 modules include code attaching to angular modules and injecting dependencies using the injector. |
If you use |
Sounds like a good candidate for a recipe. |
Closing as we are not going to change Angular to fix this issue. |
I've been playing around with testing Angular directives in the AVA concurrent test runner and I've run into issues with getting the tests running concurrently. It appears
angular-mocks
rewrites variables in theafterEach()
method, causing property reference errors:Partial test setup
Command line output (annotated with comment lines)
Relevant code from
angular-mocks
Rewriting the tests to execute serially works around this error (but loses the nice property of concurrency):
A full example including failing and working cases here:
https://gist.github.com/karlhorky/6e68101d8167be27e027
Is concurrent tests something that the angular team is interested in supporting? If not, are there any other workarounds for getting
angular-mocks
running concurrently?angular.js v. 1.5.0
angular-mocks v. 1.5.0
The text was updated successfully, but these errors were encountered: