From b4f7e6c830b360e9d93b1ea6a13df9dbf973de15 Mon Sep 17 00:00:00 2001 From: Dag Date: Thu, 19 Jan 2023 23:43:26 +0100 Subject: [PATCH] Added empty test suite --- .eslintrc.json | 21 ++++++++++++++++++ package-lock.json | 4 ++-- package.json | 10 ++++----- src/test/runTest.ts | 23 +++++++++++++++++++ src/test/suite/extension.test.ts | 15 +++++++++++++ src/test/suite/index.ts | 38 ++++++++++++++++++++++++++++++++ 6 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 .eslintrc.json create mode 100644 src/test/runTest.ts create mode 100644 src/test/suite/extension.test.ts create mode 100644 src/test/suite/index.ts diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..0c53077 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,21 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "overrides": [ + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + } +} diff --git a/package-lock.json b/package-lock.json index 0872e28..a3e1629 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,8 +13,8 @@ "@types/mocha": "^10.0.1", "@types/node": "16.x", "@types/vscode": "^1.74.0", - "@typescript-eslint/eslint-plugin": "^5.45.0", - "@typescript-eslint/parser": "^5.45.0", + "@typescript-eslint/eslint-plugin": "^5.48.2", + "@typescript-eslint/parser": "^5.48.2", "@vscode/test-electron": "^2.2.0", "eslint": "^8.28.0", "glob": "^8.0.3", diff --git a/package.json b/package.json index ef689ae..b970fd5 100644 --- a/package.json +++ b/package.json @@ -53,17 +53,17 @@ "test": "node ./out/test/runTest.js" }, "devDependencies": { - "@types/vscode": "^1.74.0", "@types/glob": "^8.0.0", "@types/mocha": "^10.0.1", "@types/node": "16.x", - "@typescript-eslint/eslint-plugin": "^5.45.0", - "@typescript-eslint/parser": "^5.45.0", + "@types/vscode": "^1.74.0", + "@typescript-eslint/eslint-plugin": "^5.48.2", + "@typescript-eslint/parser": "^5.48.2", + "@vscode/test-electron": "^2.2.0", "eslint": "^8.28.0", "glob": "^8.0.3", "mocha": "^10.1.0", - "typescript": "^4.9.3", - "@vscode/test-electron": "^2.2.0" + "typescript": "^4.9.3" }, "bugs": { "url": "https://github.com/svaberg/SWMF-grammar/issues" diff --git a/src/test/runTest.ts b/src/test/runTest.ts new file mode 100644 index 0000000..27b3ceb --- /dev/null +++ b/src/test/runTest.ts @@ -0,0 +1,23 @@ +import * as path from '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 test runner + // Passed to --extensionTestsPath + const extensionTestsPath = path.resolve(__dirname, './suite/index'); + + // Download VS Code, unzip it and run the integration test + await runTests({ extensionDevelopmentPath, extensionTestsPath }); + } catch (err) { + console.error('Failed to run tests'); + process.exit(1); + } +} + +main(); diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts new file mode 100644 index 0000000..4ca0ab4 --- /dev/null +++ b/src/test/suite/extension.test.ts @@ -0,0 +1,15 @@ +import * as assert from 'assert'; + +// You can import and use all API from the 'vscode' module +// as well as import your extension to test it +import * as vscode from 'vscode'; +// import * as myExtension from '../../extension'; + +suite('Extension Test Suite', () => { + vscode.window.showInformationMessage('Start all tests.'); + + test('Sample test', () => { + assert.strictEqual(-1, [1, 2, 3].indexOf(5)); + assert.strictEqual(-1, [1, 2, 3].indexOf(0)); + }); +}); diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts new file mode 100644 index 0000000..7029e38 --- /dev/null +++ b/src/test/suite/index.ts @@ -0,0 +1,38 @@ +import * as path from 'path'; +import * as Mocha from 'mocha'; +import * as glob from 'glob'; + +export function run(): Promise { + // Create the mocha test + const mocha = new Mocha({ + ui: 'tdd', + color: true + }); + + const testsRoot = path.resolve(__dirname, '..'); + + return new Promise((c, e) => { + glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { + if (err) { + return e(err); + } + + // 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); + } + }); + }); +}