Open baerrach opened 5 years ago
The discourse topic https://discourse.aurelia.io/t/aurelia-testing-with-jasmine-karma-fails/1629 is probably out of date too but I found it while looking at solutions to the failures.
I get the same error when trying the custom attribute section.
FAIL src/my-attribute.spec.js (5.785s)
● Console
console.error internal/process/next_tick.js:68
{ Error: Cannot find module 'C:\path\to\project\test\unit\src\my-attribute' from 'aurelia-loader-nodejs.js'
The problem with this one is that jest and karma have different base setups.
So when you scaffold a fresh project with Karma as unit tester the configuration's basePath
in karma-conf.js
is pointing to empty. That means you're starting your import routes respectively from the root of your project so you need to add src
.
If we remove the infobox all will still work for jest users, but karma users will be buffled why nothing works. @3cp any ideas how to go on with this? I see there would be quite some changes involved to modify Karma's default to use src as a base and frankly I think the Karma setup is even nicer compared to Jest because I personally feel that it's more clear that you're always kinda starting from the root of your project-folder
I'd love to see docs on setting up Karma, and in fact expected to see that as I've been reading from front-to-back the documentation and I vaguely remember the bias to Karma over Jest. Yet now that I go to find a reference to support that I can't find it. Maybe its in one of the videos I've watched, or some blog post of Rob's.
I've really appreciated the extra level of detail that Aurelia has on ensuring not just the code is working but the surrounding software development practices as well. And providing an opinionated view on how to solve these problems. It's has been useful as a rosetta stone to take the practices I would normally use in a Java project and map them into Aurelia. Other JavaScript frameworks haven't gone this extra mile when writing their documentation.
I'm submitting a bug report https://aurelia.io/docs/testing/components#testing-a-custom-element
Current behavior: After running
au new
and pasting in the examples from the testing component page they fail with the errorExpected/desired behavior:
It should be looking for the component in
src/my-component
and nottest/unit/src/my-component
Changing the line
Fixed the problem.
Note there is an info box for Karma that says "If you are using
karma
and your configuration already has a path for'*': 'src/*'
set you may not need to usesrc/
, and justmy-component
." It looks like for the default out-of-the-box that thesrc/
prefix is not needed now for the default Jest configuration.