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

fix(jest): Sass require in html #1068

Closed
wants to merge 1 commit into from

Conversation

michaelw85
Copy link
Contributor

@michaelw85 michaelw85 commented Mar 4, 2019

Fix error when testing a component that has a require tag with a
sass file.

Closes aurelia/testing#67

Fix error when testing a component that has a require tag with a
sass file.

Closes aurelia#67
@3cp
Copy link
Member

3cp commented Mar 4, 2019

There is the other generic jest recommended way. https://jestjs.io/docs/en/webpack#handling-static-assets

If don't want to write the mock module, can use https://github.com/eddyerburgh/jest-transform-stub

@michaelw85
Copy link
Contributor Author

@huochunpeng Thank you for the info, I will try that proxy setup. If it resolves this issue I will change this PR.

@michaelw85
Copy link
Contributor Author

@huochunpeng I've looked at the documentation and this setup only works for static content loaded via import statements in your js/ts files. The issue reported describes a flow where a sass file is loaded using a <required from="./style.scss"> tag. This results in aurelia-loader, aurelia-templating-resources (css-resource.js fixupCSSUrls) to handle the file which fails for sass files.

@3cp
Copy link
Member

3cp commented Mar 6, 2019

:-)
You should check. It works. https://github.com/huochunpeng/demo-au-jest-scss

Removing ".+\\.scss$": "jest-transform-stub" from package.json will make it fail.

Even with <require> in html, in jest testing, aurelia-loader-nodejs will use nodejs to load the resource anyway.

@michaelw85
Copy link
Contributor Author

Thank you for the example, I will give it another try. I think I missed the transform entry in the config :/

@michaelw85
Copy link
Contributor Author

@huochunpeng I can confirm installing jest-transform-stub and adding it as a custom transform entry there is no need for the change in this PR. Do you think we should/could provide this solution out of the box in aurelia cli?

@3cp
Copy link
Member

3cp commented Mar 7, 2019

Do you think we should/could provide this solution out of the box in aurelia cli?

Absolutely. Let’s get it in after the big refactoring PR.

@michaelw85
Copy link
Contributor Author

@huochunpeng ok I will close this PR and create a new one after the big refactor PR is done. Where can I track the status of the PR you are referring to?

@michaelw85 michaelw85 closed this Mar 7, 2019
@michaelw85 michaelw85 deleted the 67_jest_component_sass branch March 7, 2019 08:13
@3cp
Copy link
Member

3cp commented Mar 7, 2019

#1069

@michaelw85
Copy link
Contributor Author

Some additional info on stubbing, for me it still fails when adding jest-tranform-stub to the moduleNameMapper. Only adding it to transform seems to work fine (haven't testing imports from TS yet)

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 this pull request may close these issues.

2 participants