Skip to content

Commit 44bc29d

Browse files
authored
test: refactor some style tests (#837)
1 parent 5f499ac commit 44bc29d

File tree

15 files changed

+205
-30
lines changed

15 files changed

+205
-30
lines changed

tests/integration/style/less/bundle-false/rslib.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ export default defineConfig({
2222
},
2323
}),
2424
],
25-
root: resolve(__dirname, '../__fixtures__/basic'),
2625
source: {
2726
entry: {
28-
index: ['./src/**'],
27+
index: ['../__fixtures__/basic/src/**'],
2928
},
3029
},
3130
resolve: {

tests/integration/style/less/bundle-import/rslib.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ export default defineConfig({
2020
},
2121
}),
2222
],
23-
root: resolve(__dirname, '../__fixtures__/import'),
2423
source: {
2524
entry: {
26-
index: './src/index.ts',
25+
index: '../__fixtures__/import/src/index.ts',
2726
},
2827
},
2928
output: {

tests/integration/style/less/bundle/rslib.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ export default defineConfig({
2020
},
2121
}),
2222
],
23-
root: resolve(__dirname, '../__fixtures__/basic'),
2423
source: {
2524
entry: {
26-
index: ['./src/index.less'],
25+
index: ['../__fixtures__/basic/src/index.less'],
2726
},
2827
},
2928
resolve: {

tests/integration/style/postcss/bundle-false/rslib.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export default defineConfig({
1212
},
1313
},
1414
tools: {
15-
lightningcssLoader: false,
1615
postcss: {
1716
postcssOptions: {
1817
plugins: [require('postcss-alias')],

tests/integration/style/postcss/bundle/rslib.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export default defineConfig({
99
},
1010
},
1111
tools: {
12-
lightningcssLoader: false,
1312
postcss: {
1413
postcssOptions: {
1514
plugins: [require('postcss-alias')],

tests/integration/style/sass/__fixtures__/src/index.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@import 'foundation/code', 'foundation/lists';
2-
// TODO: Error: Sass variables aren't allowed in plain CSS.
3-
// @import '~lib1/index.css';
2+
@import '~lib1/index.css';
43
@import './foundation/index.scss';
54

65
$url: './foundation/logo.svg';
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`should extract css with pluginSass in bundle 2`] = `
4+
[
5+
".lib1 {
6+
font-size: 18px;
7+
}
8+
9+
code {
10+
padding: .25em;
11+
line-height: 0;
12+
}
13+
14+
ul, ol {
15+
text-align: left;
16+
}
17+
18+
ul ul, ul ol, ol ul, ol ol {
19+
padding-bottom: 0;
20+
padding-left: 0;
21+
}
22+
23+
body, .url-variable {
24+
background: url(./static/svg/logo.svg);
25+
}
26+
27+
.alert {
28+
border: 1px solid #c6538ce0;
29+
}
30+
31+
",
32+
]
33+
`;
34+
35+
exports[`should extract css with pluginSass in bundle 4`] = `
36+
[
37+
".lib1 {
38+
font-size: 18px;
39+
}
40+
41+
code {
42+
padding: .25em;
43+
line-height: 0;
44+
}
45+
46+
ul, ol {
47+
text-align: left;
48+
}
49+
50+
ul ul, ul ol, ol ul, ol ol {
51+
padding-bottom: 0;
52+
padding-left: 0;
53+
}
54+
55+
body, .url-variable {
56+
background: url(./static/svg/logo.svg);
57+
}
58+
59+
.alert {
60+
border: 1px solid #c6538ce0;
61+
}
62+
63+
",
64+
]
65+
`;
66+
67+
exports[`should extract css with pluginSass in bundle-false 2`] = `
68+
[
69+
"code {
70+
padding: .25em;
71+
line-height: 0;
72+
}
73+
74+
",
75+
"ul, ol {
76+
text-align: left;
77+
}
78+
79+
ul ul, ul ol, ol ul, ol ol {
80+
padding-bottom: 0;
81+
padding-left: 0;
82+
}
83+
84+
",
85+
"body {
86+
background: url(../static/svg/logo.svg);
87+
}
88+
89+
",
90+
"@import "~lib1/index.css";
91+
92+
code {
93+
padding: .25em;
94+
line-height: 0;
95+
}
96+
97+
ul, ol {
98+
text-align: left;
99+
}
100+
101+
ul ul, ul ol, ol ul, ol ol {
102+
padding-bottom: 0;
103+
padding-left: 0;
104+
}
105+
106+
body, .url-variable {
107+
background: url(./static/svg/logo.svg);
108+
}
109+
110+
.alert {
111+
border: 1px solid #c6538ce0;
112+
}
113+
114+
",
115+
]
116+
`;
117+
118+
exports[`should extract css with pluginSass in bundle-false 4`] = `
119+
[
120+
"code {
121+
padding: .25em;
122+
line-height: 0;
123+
}
124+
125+
",
126+
"ul, ol {
127+
text-align: left;
128+
}
129+
130+
ul ul, ul ol, ol ul, ol ol {
131+
padding-bottom: 0;
132+
padding-left: 0;
133+
}
134+
135+
",
136+
"body {
137+
background: url(../static/svg/logo.svg);
138+
}
139+
140+
",
141+
"@import "~lib1/index.css";
142+
143+
code {
144+
padding: .25em;
145+
line-height: 0;
146+
}
147+
148+
ul, ol {
149+
text-align: left;
150+
}
151+
152+
ul ul, ul ol, ol ul, ol ol {
153+
padding-bottom: 0;
154+
padding-left: 0;
155+
}
156+
157+
body, .url-variable {
158+
background: url(./static/svg/logo.svg);
159+
}
160+
161+
.alert {
162+
border: 1px solid #c6538ce0;
163+
}
164+
165+
",
166+
]
167+
`;

tests/integration/style/sass/bundle-false/rslib.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ export default defineConfig({
2424
],
2525
source: {
2626
entry: {
27-
index: ['./src/**/*.scss', './foundation/logo.svg'],
27+
index: [
28+
'../__fixtures__/src/**/*.scss',
29+
'../__fixtures__/foundation/logo.svg',
30+
],
2831
},
2932
},
30-
root: resolve(__dirname, '../__fixtures__'),
3133
plugins: [
3234
pluginSass({
3335
sassLoaderOptions: {

tests/integration/style/sass/bundle/rslib.config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ export default defineConfig({
1212
plugins: [
1313
pluginSass({
1414
sassLoaderOptions: {
15-
additionalData: '$base-color: #c6538c;',
15+
additionalData(content, loaderContext) {
16+
const contentStr =
17+
typeof content === 'string' ? content : content.toString();
18+
19+
if (loaderContext.resourcePath.endsWith('.scss')) {
20+
return `$base-color: #c6538c;${contentStr}`;
21+
}
22+
return contentStr;
23+
},
1624
},
1725
}),
1826
],

tests/integration/style/sass/index.test.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,52 @@ import { expect, test } from 'vitest';
55
test('should extract css with pluginSass in bundle', async () => {
66
const fixturePath = join(__dirname, 'bundle');
77
const { contents } = await buildAndGetResults({ fixturePath, type: 'css' });
8-
const esmFiles = Object.keys(contents.esm);
9-
expect(esmFiles).toMatchInlineSnapshot(`
8+
9+
const esmFileNames = Object.keys(contents.esm);
10+
const esmFileContents = Object.values(contents.esm);
11+
expect(esmFileNames).toMatchInlineSnapshot(`
1012
[
1113
"<ROOT>/tests/integration/style/sass/bundle/dist/esm/index.css",
1214
]
1315
`);
1416

15-
const cjsFiles = Object.keys(contents.cjs);
16-
expect(cjsFiles).toMatchInlineSnapshot(`
17+
expect(esmFileContents).toMatchSnapshot();
18+
19+
const cjsFileNames = Object.keys(contents.cjs);
20+
const cjsFileContents = Object.values(contents.cjs);
21+
expect(cjsFileNames).toMatchInlineSnapshot(`
1722
[
1823
"<ROOT>/tests/integration/style/sass/bundle/dist/cjs/index.css",
1924
]
2025
`);
26+
expect(cjsFileContents).toMatchSnapshot();
2127
});
2228

2329
test('should extract css with pluginSass in bundle-false', async () => {
2430
const fixturePath = join(__dirname, 'bundle-false');
2531
const { contents } = await buildAndGetResults({ fixturePath, type: 'css' });
26-
const esmFiles = Object.keys(contents.esm);
2732

28-
expect(esmFiles).toMatchInlineSnapshot(`
33+
const esmFileNames = Object.keys(contents.esm);
34+
const esmFileContents = Object.values(contents.esm);
35+
expect(esmFileNames).toMatchInlineSnapshot(`
2936
[
3037
"<ROOT>/tests/integration/style/sass/bundle-false/dist/esm/foundation/_code.css",
3138
"<ROOT>/tests/integration/style/sass/bundle-false/dist/esm/foundation/_lists.css",
3239
"<ROOT>/tests/integration/style/sass/bundle-false/dist/esm/foundation/index.css",
3340
"<ROOT>/tests/integration/style/sass/bundle-false/dist/esm/index.css",
3441
]
3542
`);
43+
expect(esmFileContents).toMatchSnapshot();
3644

37-
const cjsFiles = Object.keys(contents.cjs);
38-
expect(cjsFiles).toMatchInlineSnapshot(`
45+
const cjsFileNames = Object.keys(contents.cjs);
46+
const cjsFileContents = Object.values(contents.cjs);
47+
expect(cjsFileNames).toMatchInlineSnapshot(`
3948
[
4049
"<ROOT>/tests/integration/style/sass/bundle-false/dist/cjs/foundation/_code.css",
4150
"<ROOT>/tests/integration/style/sass/bundle-false/dist/cjs/foundation/_lists.css",
4251
"<ROOT>/tests/integration/style/sass/bundle-false/dist/cjs/foundation/index.css",
4352
"<ROOT>/tests/integration/style/sass/bundle-false/dist/cjs/index.css",
4453
]
4554
`);
55+
expect(cjsFileContents).toMatchSnapshot();
4656
});

0 commit comments

Comments
 (0)