Skip to content

Commit 010bdde

Browse files
committed
Update tests
1 parent 8ea378c commit 010bdde

File tree

7 files changed

+339
-3630
lines changed

7 files changed

+339
-3630
lines changed

lib/__tests__/index.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { beforeAll, describe, test } from "vitest";
2+
import esbuild from "esbuild";
3+
import path from "node:path";
4+
import { webglPlugin } from "../src";
5+
6+
describe("WebGL plugins", () => {
7+
beforeAll(async () => {
8+
await esbuild.build({
9+
format: "cjs",
10+
target: "es2019",
11+
sourcemap: false,
12+
bundle: true,
13+
minify: true,
14+
entryPoints: [path.resolve(__dirname, "shaders/render-frag.glsl")],
15+
outdir: "dist",
16+
treeShaking: true,
17+
plugins: [webglPlugin()],
18+
});
19+
});
20+
test("test comments removal", async ({ expect }) => {});
21+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#version 300 es
2+
precision mediump float;
3+
4+
out vec4 c;
5+
6+
/**
7+
block comment explaining the function
8+
*/
9+
void main() { // inline comment
10+
c = vec4(1.0); /** Some comment */
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#version 300 es
2+
precision mediump float;
3+
4+
in vec2 p;
5+
6+
void main() {
7+
gl_PointSize = 1.0;
8+
gl_Position = vec4(p, 0.0, 1.0);
9+
}

lib/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
"@types/react-dom": "^18.3.0",
3333
"@vitejs/plugin-react": "^4.3.1",
3434
"@vitest/coverage-v8": "^1.6.0",
35+
"esbuild": "^0.21.5",
3536
"esbuild-plugin-rdi": "^0.0.0",
3637
"esbuild-plugin-react18": "0.2.4",
3738
"esbuild-plugin-react18-css": "^0.0.4",
38-
"jsdom": "^24.1.0",
3939
"react": "^18.3.1",
4040
"react-dom": "^18.3.1",
4141
"tsup": "^8.1.0",
@@ -85,4 +85,4 @@
8585
"Modern",
8686
"Seamless integration"
8787
]
88-
}
88+
}

lib/src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { Plugin, PluginBuild } from "esbuild";
2+
import fs from "node:fs";
3+
4+
const uuid = () => (Date.now() * Math.random()).toString(36).slice(0, 8);
5+
6+
const name = `webgl-${uuid()}`;
7+
8+
export const webglPlugin: () => Plugin = () => ({
9+
name,
10+
setup(build: PluginBuild) {
11+
build.onLoad({ filter: /\.glsl$/, namespace: "file" }, args => {
12+
const text = fs.readFileSync(args.path, "utf8");
13+
const lines = text
14+
// remove block comments
15+
.replace(/\/\*.*\*\//gm, "")
16+
// remove line comments
17+
.replace(/\/\/.*/g, "")
18+
// remove white spaces around =
19+
.replace(/ = /g, "=")
20+
.split("\n")
21+
.map(line => line.trim())
22+
.filter(Boolean);
23+
const contents = `export default \`${lines[0]}\n${lines.slice(1).join("")}\``;
24+
return { contents, loader: "ts" };
25+
});
26+
},
27+
});

lib/vitest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ 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/**/declaration.d.ts"],
14+
exclude: ["src/**/declaration.d.ts"],
1515
reporter: ["text", "json", "clover", "html"],
1616
},
1717
},

0 commit comments

Comments
 (0)