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

Test fiber option #739

Merged
merged 1 commit into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 23 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,28 @@ describe('sassOptions option', () => {
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

it(`should work with the "fibers" option (${implementationName}) (${syntax})`, async () => {
const testId = getTestId('language', syntax);
const options = {
implementation: getImplementationByName(implementationName),
sassOptions: {},
};

if (semver.satisfies(process.version, '>= 10')) {
// eslint-disable-next-line global-require
options.sassOptions.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