I'm setting up Karma and Protractor tests for the first time. Following John Papa's style guide, unit test files are alongside the files they're testing, so for example: login.controller.js, login.controller.spec.js
However, if I'm adding a protractor test file I'd want to call it something like login.spec.js
. (this is all for the login module)
What is the standard convention for naming to distinguish which test files are Karma unit tests and which are Protractor e2e tests?
It is not about actual file names - it is about where your specs are located.
It is a good idea to have your unit tests right near the actual code they are testing and related to, make them close to the "unit" under test, cause, these are unit tests.
On the other hand, end-to-end tests are entities of a much higher level of abstraction - e2e spec files should be located away from the actual code, in a special directory. Personally, I like the idea to have a "test" folder under the project root. This is a directory structure we've agreed to have inside the team (simplified):
- root
- src
- components
- header
header-controller.js
header-controller_test.js
- test
- e2e
- config
local.conf.js
remote.conf.js
- specs
- screen1
screen1.blabla.spec.js
- po
screen1.po.js
karma.local.conf.js
karma.remote.conf.js
Where specs
directory contains all of the end-to-end spec files, while po
- page objects for every page, or part of a page of the application.
This is quite opinion based but I think deserving of an answer as I have had a similar issue in the past.
From my experience, I have used the same login.spec.js
but inside an e2e folder at the root.
The reason being although in this instance you might be running an end to end test for the login module, as a general rule the end to end tests will be running integration style tests across multiple controllers/services/views. The nature of these tests make them difficult to keep to a one-to-one file relationship like you may do with the unit tests.
eg There is no reason why you may not also have a protractor test that logs in, then changes some details on an account, then logs out.
In this situation, the e2e test wouldn't make sense to live in either the account or login module directories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With