From cf8c5fdbced172da8579b394dd5fde20025f4c05 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Wed, 21 Aug 2019 14:29:19 +0300 Subject: [PATCH] test: fiber option --- README.md | 6 +- package-lock.json | 55 ++++++------------- package.json | 1 + .../sassOptions-option.test.js.snap | 16 ++++++ test/sassOptions-option.test.js | 23 ++++++++ test/validate-options.test.js | 6 ++ 6 files changed, 68 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 4cc51d26..2e90df3a 100644 --- a/README.md +++ b/README.md @@ -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** @@ -189,7 +189,9 @@ module.exports = { loader: 'sass-loader', options: { implementation: require('sass'), - fiber: require('fibers'), + sassOptions: { + fiber: require('fibers'), + }, }, }, ], diff --git a/package-lock.json b/package-lock.json index 9baa661f..04d164d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3828,16 +3828,6 @@ "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", "dev": true - }, - "schema-utils": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-2.1.0.tgz", - "integrity": "sha512-g6SViEZAfGNrToD82ZPUjq52KUPDYc+fN5+g6Euo5mLokl/9Yx14z0Cu4RR1m55HtBXejO0sBt+qw79axN+Fiw==", - "dev": true, - "requires": { - "ajv": "^6.1.0", - "ajv-keywords": "^3.1.0" - } } } }, @@ -4182,6 +4172,12 @@ "integrity": "sha1-OHHMCmoALow+Wzz38zYmRnXwa50=", "dev": true }, + "detect-libc": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", + "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=", + "dev": true + }, "detect-newline": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-2.1.0.tgz", @@ -4390,9 +4386,9 @@ "dev": true }, "electron-to-chromium": { - "version": "1.3.236", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.236.tgz", - "integrity": "sha512-LWOvuJ80pLO3FtFqTcGuXB0dxdMtzSCkRmbXdY5mHUvXRQGor3sTVmyfU70aD2yF5i+fbHz52ncWr5T3xUYHlA==", + "version": "1.3.237", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.237.tgz", + "integrity": "sha512-SPAFjDr/7iiVK2kgTluwxela6eaWjjFkS9rO/iYpB/KGXgccUom5YC7OIf19c8m8GGptWxLU0Em8xM64A/N7Fg==", "dev": true }, "elegant-spinner": { @@ -5225,6 +5221,15 @@ "bser": "^2.0.0" } }, + "fibers": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/fibers/-/fibers-4.0.1.tgz", + "integrity": "sha512-H79EJn7DMWXk48ygmC82bMP8KNcFBZF1CPfwBpYF6cO85hGWoIrlu7eyX9ayxfjP9Nsl0JXxdI6fpYU4DWVw2w==", + "dev": true, + "requires": { + "detect-libc": "^1.0.3" + } + }, "figgy-pudding": { "version": "3.5.1", "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz", @@ -5257,18 +5262,6 @@ "requires": { "loader-utils": "^1.2.3", "schema-utils": "^2.0.0" - }, - "dependencies": { - "schema-utils": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-2.1.0.tgz", - "integrity": "sha512-g6SViEZAfGNrToD82ZPUjq52KUPDYc+fN5+g6Euo5mLokl/9Yx14z0Cu4RR1m55HtBXejO0sBt+qw79axN+Fiw==", - "dev": true, - "requires": { - "ajv": "^6.1.0", - "ajv-keywords": "^3.1.0" - } - } } }, "fill-range": { @@ -12458,18 +12451,6 @@ "requires": { "loader-utils": "^1.2.3", "schema-utils": "^2.0.1" - }, - "dependencies": { - "schema-utils": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-2.1.0.tgz", - "integrity": "sha512-g6SViEZAfGNrToD82ZPUjq52KUPDYc+fN5+g6Euo5mLokl/9Yx14z0Cu4RR1m55HtBXejO0sBt+qw79axN+Fiw==", - "dev": true, - "requires": { - "ajv": "^6.1.0", - "ajv-keywords": "^3.1.0" - } - } } }, "supports-color": { diff --git a/package.json b/package.json index f6932bfb..e7e89381 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/__snapshots__/sassOptions-option.test.js.snap b/test/__snapshots__/sassOptions-option.test.js.snap index 85d2ddc2..b83853ea 100644 --- a/test/__snapshots__/sassOptions-option.test.js.snap +++ b/test/__snapshots__/sassOptions-option.test.js.snap @@ -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 []`; diff --git a/test/sassOptions-option.test.js b/test/sassOptions-option.test.js index 2b5d0c6e..49e860b3 100644 --- a/test/sassOptions-option.test.js +++ b/test/sassOptions-option.test.js @@ -3,6 +3,7 @@ */ import path from 'path'; +import semver from 'semver'; import nodeSass from 'node-sass'; import dartSass from 'sass'; @@ -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'); + }); }); }); }); diff --git a/test/validate-options.test.js b/test/validate-options.test.js index 7973982d..271a10ca 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -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();