Skip to content

Commit 6d140bb

Browse files
committed
setup webpack integration tests
1 parent 69ad701 commit 6d140bb

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
- cli
3232
- postcss
3333
- workers
34+
- webpack
3435

3536
# Exclude windows and macos from being built on feature branches
3637
run-all:

integrations/webpack/index.test.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { css, html, js, json, test } from '../utils'
2+
3+
test(
4+
'Webpack + PostCSS (watch)',
5+
{
6+
fs: {
7+
'package.json': json`
8+
{
9+
"main": "./src/index.js",
10+
"browser": "./src/index.js",
11+
"dependencies": {
12+
"css-loader": "^6",
13+
"postcss": "^8",
14+
"postcss-loader": "^7",
15+
"webpack": "^5",
16+
"webpack-cli": "^5",
17+
"mini-css-extract-plugin": "^2",
18+
"tailwindcss": "workspace:^",
19+
"@tailwindcss/postcss": "workspace:^"
20+
}
21+
}
22+
`,
23+
'postcss.config.js': js`
24+
/** @type {import('postcss-load-config').Config} */
25+
module.exports = {
26+
plugins: {
27+
'@tailwindcss/postcss': {},
28+
},
29+
}
30+
`,
31+
'webpack.config.js': js`
32+
let MiniCssExtractPlugin = require('mini-css-extract-plugin')
33+
34+
module.exports = {
35+
plugins: [new MiniCssExtractPlugin()],
36+
module: {
37+
rules: [
38+
{
39+
test: /.css$/i,
40+
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
41+
},
42+
],
43+
},
44+
}
45+
`,
46+
'src/index.js': js`import './index.css'`,
47+
'src/index.html': html`
48+
<div class="flex"></div>
49+
`,
50+
'src/index.css': css`
51+
@import 'tailwindcss/theme';
52+
@import 'tailwindcss/utilities';
53+
`,
54+
'src/unrelated.module.css': css`
55+
.module {
56+
color: var(--color-blue-500);
57+
}
58+
`,
59+
},
60+
},
61+
async ({ fs, spawn, exec, expect }) => {
62+
// Generate the initial build so output CSS files exist on disk
63+
await exec('webpack --mode=development')
64+
65+
// NOTE: We are writing to an output CSS file which is not being ignored by
66+
// `.gitignore` nor marked with `@source not`. This should not result in an
67+
// infinite loop.
68+
let process = await spawn('webpack --mode=development --watch')
69+
await process.onStdout((m) => m.includes('compiled successfully in'))
70+
71+
expect(await fs.dumpFiles('./dist/*.css')).toMatchInlineSnapshot(`
72+
"
73+
--- ./dist/main.css ---
74+
:root, :host {
75+
--color-blue-500: oklch(0.623 0.214 259.815);
76+
}
77+
.flex {
78+
display: flex;
79+
}
80+
"
81+
`)
82+
83+
await fs.write(
84+
'src/unrelated.module.css',
85+
css`
86+
.module {
87+
color: var(--color-blue-500);
88+
background-color: var(--color-red-500);
89+
}
90+
`,
91+
)
92+
await process.onStdout((m) => m.includes('compiled successfully in'))
93+
94+
expect(await fs.dumpFiles('./dist/*.css')).toMatchInlineSnapshot(`
95+
"
96+
--- ./dist/main.css ---
97+
:root, :host {
98+
--color-red-500: oklch(0.637 0.237 25.331);
99+
--color-blue-500: oklch(0.623 0.214 259.815);
100+
}
101+
.flex {
102+
display: flex;
103+
}
104+
"
105+
`)
106+
},
107+
)

0 commit comments

Comments
 (0)