-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.test.ts
More file actions
59 lines (51 loc) · 1.55 KB
/
index.test.ts
File metadata and controls
59 lines (51 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import fs from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test } from '@playwright/test';
import { createRsbuild } from '@rsbuild/core';
import { pluginTailwindCSS } from '../../src';
const __dirname = dirname(fileURLToPath(import.meta.url));
const themePath = join(__dirname, 'src/theme.css');
test('should update styles when theme file changes', async ({ page }) => {
// Reset theme file
fs.writeFileSync(
themePath,
`
@theme {
--color-dynamic: rgb(1, 2, 3);
}
`,
);
const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: {
plugins: [pluginTailwindCSS()],
},
});
// First build
await rsbuild.build();
let result = await rsbuild.preview();
await page.goto(result.urls[0]);
let locator = page.locator('#dynamic');
await expect(locator).toHaveCSS('background-color', 'rgb(1, 2, 3)');
await result.server.close();
// Modify theme file
fs.writeFileSync(
themePath,
`
@theme {
--color-dynamic: rgb(4, 5, 6);
}
`,
);
// Second build (reusing instance if possible, or creating new one if that's how tests work)
// The user asked to "Same createRsbuild instance" if possible.
// rsbuild.build() runs the build.
// We can run it again.
await rsbuild.build();
result = await rsbuild.preview(); // New preview server
await page.goto(result.urls[0]);
locator = page.locator('#dynamic');
await expect(locator).toHaveCSS('background-color', 'rgb(4, 5, 6)');
await result.server.close();
});