Skip to content

Commit b3fa93b

Browse files
test: add test for entry and auto (webpack-contrib#1334)
1 parent 6a600fb commit b3fa93b

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

test/__snapshots__/modules-option.test.js.snap

+42
Original file line numberDiff line numberDiff line change
@@ -13412,6 +13412,48 @@ Array [
1341213412

1341313413
exports[`"modules" option should work with the "auto" by default for icss: warnings 1`] = `Array []`;
1341413414

13415+
exports[`"modules" option should work with the "auto" by default when CSS file is entrypoint: entry 1`] = `
13416+
"// Imports
13417+
import ___CSS_LOADER_API_IMPORT___ from \\"../../../../src/runtime/api.js\\";
13418+
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]});
13419+
// Module
13420+
___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\"]);
13421+
// Exports
13422+
export default ___CSS_LOADER_EXPORT___;
13423+
"
13424+
`;
13425+
13426+
exports[`"modules" option should work with the "auto" by default when CSS file is entrypoint: errors 1`] = `Array []`;
13427+
13428+
exports[`"modules" option should work with the "auto" by default when CSS file is entrypoint: module 1`] = `
13429+
"// Imports
13430+
import ___CSS_LOADER_API_IMPORT___ from \\"../../../../src/runtime/api.js\\";
13431+
var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(function(i){return i[1]});
13432+
// Module
13433+
___CSS_LOADER_EXPORT___.push([module.id, \\"._wr0eVpMbaGr94MKhByE {\\\\n color: red;\\\\n}\\\\n\\", \\"\\"]);
13434+
// Exports
13435+
___CSS_LOADER_EXPORT___.locals = {
13436+
\\"relative\\": \\"_wr0eVpMbaGr94MKhByE\\"
13437+
};
13438+
export default ___CSS_LOADER_EXPORT___;
13439+
"
13440+
`;
13441+
13442+
exports[`"modules" option should work with the "auto" by default when CSS file is entrypoint: result 1`] = `
13443+
Array [
13444+
Array [
13445+
"./modules/mode/relative.module.css",
13446+
"._wr0eVpMbaGr94MKhByE {
13447+
color: red;
13448+
}
13449+
",
13450+
"",
13451+
],
13452+
]
13453+
`;
13454+
13455+
exports[`"modules" option should work with the "auto" by default when CSS file is entrypoint: warnings 1`] = `Array []`;
13456+
1341513457
exports[`"modules" option should work with the "auto" by default with "modules" filename: errors 1`] = `Array []`;
1341613458

1341713459
exports[`"modules" option should work with the "auto" by default with "modules" filename: module 1`] = `

test/fixtures/modules/mode/entry.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.class {
2+
color: red;
3+
}

test/helpers/getCompiler.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export default (fixture, loaderOptions = {}, config = {}) => {
99
target: "node",
1010
devtool: config.devtool || false,
1111
context: path.resolve(__dirname, "../fixtures"),
12-
entry: path.resolve(__dirname, "../fixtures", fixture),
12+
entry: Array.isArray(fixture)
13+
? fixture
14+
: path.resolve(__dirname, "../fixtures", fixture),
1315
output: {
1416
path: path.resolve(__dirname, "../outputs"),
1517
filename: "[name].bundle.js",

test/modules-option.test.js

+20
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,26 @@ describe('"modules" option', () => {
886886
expect(getErrors(stats)).toMatchSnapshot("errors");
887887
});
888888

889+
it('should work with the "auto" by default when CSS file is entrypoint', async () => {
890+
const compiler = getCompiler([
891+
"./modules/mode/entry.css",
892+
"./modules/mode/modules.js",
893+
]);
894+
const stats = await compile(compiler);
895+
896+
expect(getModuleSource("./modules/mode/entry.css", stats)).toMatchSnapshot(
897+
"entry"
898+
);
899+
expect(
900+
getModuleSource("./modules/mode/relative.module.css", stats)
901+
).toMatchSnapshot("module");
902+
expect(getExecutedCode("main.bundle.js", compiler, stats)).toMatchSnapshot(
903+
"result"
904+
);
905+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
906+
expect(getErrors(stats)).toMatchSnapshot("errors");
907+
});
908+
889909
it('should work with the "auto" by default with "modules" filename', async () => {
890910
const compiler = getCompiler("./modules/mode/modules-2.js");
891911
const stats = await compile(compiler);

0 commit comments

Comments
 (0)