Skip to content

Commit 8368be1

Browse files
authored
test(e2e): add enableCssModuleTSDeclaration and disableCssExtract e2e cases (#3704)
* fix: add enableCssModuleTSDeclaration and disableCssExtract test case * fix: migrate some css test case from tests/integration to e2e/builder * fix: remove repeated test case
1 parent 4b03d17 commit 8368be1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+215
-791
lines changed

pnpm-lock.yaml

Lines changed: 0 additions & 151 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist-1
2+
dist-2
3+
*.d.ts
4+
!types.d.ts
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
html,
2+
body {
3+
padding: 0;
4+
margin: 0;
5+
font-family: nunito_for_arco, Helvetica Neue, Helvetica, PingFang SC,
6+
Hiragino Sans GB, Microsoft YaHei, 微软雅黑, Arial, sans-serif;
7+
}
8+
9+
* {
10+
-webkit-font-smoothing: antialiased;
11+
-moz-osx-font-smoothing: grayscale;
12+
box-sizing: border-box;
13+
}
14+
15+
.description {
16+
text-align: center;
17+
line-height: 1.5;
18+
font-size: 16px;
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.title {
2+
text-align: center;
3+
color: blue;
4+
font-size: 20px;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.header {
2+
text-align: center;
3+
color: red;
4+
font-size: 20px;
5+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import './App.css';
3+
import stylesForSass from './App.module.scss';
4+
import stylesForLess from './App.module.less';
5+
6+
const App = () => (
7+
<div className="container">
8+
<p className={stylesForSass.header} id="header">
9+
header
10+
</p>
11+
<p className={stylesForLess.title} id="title">
12+
title
13+
</p>
14+
<p className="description" id="description">
15+
description
16+
</p>
17+
</div>
18+
);
19+
20+
export default App;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
import { render } from 'react-dom';
3+
import App from './App';
4+
5+
render(React.createElement(App), document.getElementById('root'));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module '*.module.css';
2+
declare module '*.module.scss';
3+
declare module '*.module.less';
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { join, resolve } from 'path';
2+
import { fs } from '@modern-js/utils';
3+
import { build, getHrefByEntryName } from '@scripts/shared';
4+
import { webpackOnlyTest } from '@scripts/helper';
5+
import { expect } from '@modern-js/e2e/playwright';
6+
7+
const fixtures = resolve(__dirname, '../');
8+
9+
webpackOnlyTest('enableCssModuleTSDeclaration', async () => {
10+
fs.removeSync(join(fixtures, 'src/App.module.less.d.ts'));
11+
fs.removeSync(join(fixtures, 'src/App.module.scss.d.ts'));
12+
const buildOpts = {
13+
cwd: fixtures,
14+
entry: {
15+
main: join(fixtures, 'src/index.ts'),
16+
},
17+
};
18+
19+
const builder = await build(
20+
buildOpts,
21+
{
22+
output: {
23+
enableCssModuleTSDeclaration: true,
24+
},
25+
},
26+
false,
27+
);
28+
29+
expect(
30+
fs.existsSync(join(fixtures, 'src/App.module.less.d.ts')),
31+
).toBeTruthy();
32+
33+
expect(
34+
fs
35+
.readFileSync(join(fixtures, 'src/App.module.less.d.ts'), {
36+
encoding: 'utf-8',
37+
})
38+
.includes(`'title': string;`),
39+
).toBeTruthy();
40+
41+
expect(
42+
fs.existsSync(join(fixtures, 'src/App.module.scss.d.ts')),
43+
).toBeTruthy();
44+
45+
expect(
46+
fs
47+
.readFileSync(join(fixtures, 'src/App.module.scss.d.ts'), {
48+
encoding: 'utf-8',
49+
})
50+
.includes(`'header': string;`),
51+
).toBeTruthy();
52+
53+
builder.close();
54+
});
55+
56+
webpackOnlyTest('disableCssExtract', async ({ page }) => {
57+
const buildOpts = {
58+
cwd: fixtures,
59+
entry: {
60+
main: join(fixtures, 'src/index.ts'),
61+
},
62+
};
63+
64+
const builder = await build(buildOpts, {
65+
output: {
66+
disableCssExtract: true,
67+
},
68+
});
69+
70+
await page.goto(getHrefByEntryName('main', builder.port));
71+
72+
// disableCssExtract worked
73+
const files = await builder.unwrapOutputJSON();
74+
const cssFiles = Object.keys(files).filter(file => file.endsWith('.css'));
75+
76+
expect(cssFiles.length).toBe(0);
77+
78+
// scss worked
79+
await expect(
80+
page.evaluate(
81+
`window.getComputedStyle(document.getElementById('header')).fontSize`,
82+
),
83+
).resolves.toBe('20px');
84+
85+
// less worked
86+
await expect(
87+
page.evaluate(
88+
`window.getComputedStyle(document.getElementById('title')).fontSize`,
89+
),
90+
).resolves.toBe('20px');
91+
92+
builder.close();
93+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "@modern-js/tsconfig/base",
3+
"compilerOptions": {
4+
"declaration": false,
5+
"jsx": "react-jsx",
6+
"baseUrl": "./",
7+
"outDir": "./dist",
8+
"paths": {
9+
"@scripts/*": ["../../../scripts/*"]
10+
}
11+
},
12+
"include": ["src", "tests"]
13+
}

0 commit comments

Comments
 (0)