diff options
author | Kirill Dubovitskiy <kirill2003de@gmail.com> | 2023-08-07 14:54:37 -0700 |
---|---|---|
committer | Kirill Dubovitskiy <kirill2003de@gmail.com> | 2023-08-07 15:25:11 -0700 |
commit | c12be8daf60cd3d5554e9f5465aa5e8a5187d288 (patch) | |
tree | 9e92dc4a10004ec13cb2bfb45be8828bd2fb4dc6 /extension/esbuild.test.mjs | |
parent | 0fc56305d762181519569098a99faa255f9cd24f (diff) | |
download | sncontinue-c12be8daf60cd3d5554e9f5465aa5e8a5187d288.tar.gz sncontinue-c12be8daf60cd3d5554e9f5465aa5e8a5187d288.tar.bz2 sncontinue-c12be8daf60cd3d5554e9f5465aa5e8a5187d288.zip |
Refactor test scripts and update build configurations
- Added a new esbuild for:
- bundling test runners (run tests on vscode + mocha runner)
- bundling all tests in the project
- Some opinionated renamings / moving test related things around
- Changed output directory in tsconfig to avoid overriding the entire out directory - bundles tests also go there
Some poking around trying to deprecate jest as it is not used and mocha is more often used for vscode extension testing.
Though I assume jest was added to test GUI within extension.
This work was started because there are compilation issues with the current setup and neither of the tests are actually working so figured getting one to a working spot is a good start
Diffstat (limited to 'extension/esbuild.test.mjs')
-rw-r--r-- | extension/esbuild.test.mjs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/extension/esbuild.test.mjs b/extension/esbuild.test.mjs new file mode 100644 index 00000000..fdffd3da --- /dev/null +++ b/extension/esbuild.test.mjs @@ -0,0 +1,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 usig 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", + }, +}); |