Skip to content

Commit

Permalink
test: fiber option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Aug 21, 2019
1 parent 7b543fc commit 8a734d6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 39 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module.exports = {
Note that when using `sass` (`Dart Sass`), **synchronous compilation is twice as fast as asynchronous compilation** by default, due to the overhead of asynchronous callbacks.
To avoid this overhead, you can use the [fibers](https://www.npmjs.com/package/fibers) package to call asynchronous importers from the synchronous code path.

To enable this, pass the `Fiber` class to the `fiber` option:
To enable this, pass the `Fiber` class to the `sassOptions.fiber` option:

**webpack.config.js**

Expand All @@ -189,7 +189,9 @@ module.exports = {
loader: 'sass-loader',
options: {
implementation: require('sass'),
fiber: require('fibers'),
sassOptions: {
fiber: require('fibers'),
},
},
},
],
Expand Down
55 changes: 18 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"eslint": "^6.2.1",
"eslint-config-prettier": "^6.1.0",
"eslint-plugin-import": "^2.18.2",
"fibers": "^4.0.1",
"file-loader": "^4.2.0",
"husky": "^3.0.4",
"jest": "^24.9.0",
Expand Down
16 changes: 16 additions & 0 deletions test/__snapshots__/sassOptions-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ exports[`sassOptions option should work when the option like "Object" (node-sass

exports[`sassOptions option should work when the option like "Object" (node-sass) (scss): warnings 1`] = `Array []`;

exports[`sassOptions option should work with the "fibers" option (dart-sass) (sass): errors 1`] = `Array []`;

exports[`sassOptions option should work with the "fibers" option (dart-sass) (sass): warnings 1`] = `Array []`;

exports[`sassOptions option should work with the "fibers" option (dart-sass) (scss): errors 1`] = `Array []`;

exports[`sassOptions option should work with the "fibers" option (dart-sass) (scss): warnings 1`] = `Array []`;

exports[`sassOptions option should work with the "fibers" option (node-sass) (sass): errors 1`] = `Array []`;

exports[`sassOptions option should work with the "fibers" option (node-sass) (sass): warnings 1`] = `Array []`;

exports[`sassOptions option should work with the "fibers" option (node-sass) (scss): errors 1`] = `Array []`;

exports[`sassOptions option should work with the "fibers" option (node-sass) (scss): warnings 1`] = `Array []`;

exports[`sassOptions option should work with the "functions" option (dart-sass) (sass): errors 1`] = `Array []`;

exports[`sassOptions option should work with the "functions" option (dart-sass) (sass): warnings 1`] = `Array []`;
Expand Down
22 changes: 22 additions & 0 deletions test/sassOptions-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import path from 'path';

import semver from 'semver';
import nodeSass from 'node-sass';
import dartSass from 'sass';

Expand Down Expand Up @@ -119,6 +120,27 @@ describe('sassOptions option', () => {
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

if (semver.satisfies(process.version, '>= 10')) {
it(`should work with the "fibers" option (${implementationName}) (${syntax})`, async () => {
const testId = getTestId('language', syntax);
const options = {
implementation: getImplementationByName(implementationName),
sassOptions: {
// eslint-disable-next-line global-require
fibers: require('fibers'),
},
};
const stats = await compile(testId, { loader: { options } });

expect(getCodeFromBundle(stats).css).toBe(
getCodeFromSass(testId, options).css
);

expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});
}
});
});
});
6 changes: 6 additions & 0 deletions test/validate-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ it('validate options', () => {
).not.toThrow();
expect(() => validate({ sassOptions: () => {} })).not.toThrow();
expect(() => validate({ sassOptions: true })).toThrowErrorMatchingSnapshot();
expect(() =>
validate({ sassOptions: { fiber: { mock: true } } })
).not.toThrow();
expect(() =>
validate({ sassOptions: { indentWidth: 6, linefeed: 'crlf' } })
).not.toThrow();

expect(() => validate({ prependData: '$color: red;' })).not.toThrow();
expect(() => validate({ prependData: () => '$color: red;' })).not.toThrow();
Expand Down

0 comments on commit 8a734d6

Please sign in to comment.