-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
/
vite-css-build-test.ts
198 lines (181 loc) · 5.95 KB
/
vite-css-build-test.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import { test, expect } from "@playwright/test";
import fs from "node:fs/promises";
import path from "node:path";
import url from "node:url";
import {
createAppFixture,
createFixture,
js,
css,
} from "./helpers/create-fixture.js";
import type { Fixture, AppFixture } from "./helpers/create-fixture.js";
import { PlaywrightFixture } from "./helpers/playwright-fixture.js";
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const TEST_PADDING_VALUE = "20px";
test.describe("Vite CSS build", () => {
let fixture: Fixture;
let appFixture: AppFixture;
test.beforeAll(async () => {
// set sideEffects for global vanilla extract css
let packageJson = JSON.parse(
await fs.readFile(
path.resolve(__dirname, "helpers", "node-template", "package.json"),
"utf-8"
)
);
packageJson.sideEffects = ["*.css.ts"];
fixture = await createFixture({
compiler: "vite",
files: {
"package.json": JSON.stringify(packageJson, null, 2),
"remix.config.js": js`
throw new Error("Remix should not access remix.config.js when using Vite");
export default {};
`,
"vite.config.ts": js`
import { defineConfig } from "vite";
import { unstable_vitePlugin as remix } from "@remix-run/dev";
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
export default defineConfig({
plugins: [
vanillaExtractPlugin(),
remix(),
],
});
`,
"app/entry.client.tsx": js`
import "./entry.client.css";
import { RemixBrowser } from "@remix-run/react";
import { startTransition, StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";
startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
</StrictMode>
);
});
`,
"app/root.tsx": js`
import { Links, Meta, Outlet, Scripts } from "@remix-run/react";
export default function Root() {
return (
<html lang="en">
<head>
<Meta />
<Links />
</head>
<body>
<div id="content">
<Outlet />
</div>
<Scripts />
</body>
</html>
);
}
`,
"app/entry.client.css": css`
.client-entry {
background: pink;
padding: ${TEST_PADDING_VALUE};
}
`,
"app/routes/_index/styles-bundled.css": css`
.index_bundled {
background: papayawhip;
padding: ${TEST_PADDING_VALUE};
}
`,
"app/routes/_index/styles-linked.css": css`
.index_linked {
background: mintcream;
padding: ${TEST_PADDING_VALUE};
}
`,
"app/routes/_index/styles.module.css": css`
.index {
background: peachpuff;
padding: ${TEST_PADDING_VALUE};
}
`,
"app/routes/_index/styles-vanilla-global.css.ts": js`
import { globalStyle } from "@vanilla-extract/css";
globalStyle(".index_vanilla_global", {
background: "lightgreen",
padding: "${TEST_PADDING_VALUE}",
});
`,
"app/routes/_index/styles-vanilla-local.css.ts": js`
import { style } from "@vanilla-extract/css";
export const index = style({
background: "lightblue",
padding: "${TEST_PADDING_VALUE}",
});
`,
"app/routes/_index/route.tsx": js`
import "./styles-bundled.css";
import linkedStyles from "./styles-linked.css?url";
import cssModulesStyles from "./styles.module.css";
import "./styles-vanilla-global.css";
import * as stylesVanillaLocal from "./styles-vanilla-local.css";
export function links() {
return [{ rel: "stylesheet", href: linkedStyles }];
}
export default function IndexRoute() {
return (
<div id="index">
<div data-client-entry className="client-entry">
<div data-css-modules className={cssModulesStyles.index}>
<div data-css-linked className="index_linked">
<div data-css-bundled className="index_bundled">
<div data-css-vanilla-global className="index_vanilla_global">
<div data-css-vanilla-local className={stylesVanillaLocal.index}>
<h2>CSS test</h2>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
);
}
`,
},
});
appFixture = await createAppFixture(fixture);
});
test.afterAll(() => {
appFixture.close();
});
test("renders styles", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/");
await expect(page.locator("#index [data-client-entry]")).toHaveCSS(
"padding",
TEST_PADDING_VALUE
);
await expect(page.locator("#index [data-css-modules]")).toHaveCSS(
"padding",
TEST_PADDING_VALUE
);
await expect(page.locator("#index [data-css-linked]")).toHaveCSS(
"padding",
TEST_PADDING_VALUE
);
await expect(page.locator("#index [data-css-bundled]")).toHaveCSS(
"padding",
TEST_PADDING_VALUE
);
await expect(page.locator("#index [data-css-vanilla-global]")).toHaveCSS(
"padding",
TEST_PADDING_VALUE
);
await expect(page.locator("#index [data-css-vanilla-local]")).toHaveCSS(
"padding",
TEST_PADDING_VALUE
);
});
});