Skip to content
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

Testing Components is out of sync with latest Aurelia #441

Open
baerrach opened this issue Jul 15, 2019 · 5 comments · May be fixed by #442
Open

Testing Components is out of sync with latest Aurelia #441

baerrach opened this issue Jul 15, 2019 · 5 comments · May be fixed by #442

Comments

@baerrach
Copy link
Contributor

I'm submitting a bug report
https://aurelia.io/docs/testing/components#testing-a-custom-element

  • Library Version:
    "aurelia-cli": "^1.0.2",

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 added a commit to baerrach/documentation that referenced this issue Jul 15, 2019
Removed inform box specific to Karma as there is no documentation at all about
how to set Karma up.

Fixes aurelia#441
@baerrach
Copy link
Contributor Author

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
Copy link
Contributor Author

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'

baerrach added a commit to baerrach/documentation that referenced this issue Jul 15, 2019
@zewa666
Copy link
Member

zewa666 commented Jul 15, 2019

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
Copy link
Contributor Author

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
Copy link
Member

3cp commented Jul 16, 2019

#442 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants