Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: enable test suites #436

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ package-lock.json
/out/
/dist/

# Tests
.vscode-test/

# generated by js-yaml
syntaxes/*.json
!syntaxes/tmLanguage.schema.json
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"format": "prettier --write .",
"clean": "gulp clean",
"toc": "md-magic --path \"*.md\"",
"pretest": "yarn run build && yarn run lint",
"tsc": "tsc --noEmit",
"pretest": "yarn run build && yarn run tsc -p tsconfig.test.json",
"tsc:noEmit": "tsc --noEmit",
"test": "node ./out/test/runTest.js",
"package": "gulp package",
"prepack": "yarn port-i18n && yarn crowdin:pull && yarn import-i18n",
Expand Down Expand Up @@ -165,6 +165,7 @@
"@types/vscode": "^1.60.0",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.52.0",
"@vscode/test-electron": "^2.3.10",
"del": "^7.0.0",
"eslint": "^8.55.0",
"eslint-import-resolver-typescript": "^3.6.1",
Expand All @@ -184,8 +185,7 @@
"ts-node": "^10.9.1",
"tsimportlib": "^0.0.5",
"vsce": "^2.15.0",
"vscode-nls-dev": "^4.0.3",
"vscode-test": "^1.6.1"
"vscode-nls-dev": "^4.0.3"
},
"dependencies": {
"typescript": "^5.4.2",
Expand Down
4 changes: 2 additions & 2 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path'

import { runTests } from 'vscode-test'
import { runTests } from '@vscode/test-electron'

async function main() {
try {
Expand All @@ -15,7 +15,7 @@ async function main() {
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath })
} catch (err) {
console.error('Failed to run tests')
console.error('Failed to run tests', err)
process.exit(1)
}
}
Expand Down
36 changes: 14 additions & 22 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable */
import * as path from 'path'
import Mocha from 'mocha'
import glob from 'glob'
import { glob } from 'glob'

export function run(): Promise<void> {
export async function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
Expand All @@ -12,28 +12,20 @@ export function run(): Promise<void> {

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

return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err)
}
const files = await glob('**/**.test.js', { cwd: testsRoot })

// Add files to the test suite
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)))
// Add files to the test suite
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)))

try {
// Run the mocha test
mocha.run((failures) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`))
} else {
c()
}
})
} catch (err) {
console.error(err)
e(err)
try {
// Run the mocha test
mocha.run((failures) => {
if (failures > 0) {
throw new Error(`${failures} tests failed.`)
}
})
})
} catch (err) {
console.error(err)
throw err
}
}
10 changes: 10 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES2021",
"outDir": "out/test",
"rootDir": "src/test",
"esModuleInterop": true,
},
"include": ["src/test/**/*"]
}
Loading
Loading