Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jestjs - sass/sass-true/jest not finding testfiles

I'm trying to unit test some sass functions with dart-sass and sass-true via jest. The node version I am applying is v14.5.4, module versions can be found below.

However, it appears that dart-sass cannot find my testfiles.

My file structure matches to the following one:

  • package.json
  • src
    • scss
      • main.scss
      • _tools.scss
    • css
      • main.css
  • __tests__
    • scss.test.js
    • tools.test.scss

The files are as follows.

package.json

{
    ...
    "scripts": {
        "test": "jest"
    },

    "devDependencies": {
        "sass": "^1.32.0",
        "sass-true": "^6.0.1",
        "jest": "^26.4.2",
        "glob": "^7.1.6"
    }
    ...
}

main.scss

@import "tools";

_tools.scss

$font-size--base: 16px;

@function font-size-get-ratio($new-size, $base: $font-size--base) {
    @return $new-size/$base * 1rem; 
}

scss.test.js

const path = require('path');
const sassTrue = require('sass-true');

describe('Sass', () => {
    const file = path.join(__dirname, 'tools.test.scss');

    sassTrue.runSass({ file }, describe, it);
})

tools.test.scss

@import 'true';
@import '../src/scss/tools';

@include describe('font-size-get-ratio()') {
    @include it('should return the font-size ratio in rem') {
        @include assert-equal(font-size-get-ratio(16px), 1.0rem);
    }
}

Running npm run test leads to the following output.

Among other stuff, the output displays tools.test.scss to be missing. The path itself seams to be correct. Curiously, the root slash is not display, but it seams to be present if use a call to console.log on the file path variable right before the error gets trigger within dart-sass.

home/user/eclipse-workspace/someproject/__tests__/tools.test.scss: no such file or directory

Does anybody have a solution for this behavior?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...