-
Notifications
You must be signed in to change notification settings - Fork 417
Expand file tree
/
Copy pathtreeshake.server.test.ts
More file actions
30 lines (24 loc) · 1.32 KB
/
treeshake.server.test.ts
File metadata and controls
30 lines (24 loc) · 1.32 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
import { describe, expect, it } from "vitest";
import { getBuildOutputDirs, getFiles, readFileContent } from "~/utils/build-output-utils";
describe("Make sure treeshaking works", () => {
it("should not have any unused code in the client-bundle", async () => {
const { clientOutputRoot } = getBuildOutputDirs();
const files = await getFiles(clientOutputRoot, /^\(no-side-effects\)-.*\.js(\.gz|\.br)?$/);
expect(files.length, "No files matching the treeshaking pattern found").toBeGreaterThan(0);
for (const targetFile of files) {
const file = await readFileContent(targetFile);
const result = file.includes("myTreeshakingTestUniqueString1");
expect(result, `Unused code found in file: ${targetFile}`).toBeFalsy();
}
});
it("should include side-effects code in the client-bundle", async () => {
const { clientOutputRoot } = getBuildOutputDirs();
const files = await getFiles(clientOutputRoot, /^side-effects.*\.js(\.gz|\.br)?$/);
expect(files.length, "No side-effects files matching the pattern found").toBeGreaterThan(0);
for (const targetFile of files) {
const file = await readFileContent(targetFile);
const result = file.includes("myTreeshakingTestUniqueString2");
expect(result, `Side-effects code not found in file: ${targetFile}`).toBeTruthy();
}
});
});