Skip to content

Commit c2764ab

Browse files
test: restore three minified parser fixture
1 parent 8b8dc74 commit c2764ab

2 files changed

Lines changed: 44 additions & 9 deletions

File tree

‎test/benchmarkCases/js-parser-unit/index.bench.mjs‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ const typescriptSource = fs.readFileSync(
2929
// "three" import condition resolves to build/three.module.js
3030
const threeEsmPath = fileURLToPath(import.meta.resolve("three"));
3131
const threeEsmSource = fs.readFileSync(threeEsmPath, "utf8");
32+
const threeEsmMinSource = fs.readFileSync(
33+
fileURLToPath(
34+
new URL("../../js/benchmark/three.module.min.js", import.meta.url)
35+
),
36+
"utf8"
37+
);
3238
// Popular libraries also shipped as devDependencies.
3339
const reactSource = readPkgFile("react", "cjs/react.development.js");
3440
const reactDomSource = readPkgFile("react-dom", "cjs/react-dom.development.js");
3541
const lodashSource = readPkgFile("lodash", "lodash.js");
36-
const lodashMinSource = readPkgFile("lodash", "lodash.min.js");
3742
const lodashEsSource = readPkgFile("lodash-es", "lodash.js");
3843

3944
// Tokenize-only: drive WebpackParser's owned tokenizer to EOF, no AST/walk.
@@ -89,9 +94,12 @@ export default (bench) => {
8994
new JavascriptParser("module").parse(threeEsmSource, {});
9095
}
9196
);
92-
bench.add("unit benchmark \"js-parser-unit\", source 'lodash.min.js'", () => {
93-
new JavascriptParser("auto").parse(lodashMinSource, {});
94-
});
97+
bench.add(
98+
"unit benchmark \"js-parser-unit\", source 'three.module.min.js'",
99+
() => {
100+
new JavascriptParser("module").parse(threeEsmMinSource, {});
101+
}
102+
);
95103
bench.add(
96104
"unit benchmark \"js-parser-unit\", source 'react.development.js'",
97105
() => {
@@ -116,10 +124,13 @@ export default (bench) => {
116124
bench.add('unit benchmark "js-parser-unit", tokenize typescript', () => {
117125
tokenizeJs(typescriptSource, "module");
118126
});
119-
bench.add('unit benchmark "js-parser-unit", tokenize lodash.js', () => {
120-
tokenizeJs(lodashSource, "script");
121-
});
122-
bench.add('unit benchmark "js-parser-unit", tokenize lodash.min.js', () => {
123-
tokenizeJs(lodashMinSource, "script");
127+
bench.add('unit benchmark "js-parser-unit", tokenize three.module.js', () => {
128+
tokenizeJs(threeEsmSource, "module");
124129
});
130+
bench.add(
131+
'unit benchmark "js-parser-unit", tokenize three.module.min.js',
132+
() => {
133+
tokenizeJs(threeEsmMinSource, "module");
134+
}
135+
);
125136
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import fs from "fs/promises";
2+
import { fileURLToPath } from "url";
3+
import { minify } from "terser";
4+
5+
export async function setup() {
6+
const source = await fs.readFile(
7+
fileURLToPath(import.meta.resolve("three")),
8+
"utf8"
9+
);
10+
const { code } = await minify(source, { module: true });
11+
12+
if (!code) {
13+
throw new Error("Failed to minify the three ESM fixture");
14+
}
15+
16+
const outputPath = fileURLToPath(
17+
new URL("../../js/benchmark/three.module.min.js", import.meta.url)
18+
);
19+
20+
await fs.mkdir(new URL("../../js/benchmark/", import.meta.url), {
21+
recursive: true
22+
});
23+
await fs.writeFile(outputPath, code);
24+
}

0 commit comments

Comments
 (0)