Skip to content

Relative imports inside scss global resources throw error #374

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

Open
pmrotule opened this issue Aug 12, 2021 · 2 comments · Fixed by #373
Open

Relative imports inside scss global resources throw error #374

pmrotule opened this issue Aug 12, 2021 · 2 comments · Fixed by #373

Comments

@pmrotule
Copy link
Contributor

pmrotule commented Aug 12, 2021

When importing relative paths inside a stylesheet being made globally available using the option jest.globals['vue-jest'].resources, the test will fail with the following error:

image

Considering the following

{
  "jest": {
    "globals": {
      "vue-jest": {
        "resources": {
          "scss": [
            "./src/styles/settings/breakpoints.scss",
            "./src/styles/settings/colors.scss",
            "./src/styles/settings/unit.scss",
          ],
        }
      }
    }
  }
}

src/styles/settings/breakpoints.scss

@import './unit.scss';

$breakpoint-mobile: 450px;
$breakpoint-tablet: 768px;
$breakpoint-desktop: 1200px;

:export {
  mobile: strip-unit($breakpoint-mobile);
  tablet: strip-unit($breakpoint-tablet);
  desktop: strip-unit($breakpoint-desktop);
}

and considering that src/styles/settings/unit.scss exists, it should be able to find it.

Version

I'm using version 4.0.1, but I had the same issue when downgrading to 3.0.7.

Steps to reproduce

Run the test in this repository: https://github.com/pmrotule/vue-jest-global-resources-bug

Moreover, the test only started failing when I added CSS modules to HelloWorld.vue (<style lang="scss" module>) so it seems to be both related to vue-jest not resolving relative paths properly + using CSS modules.

@pmrotule
Copy link
Contributor Author

@lmiller1990 It would be greatly appreciated if you could find time to review the issue and PR. It's currently blocking my team... I provided a repository to reproduce the issue and a PR to fix it.

The only thing I'm not sure is how to handle the versions since it is current quite hard to follow (the stable version on npm is 3.0.7, but the release note says we should upgrade to v4, then there is also a v5 and an alpha version for v27). I'm happy to fix it in 3.0.7 instead of 4.0.1 if needed.

@lmiller1990
Copy link
Member

Hi @pmrotule, I must have missed this notification. I will take a look now.

4.x is working with Vue 2, and 5.x with Vue 3. We should definitely be targeting 4.x or 5.x, not 3.x. Your PR is targeting with the right branch.

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.

2 participants