Skip to content

Commit b798a3c

Browse files
committed
Add tests
1 parent d908a12 commit b798a3c

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

lib/__tests__/declarations.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module "*?raw";

lib/__tests__/index.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { beforeAll, describe, test } from "vitest";
2+
import esbuild from "esbuild";
3+
import path from "node:path";
4+
import { raw } from "../src";
5+
import fs from "node:fs";
6+
7+
describe("WebGL plugins", () => {
8+
beforeAll(async () => {
9+
await esbuild.build({
10+
format: "cjs",
11+
target: "es2019",
12+
sourcemap: false,
13+
bundle: true,
14+
minify: true,
15+
entryPoints: [path.resolve(__dirname, "test.ts")],
16+
outdir: "__tests__/dist",
17+
treeShaking: true,
18+
plugins: [raw()],
19+
});
20+
});
21+
test("test raw import", async ({ expect }) => {
22+
const fileContent = fs.readFileSync(path.resolve(__dirname, "../src/index.ts"), "utf-8");
23+
// @ts-ignore
24+
const generatedCodeContent = (await import("./dist/test.js")).getText();
25+
expect(fileContent).toBe(generatedCodeContent);
26+
});
27+
});

lib/__tests__/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import text from "../src/index.ts?raw";
2+
3+
export const getText = () => text;

lib/vitest.config.mts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import tsconfigPaths from "vite-tsconfig-paths";
66
export default defineConfig({
77
plugins: [react(), tsconfigPaths()],
88
test: {
9-
environment: "jsdom",
9+
environment: "node",
1010
globals: true,
1111
setupFiles: [],
1212
coverage: {
1313
include: ["src/**"],
14-
exclude: ["src/**/index.ts", "src/**/*.test.*", "src/**/declaration.d.ts"],
1514
reporter: ["text", "json", "clover", "html"],
1615
},
1716
},

0 commit comments

Comments
 (0)