summaryrefslogtreecommitdiff
path: root/extension/esbuild.test.mjs
blob: f6dc092c22d7027431ae7213809ba251a2db3e06 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as esbuild from "esbuild";
import glob from "glob";

/** 
 * Bundles tests into multiple files, runTestOnVSCodeHost is then run using node runTestOnVSCodeHost.js
 * It downloads vscode, starts it and passes test file to run - mochaRunner.js
 * mochaRunner.js then runs tests using Mocha class
*/

// Bundles script to run tests on VSCode host + mocha runner that will be invoked from within VSCode host
await esbuild.build({
    entryPoints: [
        // Runs mocha runner on VSCode host using runTests from @vscode/test-electron
        "src/test-runner/runTestOnVSCodeHost.ts",

        // Runs the bundled tests using Mocha class
        "src/test-runner/mochaRunner.ts",
    ],
    bundle: true,
    outdir: "out/test-runner",

    external: [
        "vscode",

        // Its important to externalize mocha, otherwise mocha seems to be not initialized properly when running tests
        // Example warning by esbuild when mocha is not externalized:
        // [WARNING] "./reporters/parallel-buffered" should be marked as external for use with "require.resolve" [require-resolve-not-external]
        "mocha",
    ],
    format: "cjs",
    platform: "node",
    sourcemap: true,
    loader: {
        // eslint-disable-next-line @typescript-eslint/naming-convention
        ".node": "file",
    },
});

/**
 * Note: Bundling is done to work around import issues, for example with fkill that does not provide cjs module.
 * Rather than figuring out a combination of tsconfig.json that would work, I decided to bundle tests instead.
 */
await esbuild.build({
    // Tests can be added anywhere in src folder
    entryPoints: glob.sync("src/**/*.test.ts"),
    bundle: true,
    outdir: "out/test-suites",
    external: [
        "vscode",

        // Its important to externalize mocha, otherwise mocha seems to be not initialized properly when running tests
        "mocha",
    ],
    format: "cjs",
    platform: "node",
    sourcemap: true,
    loader: {
        // eslint-disable-next-line @typescript-eslint/naming-convention
        ".node": "file",
    },
});