Skip to content

Commit a8198df

Browse files
test: the webpack export field (#1189)
1 parent a692622 commit a8198df

File tree

10 files changed

+95
-0
lines changed

10 files changed

+95
-0
lines changed

test/__snapshots__/loader.test.js.snap

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470389,6 +470389,46 @@ Deprecation Warning on line 89, column 26 of file:///node_modules/@material/touc
470389470389
]
470390470390
`;
470391470391

470392+
exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `
470393+
".webpack_file_scss {
470394+
color: red;
470395+
}"
470396+
`;
470397+
470398+
exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'sass' syntax): errors 1`] = `[]`;
470399+
470400+
exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'sass' syntax): warnings 1`] = `[]`;
470401+
470402+
exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'scss' syntax): css 1`] = `
470403+
".webpack_file_scss {
470404+
color: red;
470405+
}"
470406+
`;
470407+
470408+
exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'scss' syntax): errors 1`] = `[]`;
470409+
470410+
exports[`loader should work with the "webpack" export field ('dart-sass', 'legacy' API, 'scss' syntax): warnings 1`] = `[]`;
470411+
470412+
exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'sass' syntax): css 1`] = `
470413+
".webpack_file_scss {
470414+
color: red;
470415+
}"
470416+
`;
470417+
470418+
exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'sass' syntax): errors 1`] = `[]`;
470419+
470420+
exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'sass' syntax): warnings 1`] = `[]`;
470421+
470422+
exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'scss' syntax): css 1`] = `
470423+
".webpack_file_scss {
470424+
color: red;
470425+
}"
470426+
`;
470427+
470428+
exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'scss' syntax): errors 1`] = `[]`;
470429+
470430+
exports[`loader should work with the "webpack" export field ('sass-embedded', 'legacy' API, 'scss' syntax): warnings 1`] = `[]`;
470431+
470392470432
exports[`loader should work with the 'resolve.byDependency.sass' option ('dart-sass', 'legacy' API, 'sass' syntax): css 1`] = `
470393470433
".a {
470394470434
color: red;

test/helpers/getCodeFromSass.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ async function getCodeFromSass(testId, options, context = {}) {
320320
const pathToCustomMainFiles = isSass
321321
? path.resolve(testFolder, "sass/custom-main-files/custom.sass")
322322
: path.resolve(testFolder, "scss/custom-main-files/custom.scss");
323+
const pathToWebpackExportField = path.resolve(
324+
testFolder,
325+
"node_modules/webpack-export-field/dist/styles/webpack/file.scss",
326+
);
323327

324328
// Pseudo importer for tests
325329
function testImporter(url) {
@@ -729,6 +733,10 @@ async function getCodeFromSass(testId, options, context = {}) {
729733

730734
// eslint-disable-next-line no-param-reassign
731735
url = url
736+
.replace(
737+
/^webpack-export-field\/styles\/file$/,
738+
pathToWebpackExportField,
739+
)
732740
.replace(/^path-to-alias/, pathToAlias)
733741
.replace(
734742
/^package-with-style-field-and-css/,

test/loader.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,25 @@ describe("loader", () => {
21232123
expect(getErrors(stats)).toMatchSnapshot("errors");
21242124
expect(logs).toMatchSnapshot("logs");
21252125
});
2126+
2127+
if (!isModernAPI) {
2128+
it(`should work with the "webpack" export field ('${implementationName}', '${api}' API, '${syntax}' syntax)`, async () => {
2129+
const testId = getTestId("webpack-export-field", syntax);
2130+
const options = {
2131+
implementation,
2132+
api,
2133+
};
2134+
const compiler = getCompiler(testId, { loader: { options } });
2135+
const stats = await compile(compiler);
2136+
const codeFromBundle = getCodeFromBundle(stats, compiler);
2137+
const codeFromSass = await getCodeFromSass(testId, options);
2138+
2139+
expect(codeFromBundle.css).toBe(codeFromSass.css);
2140+
expect(codeFromBundle.css).toMatchSnapshot("css");
2141+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
2142+
expect(getErrors(stats)).toMatchSnapshot("errors");
2143+
});
2144+
}
21262145
}
21272146
});
21282147
});

test/node_modules/webpack-export-field/dist/styles/file.css

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/webpack-export-field/dist/styles/file.scss

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/webpack-export-field/dist/styles/webpack/file.css

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/webpack-export-field/dist/styles/webpack/file.scss

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/webpack-export-field/package.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/sass/webpack-export-field.sass

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "webpack-export-field/styles/file"

test/scss/webpack-export-field.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "webpack-export-field/styles/file";

0 commit comments

Comments
 (0)