diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index 2b325bd7..4e569b75 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -470389,6 +470389,46 @@ Deprecation Warning on line 89, column 26 of file:///node_modules/@material/touc ] `; +exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = ` +".webpack_file_scss { + color: red; +}" +`; + +exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'sass' syntax): errors 1`] = `[]`; + +exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'sass' syntax): warnings 1`] = `[]`; + +exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'scss' syntax): css 1`] = ` +".webpack_file_scss { + color: red; +}" +`; + +exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'scss' syntax): errors 1`] = `[]`; + +exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'scss' syntax): warnings 1`] = `[]`; + +exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'sass' syntax): css 1`] = ` +".webpack_file_scss { + color: red; +}" +`; + +exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'sass' syntax): errors 1`] = `[]`; + +exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'sass' syntax): warnings 1`] = `[]`; + +exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'scss' syntax): css 1`] = ` +".webpack_file_scss { + color: red; +}" +`; + +exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'scss' syntax): errors 1`] = `[]`; + +exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'scss' syntax): warnings 1`] = `[]`; + exports[`loader should work with the 'resolve.byDependency.sass' option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = ` ".a { color: red; diff --git a/test/helpers/getCodeFromSass.js b/test/helpers/getCodeFromSass.js index 7196a1bf..3daf235a 100644 --- a/test/helpers/getCodeFromSass.js +++ b/test/helpers/getCodeFromSass.js @@ -320,6 +320,10 @@ async function getCodeFromSass(testId, options, context = {}) { const pathToCustomMainFiles = isSass ? path.resolve(testFolder, "sass/custom-main-files/custom.sass") : path.resolve(testFolder, "scss/custom-main-files/custom.scss"); + const pathToWebpackExportField = path.resolve( + testFolder, + "node_modules/webpack-export-field/dist/styles/webpack/file.scss", + ); // Pseudo importer for tests function testImporter(url) { @@ -729,6 +733,10 @@ async function getCodeFromSass(testId, options, context = {}) { // eslint-disable-next-line no-param-reassign url = url + .replace( + /^webpack-export-field\/styles\/file$/, + pathToWebpackExportField, + ) .replace(/^path-to-alias/, pathToAlias) .replace( /^package-with-style-field-and-css/, diff --git a/test/loader.test.js b/test/loader.test.js index a5e4abe1..c2d5bc80 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -2123,6 +2123,25 @@ describe("loader", () => { expect(getErrors(stats)).toMatchSnapshot("errors"); expect(logs).toMatchSnapshot("logs"); }); + + if (!isModernAPI) { + it(`should work with the "webpack" export field ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => { + const testId = getTestId("webpack-export-field", syntax); + const options = { + implementation, + api, + }; + const compiler = getCompiler(testId, { loader: { options } }); + const stats = await compile(compiler); + const codeFromBundle = getCodeFromBundle(stats, compiler); + const codeFromSass = await getCodeFromSass(testId, options); + + expect(codeFromBundle.css).toBe(codeFromSass.css); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + }); + } } }); }); diff --git a/test/node_modules/webpack-export-field/dist/styles/file.css b/test/node_modules/webpack-export-field/dist/styles/file.css new file mode 100644 index 00000000..e7976df8 --- /dev/null +++ b/test/node_modules/webpack-export-field/dist/styles/file.css @@ -0,0 +1,3 @@ +.file_css { + color: red; +} diff --git a/test/node_modules/webpack-export-field/dist/styles/file.scss b/test/node_modules/webpack-export-field/dist/styles/file.scss new file mode 100644 index 00000000..7923f287 --- /dev/null +++ b/test/node_modules/webpack-export-field/dist/styles/file.scss @@ -0,0 +1,3 @@ +.file_scss { + color: red; +} diff --git a/test/node_modules/webpack-export-field/dist/styles/webpack/file.css b/test/node_modules/webpack-export-field/dist/styles/webpack/file.css new file mode 100644 index 00000000..db802829 --- /dev/null +++ b/test/node_modules/webpack-export-field/dist/styles/webpack/file.css @@ -0,0 +1,3 @@ +.webpack_file_css { + color: red; +} diff --git a/test/node_modules/webpack-export-field/dist/styles/webpack/file.scss b/test/node_modules/webpack-export-field/dist/styles/webpack/file.scss new file mode 100644 index 00000000..2fcc5afd --- /dev/null +++ b/test/node_modules/webpack-export-field/dist/styles/webpack/file.scss @@ -0,0 +1,3 @@ +.webpack_file_scss { + color: red; +} diff --git a/test/node_modules/webpack-export-field/package.json b/test/node_modules/webpack-export-field/package.json new file mode 100644 index 00000000..64c4ccdf --- /dev/null +++ b/test/node_modules/webpack-export-field/package.json @@ -0,0 +1,14 @@ +{ + "name": "webpack-export-field", + "version": "1.0.0", + "exports": { + "./styles/*": { + "webpack": { + "sass": "./dist/styles/webpack/*.scss", + "style": "./dist/styles/webpack/*.css" + }, + "sass": "./dist/styles/*.scss", + "style": "./dist/styles/*.css" + } + } +} diff --git a/test/sass/webpack-export-field.sass b/test/sass/webpack-export-field.sass new file mode 100644 index 00000000..63c1e1f6 --- /dev/null +++ b/test/sass/webpack-export-field.sass @@ -0,0 +1 @@ +@import "webpack-export-field/styles/file" diff --git a/test/scss/webpack-export-field.scss b/test/scss/webpack-export-field.scss new file mode 100644 index 00000000..f01bd3f8 --- /dev/null +++ b/test/scss/webpack-export-field.scss @@ -0,0 +1 @@ +@import "webpack-export-field/styles/file";