From 97761ba9e37347134c801c31ce5f59027e3c2092 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Thu, 4 Apr 2024 12:15:41 -0700 Subject: [PATCH 1/2] Use vscode-test script instead of test-runner package. --- ide/packages/itests/.vscode-test.js | 14 +++++ ide/packages/itests/package.json | 13 ++-- ide/packages/itests/src/main.ts | 44 ------------- ide/packages/itests/tests/add.test.ts | 5 -- ide/packages/itests/vite.config.ts | 5 +- ide/packages/itests/workspaces | 1 + ide/packages/test-runner/.eslintrc.cjs | 6 -- ide/packages/test-runner/package.json | 22 ------- ide/packages/test-runner/src/constants.ts | 1 - ide/packages/test-runner/src/main.ts | 77 ----------------------- ide/packages/test-runner/src/workspaces | 1 - ide/packages/test-runner/tsconfig.json | 9 --- ide/packages/test-runner/vite.config.ts | 28 --------- ide/pnpm-lock.yaml | 30 +++------ 14 files changed, 31 insertions(+), 225 deletions(-) create mode 100644 ide/packages/itests/.vscode-test.js delete mode 100644 ide/packages/itests/src/main.ts delete mode 100644 ide/packages/itests/tests/add.test.ts create mode 120000 ide/packages/itests/workspaces delete mode 100644 ide/packages/test-runner/.eslintrc.cjs delete mode 100644 ide/packages/test-runner/package.json delete mode 100644 ide/packages/test-runner/src/constants.ts delete mode 100644 ide/packages/test-runner/src/main.ts delete mode 120000 ide/packages/test-runner/src/workspaces delete mode 100644 ide/packages/test-runner/tsconfig.json delete mode 100644 ide/packages/test-runner/vite.config.ts diff --git a/ide/packages/itests/.vscode-test.js b/ide/packages/itests/.vscode-test.js new file mode 100644 index 0000000..fe1b969 --- /dev/null +++ b/ide/packages/itests/.vscode-test.js @@ -0,0 +1,14 @@ +import { defineConfig } from "@vscode/test-cli"; +import fs from "fs"; +import path from "path"; + +let workspaces = fs + .readdirSync("workspaces") + .map(p => path.join("workspaces", p)); + +let configs = workspaces.map(ws => ({ + files: "dist/*.cjs", + workspaceFolder: ws, +})); + +export default defineConfig(configs); diff --git a/ide/packages/itests/package.json b/ide/packages/itests/package.json index d801563..7c390a3 100644 --- a/ide/packages/itests/package.json +++ b/ide/packages/itests/package.json @@ -1,12 +1,10 @@ { "name": "@argus/itests", "version": "0.1.0", - "bin": { - "itests": "dist/itests.cjs" - }, "type": "module", "depot": { - "platform": "node" + "platform": "node", + "target": "script" }, "dependencies": { "mocha": "^10.4.0" @@ -15,8 +13,9 @@ "@types/chai": "^4.3.14", "@types/glob": "^8.1.0", "@types/mocha": "^10.0.6", - "chai": "^5.1.0", - "glob": "^8.1.0", - "mocha": "^10.4.0" + "@vscode/test-cli": "^0.0.6", + "@vscode/test-electron": "^2.3.9", + "chai": "^5.1.0", + "glob": "^8.1.0" } } \ No newline at end of file diff --git a/ide/packages/itests/src/main.ts b/ide/packages/itests/src/main.ts deleted file mode 100644 index 7b54b94..0000000 --- a/ide/packages/itests/src/main.ts +++ /dev/null @@ -1,44 +0,0 @@ -import Mocha from "mocha"; - -import "./add.test.ts"; - -export async function run(): Promise { - console.debug("RUNNING TESTS"); - - // Create the mocha test - const mocha = new Mocha({ - ui: "tdd", - color: true, - }); - - return new Promise(function (resolve, reject) { - try { - // FIXME: note to self. - // - // The global Mocha context isn't getting set, because the EVENT_FILE_PRE_REQUIRE - // isn't getting emitted for "loaded" files. This normally gets emitted after - // files are added to Mocha, and then they are prepared before running. - // Manually emitting the event doesn't do anything, because the problem is having the - // tests bundled and loaded in the first place. - // - // ste.emit(Suite.constants.EVENT_FILE_PRE_REQUIRE, mocha); - // - // Using vitest isn't working either for similar reasons. It has an added problem - // of introducing @types/chai mismatch problems due to namespace exports. This is - // an open issue on the vitest repo. - - // Run the mocha test - mocha.timeout(10000); - - mocha.run(function (failures) { - if (failures > 0) { - reject(new Error(`${failures} tests failed.`)); - } else { - resolve(); - } - }); - } catch (err) { - reject(err); - } - }); -} diff --git a/ide/packages/itests/tests/add.test.ts b/ide/packages/itests/tests/add.test.ts deleted file mode 100644 index cecc313..0000000 --- a/ide/packages/itests/tests/add.test.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { expect, test } from "vitest"; - -import { add } from "../src/lib"; - -test("add", () => expect(add(2, 2)).toBe(4)); diff --git a/ide/packages/itests/vite.config.ts b/ide/packages/itests/vite.config.ts index dc4177d..095a6ec 100644 --- a/ide/packages/itests/vite.config.ts +++ b/ide/packages/itests/vite.config.ts @@ -1,13 +1,14 @@ import fs from "fs"; import { builtinModules } from "module"; -import { resolve } from "path"; +import path from "path"; import { defineConfig } from "vite"; +let tests = fs.readdirSync("src").map(p => path.join("src", p)); let manifest = JSON.parse(fs.readFileSync("package.json", "utf-8")); export default defineConfig(({ mode }) => ({ build: { lib: { - entry: resolve(__dirname, "src/main.ts"), + entry: tests, formats: ["cjs"], }, minify: false, diff --git a/ide/packages/itests/workspaces b/ide/packages/itests/workspaces new file mode 120000 index 0000000..14c97e4 --- /dev/null +++ b/ide/packages/itests/workspaces @@ -0,0 +1 @@ +../../../crates/argus_cli/tests/workspaces \ No newline at end of file diff --git a/ide/packages/test-runner/.eslintrc.cjs b/ide/packages/test-runner/.eslintrc.cjs deleted file mode 100644 index cb293e7..0000000 --- a/ide/packages/test-runner/.eslintrc.cjs +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - "extends": "../../.eslintrc.cjs", - "env": { - "node": true - } -} \ No newline at end of file diff --git a/ide/packages/test-runner/package.json b/ide/packages/test-runner/package.json deleted file mode 100644 index b0bfdf0..0000000 --- a/ide/packages/test-runner/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "@argus/test-runner", - "version": "0.1.0", - "bin": { - "test-runner": "dist/test-runner.cjs" - }, - "type": "module", - "depot": { - "platform": "node" - }, - "dependencies": { - "@argus/itests": "workspace:*", - "argus": "workspace:*", - "mocha": "^10.4.0" - }, - "devDependencies": { - "@vscode/test-cli": "^0.0.6", - "@vscode/test-electron": "^2.3.9", - "mocha": "^10.4.0", - "vite": "^4.4.9" - } -} \ No newline at end of file diff --git a/ide/packages/test-runner/src/constants.ts b/ide/packages/test-runner/src/constants.ts deleted file mode 100644 index c443a79..0000000 --- a/ide/packages/test-runner/src/constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const TEST_WORKSPACES = "workspaces/"; diff --git a/ide/packages/test-runner/src/main.ts b/ide/packages/test-runner/src/main.ts deleted file mode 100644 index 687f82d..0000000 --- a/ide/packages/test-runner/src/main.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { runTests } from "@vscode/test-electron"; -import path from "path"; - -import { TEST_WORKSPACES } from "./constants"; - -async function runOnWorkspace(workspace: string) { - // The folder containing the Extension Manifest package.json - // Passed to `--extensionDevelopmentPath` - const extensionDevelopmentPath = path.resolve( - __dirname, - "..", - "node_modules", - "argus" - ); - - // The path to the extension test runner script - // Passed to --extensionTestsPath - const extensionTestsPath = path.resolve( - __dirname, - "..", - "node_modules", - "@argus/itests", - "dist", - "itests.cjs" - ); - - // Get all .rs files in ${workspace}/src/**.rs - // const workspaceFiles = path.resolve(workspace, "src/**/*.rs"); - const _launchArgs = ["--disable-extensions", workspace]; - - // Download VS Code, unzip it and run the integration test - await runTests({ - version: "stable", - // launchArgs, - extensionDevelopmentPath, - extensionTestsPath, - }); -} - -async function main() { - const workspaceDirectory = path.resolve( - __dirname, - "..", - "src", - TEST_WORKSPACES - ); - - await runOnWorkspace(path.resolve(workspaceDirectory, "bevy")).catch(err => { - // console.error(`Failed to run tests on workspace: ${workspace}`); - console.error(err); - throw new Error(err); - }); - - // // Get all subdirectories of TEST_WORKSPACES - // const workspaces = fs.readdirSync(workspaceDirectory); - - // // for each subdirectory of TEST_WORKSPACES, run the tests - // const testingWorkspaces = workspaces.map(async workspace => { - // // FIXME: remove after testing - // if (workspace === "bevy") { - // await runOnWorkspace(path.resolve(workspaceDirectory, workspace)).catch( - // err => { - // console.error(`Failed to run tests on workspace: ${workspace}`); - // console.error(err); - // throw new Error(err); - // } - // ); - // } - // }); - - // await Promise.all(testingWorkspaces); -} - -main().catch(err => { - console.log(err); - process.exit(1); -}); diff --git a/ide/packages/test-runner/src/workspaces b/ide/packages/test-runner/src/workspaces deleted file mode 120000 index d8fec46..0000000 --- a/ide/packages/test-runner/src/workspaces +++ /dev/null @@ -1 +0,0 @@ -../../../../crates/argus_cli/tests/workspaces \ No newline at end of file diff --git a/ide/packages/test-runner/tsconfig.json b/ide/packages/test-runner/tsconfig.json deleted file mode 100644 index 2d8f520..0000000 --- a/ide/packages/test-runner/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "include": [ - "src" - ], - "compilerOptions": { - "noEmit": true - } -} \ No newline at end of file diff --git a/ide/packages/test-runner/vite.config.ts b/ide/packages/test-runner/vite.config.ts deleted file mode 100644 index c18e843..0000000 --- a/ide/packages/test-runner/vite.config.ts +++ /dev/null @@ -1,28 +0,0 @@ -import fs from "fs"; -import { defineConfig } from "vite"; -import { builtinModules } from "module"; -import { resolve } from "path"; - -let manifest = JSON.parse(fs.readFileSync("package.json", "utf-8")); -export default defineConfig(({ mode }) => ({ - build: { - lib: { - entry: resolve(__dirname, "src/main.ts"), - formats: ["cjs"], - }, - minify: false, - rollupOptions: { - external: Object.keys(manifest.dependencies || {}).concat(builtinModules) - } - }, - define: { - "process.env.NODE_ENV": JSON.stringify(mode), - }, - test: { - environment: "node", - deps: { - inline: [/^(?!.*vitest).*$/], - }, - }, - resolve: {conditions: ["node"]}, -})); diff --git a/ide/pnpm-lock.yaml b/ide/pnpm-lock.yaml index df12259..d7ee208 100644 --- a/ide/pnpm-lock.yaml +++ b/ide/pnpm-lock.yaml @@ -159,6 +159,12 @@ importers: '@types/mocha': specifier: ^10.0.6 version: 10.0.6 + '@vscode/test-cli': + specifier: ^0.0.6 + version: 0.0.6 + '@vscode/test-electron': + specifier: ^2.3.9 + version: 2.3.9 chai: specifier: ^5.1.0 version: 5.1.0 @@ -246,28 +252,6 @@ importers: packages/system: {} - packages/test-runner: - dependencies: - '@argus/itests': - specifier: workspace:* - version: link:../itests - argus: - specifier: workspace:* - version: link:../extension - mocha: - specifier: ^10.4.0 - version: 10.4.0 - devDependencies: - '@vscode/test-cli': - specifier: ^0.0.6 - version: 0.0.6 - '@vscode/test-electron': - specifier: ^2.3.9 - version: 2.3.9 - vite: - specifier: ^4.4.9 - version: 4.4.9(@types/node@20.2.5) - packages: /@aashutoshrathi/word-wrap@1.2.6: @@ -1775,7 +1759,7 @@ packages: dev: true /concat-map@0.0.1: - resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} + resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} dev: true /convert-source-map@2.0.0: From a878474cd66cef5026b6a3599955fad94fbbd746 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Thu, 4 Apr 2024 12:20:36 -0700 Subject: [PATCH 2/2] Update depot in CI --- .github/workflows/setup/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/setup/action.yml b/.github/workflows/setup/action.yml index 8013869..d85c8bf 100644 --- a/.github/workflows/setup/action.yml +++ b/.github/workflows/setup/action.yml @@ -13,7 +13,7 @@ runs: shell: bash - name: Install Depot - run: curl https://raw.githubusercontent.com/cognitive-engineering-lab/depot/main/scripts/install.sh | sh + run: curl https://raw.githubusercontent.com/cognitive-engineering-lab/depot/main/scripts/install.sh | sh -s e92a63edcb17cf156e399587b79192369911560e shell: bash - name: Install Test Libraries