aurelia / documentation

The documentation for Aurelia.
MIT License
105 stars 111 forks source link

Testing Components is out of sync with latest Aurelia #441

Open baerrach opened 5 years ago

baerrach commented 5 years ago

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 error

 FAIL  src/my-component.spec.js (5.961s)
  ● Console

    console.error internal/process/next_tick.js:68
      { Error: Cannot find module 'C:\path\to\project\test\unit\src\my-component' from 'aurelia-loader-nodejs.js'

Expected/desired behavior:

It should be looking for the component in src/my-component and not test/unit/src/my-component

Changing the line

-  .withResources('src/my-component')
+  .withResources('my-component')

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 use src/, and just my-component." It looks like for the default out-of-the-box that the src/ prefix is not needed now for the default Jest configuration.

baerrach commented 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.

baerrach commented 5 years ago

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'
zewa666 commented 5 years ago

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

baerrach commented 5 years ago

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.

3cp commented 5 years ago

https://github.com/aurelia/documentation/pull/442#issuecomment-512026320