Skip to content

Commit

Permalink
[wip] adds custom test runner
Browse files Browse the repository at this point in the history
this allows us to open VS Code with the radicle repo we have previously created in the e2e tests

Signed-off-by: Yorgos Saslis <yorgo@protonmail.com>
  • Loading branch information
gsaslis committed Aug 8, 2024
1 parent bd263f5 commit 8c7d9c2
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/end-to-end-tests.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 }}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
78 changes: 55 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -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()
39 changes: 39 additions & 0 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as path from 'node:path'
import Mocha from 'mocha'
import glob from 'glob'

export async function run(): Promise<unknown> {

Check warning on line 5 in src/test/suite/index.ts

View workflow job for this annotation

GitHub Actions / audit (macos-latest)

Async function 'run' has no 'await' expression

Check warning on line 5 in src/test/suite/index.ts

View workflow job for this annotation

GitHub Actions / audit (ubuntu-latest)

Async function 'run' has no 'await' expression
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
})

const testsRoot = path.resolve(__dirname, '..')

return new Promise<void>((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)
}
})
})
}

0 comments on commit 8c7d9c2

Please sign in to comment.