Elffuss BraidHub

kikocis/continue public

a36aa2a5e5e6 · 2.1 KiBRawPermalink
1import * as esbuild from "esbuild";
2import glob from "glob";
3
4/**
5 * Bundles tests into multiple files, runTestOnVSCodeHost is then run using node runTestOnVSCodeHost.js
6 * It downloads vscode, starts it and passes test file to run - mochaRunner.js
7 * mochaRunner.js then runs tests using Mocha class
8 */
9
10console.log("Bundling tests...");
11
12// Bundles script to run tests on VSCode host + mocha runner that will be invoked from within VSCode host
13await esbuild.build({
14 entryPoints: [
15 // Runs mocha runner on VSCode host using runTests from @vscode/test-electron
16 "src/test/runner/runTestOnVSCodeHost.ts",
17
18 // Runs the bundled tests using Mocha class
19 "src/test/runner/mochaRunner.ts",
20 ],
21 bundle: true,
22 outdir: "out",
23
24 external: [
25 "vscode",
26
27 // Its important to externalize mocha, otherwise mocha seems to be not initialized properly when running tests
28 // Example warning by esbuild when mocha is not externalized:
29 // [WARNING] "./reporters/parallel-buffered" should be marked as external for use with "require.resolve" [require-resolve-not-external]
30 "mocha",
31 ],
32 format: "cjs",
33 platform: "node",
34 sourcemap: true,
35 loader: {
36 // eslint-disable-next-line @typescript-eslint/naming-convention
37 ".node": "file",
38 },
39});
40
41/**
42 * Note: Bundling is done to work around import issues, for example with fkill that does not provide cjs module.
43 * Rather than figuring out a combination of tsconfig.json that would work, I decided to bundle tests instead.
44 */
45await esbuild.build({
46 // Tests can be added anywhere in src folder
47 entryPoints: glob.sync("src/**/*.test.ts"),
48 bundle: true,
49 outdir: "out",
50 external: [
51 "vscode",
52
53 // Its important to externalize mocha, otherwise mocha seems to be not initialized properly when running tests
54 "mocha",
55 ],
56 format: "cjs",
57 platform: "node",
58 sourcemap: true,
59 loader: {
60 // eslint-disable-next-line @typescript-eslint/naming-convention
61 ".node": "file",
62 },
63 // To allow import.meta.path for transformers.js
64 // https://github.com/evanw/esbuild/issues/1492#issuecomment-893144483
65 inject: ["./scripts/importMetaUrl.js"],
66 define: { "import.meta.url": "importMetaUrl" },
67});