Skip to content

Commit

Permalink
test: the webpack export field (#1189)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Feb 14, 2024
1 parent a692622 commit a8198df
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test/helpers/getCodeFromSass.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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/,
Expand Down
19 changes: 19 additions & 0 deletions test/loader.test.js
Expand Up @@ -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");
});
}
}
});
});
Expand Down
3 changes: 3 additions & 0 deletions test/node_modules/webpack-export-field/dist/styles/file.css

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

3 changes: 3 additions & 0 deletions test/node_modules/webpack-export-field/dist/styles/file.scss

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

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

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

14 changes: 14 additions & 0 deletions test/node_modules/webpack-export-field/package.json

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

1 change: 1 addition & 0 deletions test/sass/webpack-export-field.sass
@@ -0,0 +1 @@
@import "webpack-export-field/styles/file"
1 change: 1 addition & 0 deletions test/scss/webpack-export-field.scss
@@ -0,0 +1 @@
@import "webpack-export-field/styles/file";

0 comments on commit a8198df

Please sign in to comment.