From 8c7d9c205034336c4e8e1a901eee978a30b1635d Mon Sep 17 00:00:00 2001 From: Yorgos Saslis Date: Thu, 8 Aug 2024 20:59:00 +0300 Subject: [PATCH] [wip] adds custom test runner this allows us to open VS Code with the radicle repo we have previously created in the e2e tests Signed-off-by: Yorgos Saslis --- .github/workflows/end-to-end-tests.yaml | 2 + package.json | 4 +- pnpm-lock.yaml | 78 +++++++++++++++++-------- src/test/runTest.ts | 38 ++++++++++++ src/test/suite/index.ts | 39 +++++++++++++ 5 files changed, 137 insertions(+), 24 deletions(-) create mode 100644 src/test/runTest.ts create mode 100644 src/test/suite/index.ts diff --git a/.github/workflows/end-to-end-tests.yaml b/.github/workflows/end-to-end-tests.yaml index 2cd35236..0c1dcfcb 100644 --- a/.github/workflows/end-to-end-tests.yaml +++ b/.github/workflows/end-to-end-tests.yaml @@ -1,5 +1,6 @@ name: CI on: +# TODO: when PR is ready to merge, we should adapt these depending on when we actually want this workflow to run # push: # branches: [ main ] # pull_request: @@ -11,6 +12,7 @@ jobs: e2e-test: strategy: matrix: +# TODO: when PR is ready to merge, we should adapt these depending on when we actually want this workflow to run # os: [macos-latest, ubuntu-latest, windows-latest] os: [ubuntu-latest] runs-on: ${{ matrix.os }} diff --git a/package.json b/package.json index 602edbd2..7b02b8b1 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "test:typings:extension": "tsc --noEmit", "test:typings:webviews": "cd ./src/webviews && npm run type-check", "test:unit": "echo \"Unit testing not yet implemented.\"", - "test:e2e": "vscode-test" + "test:e2e": "node ./dist/test/runTest.js" }, "main": "./dist/extension.js", "activationEvents": [ @@ -580,6 +580,7 @@ "@antfu/eslint-config": "^0.39.8", "@total-typescript/ts-reset": "^0.5.1", "@types/javascript-time-ago": "^2.0.8", + "@types/glob": "^7.1.1", "@types/lodash": "^4.17.6", "@types/mocha": "^10.0.6", "@types/node": "^20.11.21", @@ -592,6 +593,7 @@ "eslint-plugin-prettier-vue": "^4.2.0", "eslint-plugin-tailwindcss": "^3.14.3", "eslint-plugin-vue-scoped-css": "^2.7.2", + "glob": "^7.1.4", "npm-run-all": "^4.1.5", "simple-git-hooks": "^2.9.0", "ts-xor": "^1.3.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5b117a06..7091d8bf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,6 +30,9 @@ importers: '@total-typescript/ts-reset': specifier: ^0.5.1 version: 0.5.1 + '@types/glob': + specifier: ^7.1.1 + version: 7.2.0 '@types/javascript-time-ago': specifier: ^2.0.8 version: 2.0.8 @@ -69,6 +72,9 @@ importers: eslint-plugin-vue-scoped-css: specifier: ^2.7.2 version: 2.7.2(eslint@8.57.0)(vue-eslint-parser@9.4.2(eslint@8.57.0)) + glob: + specifier: ^7.1.4 + version: 7.2.3 npm-run-all: specifier: ^4.1.5 version: 4.1.5 @@ -359,6 +365,9 @@ packages: '@total-typescript/ts-reset@0.5.1': resolution: {integrity: sha512-AqlrT8YA1o7Ff5wPfMOL0pvL+1X+sw60NN6CcOCqs658emD6RfiXhF7Gu9QcfKBH7ELY2nInLhKSCWVoNL70MQ==} + '@types/glob@7.2.0': + resolution: {integrity: sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==} + '@types/istanbul-lib-coverage@2.0.6': resolution: {integrity: sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==} @@ -374,6 +383,9 @@ packages: '@types/mdast@3.0.15': resolution: {integrity: sha512-LnwD+mUEfxWMa1QpDraczIn6k0Ee3SMicuYSSzS6ZYl2gKS09EClnJYGd8Du6rfc5r/GZEk5o1mRb8TaTj03sQ==} + '@types/minimatch@5.1.2': + resolution: {integrity: sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==} + '@types/mocha@10.0.7': resolution: {integrity: sha512-GN8yJ1mNTcFcah/wKEFIJckJx9iJLoMSzWcfRRuxz/Jk+U6KQNnml+etbtxFK8lPjzOw3zp4Ha/kjSst9fsHYw==} @@ -1185,13 +1197,13 @@ packages: resolution: {integrity: sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==} engines: {node: '>=10.13.0'} - glob@10.3.10: - resolution: {integrity: sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==} - engines: {node: '>=16 || 14 >=14.17'} + glob@10.4.5: + resolution: {integrity: sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==} hasBin: true glob@7.2.3: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} + deprecated: Glob versions prior to v9 are no longer supported glob@8.1.0: resolution: {integrity: sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==} @@ -1435,9 +1447,8 @@ packages: resolution: {integrity: sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==} engines: {node: '>=8'} - jackspeak@2.3.6: - resolution: {integrity: sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==} - engines: {node: '>=14'} + jackspeak@3.4.3: + resolution: {integrity: sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==} javascript-time-ago@2.5.9: resolution: {integrity: sha512-pQ8mNco/9g9TqWXWWjP0EWl6i/lAQScOyEeXy5AB+f7MfLSdgyV9BJhiOD1zrIac/lrxPYOWNbyl/IW8CW5n0A==} @@ -1594,8 +1605,12 @@ packages: resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} engines: {node: '>=16 || 14 >=14.17'} - minipass@7.0.4: - resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==} + minimatch@9.0.5: + resolution: {integrity: sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==} + engines: {node: '>=16 || 14 >=14.17'} + + minipass@7.1.2: + resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==} engines: {node: '>=16 || 14 >=14.17'} mocha@10.7.0: @@ -1698,6 +1713,9 @@ packages: resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==} engines: {node: '>=6'} + package-json-from-dist@1.0.0: + resolution: {integrity: sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==} + pako@1.0.11: resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==} @@ -1735,9 +1753,9 @@ packages: path-parse@1.0.7: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} - path-scurry@1.10.1: - resolution: {integrity: sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==} - engines: {node: '>=16 || 14 >=14.17'} + path-scurry@1.11.1: + resolution: {integrity: sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==} + engines: {node: '>=16 || 14 >=14.18'} path-type@3.0.0: resolution: {integrity: sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==} @@ -2628,6 +2646,11 @@ snapshots: '@total-typescript/ts-reset@0.5.1': {} + '@types/glob@7.2.0': + dependencies: + '@types/minimatch': 5.1.2 + '@types/node': 20.11.21 + '@types/istanbul-lib-coverage@2.0.6': {} '@types/javascript-time-ago@2.0.8': {} @@ -2640,6 +2663,8 @@ snapshots: dependencies: '@types/unist': 2.0.10 + '@types/minimatch@5.1.2': {} + '@types/mocha@10.0.7': {} '@types/node@20.11.21': @@ -2789,7 +2814,7 @@ snapshots: c8: 9.1.0 chokidar: 3.6.0 enhanced-resolve: 5.17.1 - glob: 10.3.10 + glob: 10.4.5 minimatch: 9.0.3 mocha: 10.7.0 supports-color: 9.4.0 @@ -3348,7 +3373,7 @@ snapshots: is-glob: 4.0.3 minimatch: 3.1.2 resolve: 1.22.8 - semver: 7.6.0 + semver: 7.6.3 transitivePeerDependencies: - '@typescript-eslint/parser' - eslint-import-resolver-typescript @@ -3662,13 +3687,14 @@ snapshots: dependencies: is-glob: 4.0.3 - glob@10.3.10: + glob@10.4.5: dependencies: foreground-child: 3.1.1 - jackspeak: 2.3.6 - minimatch: 9.0.3 - minipass: 7.0.4 - path-scurry: 1.10.1 + jackspeak: 3.4.3 + minimatch: 9.0.5 + minipass: 7.1.2 + package-json-from-dist: 1.0.0 + path-scurry: 1.11.1 glob@7.2.3: dependencies: @@ -3904,7 +3930,7 @@ snapshots: html-escaper: 2.0.2 istanbul-lib-report: 3.0.1 - jackspeak@2.3.6: + jackspeak@3.4.3: dependencies: '@isaacs/cliui': 8.0.2 optionalDependencies: @@ -4060,7 +4086,11 @@ snapshots: dependencies: brace-expansion: 2.0.1 - minipass@7.0.4: {} + minimatch@9.0.5: + dependencies: + brace-expansion: 2.0.1 + + minipass@7.1.2: {} mocha@10.7.0: dependencies: @@ -4196,6 +4226,8 @@ snapshots: p-try@2.2.0: {} + package-json-from-dist@1.0.0: {} + pako@1.0.11: {} parent-module@1.0.1: @@ -4233,10 +4265,10 @@ snapshots: path-parse@1.0.7: {} - path-scurry@1.10.1: + path-scurry@1.11.1: dependencies: lru-cache: 10.2.0 - minipass: 7.0.4 + minipass: 7.1.2 path-type@3.0.0: dependencies: @@ -4616,7 +4648,7 @@ snapshots: dependencies: '@jridgewell/gen-mapping': 0.3.4 commander: 4.1.1 - glob: 10.3.10 + glob: 10.4.5 lines-and-columns: 1.2.4 mz: 2.7.0 pirates: 4.0.6 diff --git a/src/test/runTest.ts b/src/test/runTest.ts new file mode 100644 index 00000000..f5477275 --- /dev/null +++ b/src/test/runTest.ts @@ -0,0 +1,38 @@ +import * as path from 'node:path' + +import { runTests } from '@vscode/test-electron' + +async function main() { + try { + // The folder containing the Extension Manifest package.json + // Passed to `--extensionDevelopmentPath` + const extensionDevelopmentPath = path.resolve(__dirname, '../../') + + // The path to the extension test script + // Passed to --extensionTestsPath + const extensionTestsPath = path.resolve(__dirname, './suite/index') + + // Prepare the options for runTests + const options: { + extensionDevelopmentPath: string + extensionTestsPath: string + launchArgs?: string[] // Make launchArgs optional + } = { + extensionDevelopmentPath, + extensionTestsPath, + } + + // If the REPO environment variable is set, add it to launchArgs + if (process.env['RADICLE_REPO']) { + options.launchArgs = [path.resolve(process.env['RADICLE_REPO'])] + } + + // Download VS Code, unzip it and run the integration test + await runTests(options) + } catch (err) { + console.error('Failed to run tests') + process.exit(1) + } +} + +main() diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts new file mode 100644 index 00000000..a9f1a69e --- /dev/null +++ b/src/test/suite/index.ts @@ -0,0 +1,39 @@ +import * as path from 'node:path' +import Mocha from 'mocha' +import glob from 'glob' + +export async function run(): Promise { + // Create the mocha test + const mocha = new Mocha({ + ui: 'tdd', + }) + + const testsRoot = path.resolve(__dirname, '..') + + return new Promise((resolve, reject) => { + glob('**/**.test.js', { cwd: testsRoot }, (err: Error | null, files: string[]) => { + if (err) { + reject(err) + + return + } + + // Add files to the test suite + files.forEach((file) => mocha.addFile(path.resolve(testsRoot, file))) + + try { + // Run the mocha test + mocha.run((failures) => { + if (failures > 0) { + reject(new Error(`${failures} tests failed.`)) + } else { + resolve() + } + }) + } catch (err) { + console.error(err) + reject(err) + } + }) + }) +}