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: the webpack export field #1189

Merged
merged 1 commit into from
Feb 14, 2024
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
40 changes: 40 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "webpack-export-field/styles/file"
1 change: 1 addition & 0 deletions test/scss/webpack-export-field.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "webpack-export-field/styles/file";
Loading