Skip to content

Commit 7ec1120

Browse files
test: fix
1 parent 977bb71 commit 7ec1120

File tree

7 files changed

+213
-102
lines changed

7 files changed

+213
-102
lines changed

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

Lines changed: 12 additions & 96 deletions
Large diffs are not rendered by default.

test/__snapshots__/loader.test.js.snap

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,118 @@ exports[`loader should work when the "injectType" option is "styleTag": errors 1
923923
924924
exports[`loader should work when the "injectType" option is "styleTag": warnings 1`] = `[]`;
925925
926+
exports[`loader should work with css modules when the "injectType" option is "autoStyleTag": DOM 1`] = `
927+
"<!DOCTYPE html><html><head>
928+
<title>style-loader test</title>
929+
<style id="existing-style">.existing { color: yellow }</style>
930+
<style>.css-modules-local-scoped-className_B_X8gxt {
931+
background: red;
932+
}
933+
</style><style>.css-modules-myClassName_ll2xYwU {
934+
background: red;
935+
}
936+
937+
.css-modules-myComposingClass__qO4CWd {
938+
color: blue;
939+
}
940+
</style></head>
941+
<body>
942+
<h1>Body</h1>
943+
<div class="target"></div>
944+
<iframe class="iframeTarget"></iframe>
945+
946+
947+
<div class="css-modules-myClassName_ll2xYwU">Water</div><div class="css-modules-myComposingClass__qO4CWd css-modules-local-scoped-className_B_X8gxt">Ground</div></body></html>"
948+
`;
949+
950+
exports[`loader should work with css modules when the "injectType" option is "autoStyleTag": errors 1`] = `[]`;
951+
952+
exports[`loader should work with css modules when the "injectType" option is "autoStyleTag": warnings 1`] = `[]`;
953+
954+
exports[`loader should work with css modules when the "injectType" option is "lazyAutoStyleTag": DOM 1`] = `
955+
"<!DOCTYPE html><html><head>
956+
<title>style-loader test</title>
957+
<style id="existing-style">.existing { color: yellow }</style>
958+
<style>.css-modules-local-scoped-className_B_X8gxt {
959+
background: red;
960+
}
961+
</style><style>.css-modules-myClassName_ll2xYwU {
962+
background: red;
963+
}
964+
965+
.css-modules-myComposingClass__qO4CWd {
966+
color: blue;
967+
}
968+
</style></head>
969+
<body>
970+
<h1>Body</h1>
971+
<div class="target"></div>
972+
<iframe class="iframeTarget"></iframe>
973+
974+
975+
<div class="css-modules-myClassName_ll2xYwU">Water</div><div class="css-modules-myComposingClass__qO4CWd css-modules-local-scoped-className_B_X8gxt">Ground</div></body></html>"
976+
`;
977+
978+
exports[`loader should work with css modules when the "injectType" option is "lazyAutoStyleTag": errors 1`] = `[]`;
979+
980+
exports[`loader should work with css modules when the "injectType" option is "lazyAutoStyleTag": warnings 1`] = `[]`;
981+
982+
exports[`loader should work with css modules when the "injectType" option is "lazySingletonStyleTag": DOM 1`] = `
983+
"<!DOCTYPE html><html><head>
984+
<title>style-loader test</title>
985+
<style id="existing-style">.existing { color: yellow }</style>
986+
<style>.css-modules-local-scoped-className_B_X8gxt {
987+
background: red;
988+
}
989+
.css-modules-myClassName_ll2xYwU {
990+
background: red;
991+
}
992+
993+
.css-modules-myComposingClass__qO4CWd {
994+
color: blue;
995+
}
996+
</style></head>
997+
<body>
998+
<h1>Body</h1>
999+
<div class="target"></div>
1000+
<iframe class="iframeTarget"></iframe>
1001+
1002+
1003+
<div class="css-modules-myClassName_ll2xYwU">Water</div><div class="css-modules-myComposingClass__qO4CWd css-modules-local-scoped-className_B_X8gxt">Ground</div></body></html>"
1004+
`;
1005+
1006+
exports[`loader should work with css modules when the "injectType" option is "lazySingletonStyleTag": errors 1`] = `[]`;
1007+
1008+
exports[`loader should work with css modules when the "injectType" option is "lazySingletonStyleTag": warnings 1`] = `[]`;
1009+
1010+
exports[`loader should work with css modules when the "injectType" option is "lazyStyleTag": DOM 1`] = `
1011+
"<!DOCTYPE html><html><head>
1012+
<title>style-loader test</title>
1013+
<style id="existing-style">.existing { color: yellow }</style>
1014+
<style>.css-modules-local-scoped-className_B_X8gxt {
1015+
background: red;
1016+
}
1017+
</style><style>.css-modules-myClassName_ll2xYwU {
1018+
background: red;
1019+
}
1020+
1021+
.css-modules-myComposingClass__qO4CWd {
1022+
color: blue;
1023+
}
1024+
</style></head>
1025+
<body>
1026+
<h1>Body</h1>
1027+
<div class="target"></div>
1028+
<iframe class="iframeTarget"></iframe>
1029+
1030+
1031+
<div class="css-modules-myClassName_ll2xYwU">Water</div><div class="css-modules-myComposingClass__qO4CWd css-modules-local-scoped-className_B_X8gxt">Ground</div></body></html>"
1032+
`;
1033+
1034+
exports[`loader should work with css modules when the "injectType" option is "lazyStyleTag": errors 1`] = `[]`;
1035+
1036+
exports[`loader should work with css modules when the "injectType" option is "lazyStyleTag": warnings 1`] = `[]`;
1037+
9261038
exports[`loader should work with css modules when the "injectType" option is "linkTag": DOM 1`] = `
9271039
"<!DOCTYPE html><html><head>
9281040
<title>style-loader test</title>
@@ -934,13 +1046,69 @@ exports[`loader should work with css modules when the "injectType" option is "li
9341046
<iframe class="iframeTarget"></iframe>
9351047
9361048
937-
<div class="undefined">Water</div><div class="undefined">Ground</div></body></html>"
1049+
<div>Water</div><div>Ground</div></body></html>"
9381050
`;
9391051
9401052
exports[`loader should work with css modules when the "injectType" option is "linkTag": errors 1`] = `[]`;
9411053
9421054
exports[`loader should work with css modules when the "injectType" option is "linkTag": warnings 1`] = `[]`;
9431055
1056+
exports[`loader should work with css modules when the "injectType" option is "singletonStyleTag": DOM 1`] = `
1057+
"<!DOCTYPE html><html><head>
1058+
<title>style-loader test</title>
1059+
<style id="existing-style">.existing { color: yellow }</style>
1060+
<style>.css-modules-local-scoped-className_B_X8gxt {
1061+
background: red;
1062+
}
1063+
.css-modules-myClassName_ll2xYwU {
1064+
background: red;
1065+
}
1066+
1067+
.css-modules-myComposingClass__qO4CWd {
1068+
color: blue;
1069+
}
1070+
</style></head>
1071+
<body>
1072+
<h1>Body</h1>
1073+
<div class="target"></div>
1074+
<iframe class="iframeTarget"></iframe>
1075+
1076+
1077+
<div class="css-modules-myClassName_ll2xYwU">Water</div><div class="css-modules-myComposingClass__qO4CWd css-modules-local-scoped-className_B_X8gxt">Ground</div></body></html>"
1078+
`;
1079+
1080+
exports[`loader should work with css modules when the "injectType" option is "singletonStyleTag": errors 1`] = `[]`;
1081+
1082+
exports[`loader should work with css modules when the "injectType" option is "singletonStyleTag": warnings 1`] = `[]`;
1083+
1084+
exports[`loader should work with css modules when the "injectType" option is "styleTag": DOM 1`] = `
1085+
"<!DOCTYPE html><html><head>
1086+
<title>style-loader test</title>
1087+
<style id="existing-style">.existing { color: yellow }</style>
1088+
<style>.css-modules-local-scoped-className_B_X8gxt {
1089+
background: red;
1090+
}
1091+
</style><style>.css-modules-myClassName_ll2xYwU {
1092+
background: red;
1093+
}
1094+
1095+
.css-modules-myComposingClass__qO4CWd {
1096+
color: blue;
1097+
}
1098+
</style></head>
1099+
<body>
1100+
<h1>Body</h1>
1101+
<div class="target"></div>
1102+
<iframe class="iframeTarget"></iframe>
1103+
1104+
1105+
<div class="css-modules-myClassName_ll2xYwU">Water</div><div class="css-modules-myComposingClass__qO4CWd css-modules-local-scoped-className_B_X8gxt">Ground</div></body></html>"
1106+
`;
1107+
1108+
exports[`loader should work with css modules when the "injectType" option is "styleTag": errors 1`] = `[]`;
1109+
1110+
exports[`loader should work with css modules when the "injectType" option is "styleTag": warnings 1`] = `[]`;
1111+
9441112
exports[`loader should work: DOM 1`] = `
9451113
"<!DOCTYPE html><html><head>
9461114
<title>style-loader test</title>

test/esModule-option.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ describe('"esModule" option', () => {
9696
{},
9797
{
9898
module: {
99+
parser: {
100+
javascript: {
101+
exportsPresence:
102+
esModuleValue.cssLoader.modules &&
103+
esModuleValue.cssLoader.modules.exportOnlyLocals
104+
? false
105+
: "error",
106+
},
107+
},
99108
rules: [
100109
{
101110
test: /\.css$/i,

test/fixtures/css-modules-link.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import './css-modules.css';
2+
3+
const node1 = document.createElement("DIV");
4+
const textNode1 = document.createTextNode("Water");
5+
6+
node1.appendChild(textNode1);
7+
8+
document.body.appendChild(node1);
9+
10+
const node2 = document.createElement("DIV");
11+
const textNode2 = document.createTextNode("Ground");
12+
13+
node2.appendChild(textNode2);
14+
15+
document.body.appendChild(node2);

test/fixtures/css-modules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import styles from './css-modules.css';
1+
import * as styles from './css-modules.css';
22

33
const node1 = document.createElement("DIV");
44
const textNode1 = document.createTextNode("Water");

test/fixtures/lazy-css-modules.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import styles from './css-modules.css';
1+
import styles, { myClassName, myComposingClass } from './css-modules.css';
22

33
styles.use();
44

55
const node1 = document.createElement("DIV");
66
const textNode1 = document.createTextNode("Water");
77

88
node1.appendChild(textNode1);
9-
node1.className = styles.locals.myClassName;
9+
node1.className = myClassName;
1010

1111
document.body.appendChild(node1);
1212

1313
const node2 = document.createElement("DIV");
1414
const textNode2 = document.createTextNode("Ground");
1515

1616
node2.appendChild(textNode2);
17-
node2.className = styles.locals.myComposingClass;
17+
node2.className = myComposingClass;
1818

1919
document.body.appendChild(node2);

test/loader.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ describe("loader", () => {
7474
it(`should work with css modules when the "injectType" option is "${injectType}"`, async () => {
7575
expect.assertions(3);
7676

77-
const entry = getEntryByInjectType("css-modules.js", injectType);
77+
const entry = getEntryByInjectType(
78+
injectType === "linkTag" ? "css-modules-link.js" : "css-modules.js",
79+
injectType,
80+
);
7881
const compiler = getCompiler(
7982
entry,
8083
{},

0 commit comments

Comments
 (0)