diff --git a/generators/app/templates/ext-command-js/package.json b/generators/app/templates/ext-command-js/package.json index da02b2e7..d8dfacbd 100644 --- a/generators/app/templates/ext-command-js/package.json +++ b/generators/app/templates/ext-command-js/package.json @@ -20,14 +20,17 @@ }] }, "scripts": { - "postinstall": "node ./node_modules/vscode/bin/install", - "test": "node ./node_modules/vscode/bin/test" + "test": "node ./test/runTest.js" }, "devDependencies": { - "typescript": "^3.3.1", - "vscode": "^1.1.28", - "eslint": "^5.13.0", + "@types/glob": "^7.1.1", + "@types/mocha": "^5.2.6", "@types/node": "^10.12.21", - "@types/mocha": "^2.2.42" + "@types/vscode": "^1.32.0", + "eslint": "^5.13.0", + "glob": "^7.1.4", + "mocha": "^6.1.4", + "typescript": "^3.3.1", + "vscode-test": "^0.4.2" } } diff --git a/generators/app/templates/ext-command-js/test/extension.test.js b/generators/app/templates/ext-command-js/test/extension.test.js deleted file mode 100644 index 22782f81..00000000 --- a/generators/app/templates/ext-command-js/test/extension.test.js +++ /dev/null @@ -1,24 +0,0 @@ -/* global suite, test */ - -// -// Note: This example test is leveraging the Mocha test framework. -// Please refer to their documentation on https://mochajs.org/ for help. -// - -// The module 'assert' provides assertion methods from node -const assert = require('assert'); - -// You can import and use all API from the 'vscode' module -// as well as import your extension to test it -// const vscode = require('vscode'); -// const myExtension = require('../extension'); - -// Defines a Mocha test suite to group tests of similar kind together -suite("Extension Tests", function() { - - // Defines a Mocha unit test - test("Something 1", function() { - assert.equal(-1, [1, 2, 3].indexOf(5)); - assert.equal(-1, [1, 2, 3].indexOf(0)); - }); -}); diff --git a/generators/app/templates/ext-command-js/test/index.js b/generators/app/templates/ext-command-js/test/index.js deleted file mode 100644 index 774069fd..00000000 --- a/generators/app/templates/ext-command-js/test/index.js +++ /dev/null @@ -1,23 +0,0 @@ -// -// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING -// -// This file is providing the test runner to use when running extension tests. -// By default the test runner in use is Mocha based. -// -// You can provide your own test runner if you want to override it by exporting -// a function run(testsRoot: string, clb: (error: Error, failures?: number) => void): void -// that the extension host can call to run the tests. The test runner is expected to use console.log -// to report the results back to the caller. When the tests are finished, return -// a possible error to the callback or null if none. - -const testRunner = require('vscode/lib/testrunner'); - -// You can directly control Mocha options by configuring the test runner below -// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options -// for more info -testRunner.configure({ - ui: 'tdd', // the TDD UI is being used in extension.test.js (suite, test, etc.) - useColors: true // colored output from test results -}); - -module.exports = testRunner; diff --git a/generators/app/templates/ext-command-js/test/runTest.js b/generators/app/templates/ext-command-js/test/runTest.js new file mode 100644 index 00000000..e9cebe76 --- /dev/null +++ b/generators/app/templates/ext-command-js/test/runTest.js @@ -0,0 +1,23 @@ +const path = require('path'); + +const { runTests } = require('vscode-test'); + +async function main() { + try { + // The folder containing the Extension Manifest package.json + // Passed to `--extensionDevelopmentPath` + const extensionPath = path.resolve(__dirname, '../../'); + + // The path to test runner + // Passed to --extensionTestsPath + const testRunnerPath = path.resolve(__dirname, './suite'); + + // Download VS Code, unzip it and run the integration test + await runTests({ extensionPath, testRunnerPath }); + } catch (err) { + console.error('Failed to run tests'); + process.exit(1); + } +} + +main(); diff --git a/generators/app/templates/ext-command-js/test/suite/extension.test.js b/generators/app/templates/ext-command-js/test/suite/extension.test.js new file mode 100644 index 00000000..34249bb9 --- /dev/null +++ b/generators/app/templates/ext-command-js/test/suite/extension.test.js @@ -0,0 +1,18 @@ +const assert = require('assert'); +const { before } = require('mocha'); + +// You can import and use all API from the 'vscode' module +// as well as import your extension to test it +const vscode = require('vscode'); +// const myExtension = require('../extension'); + +suite('Extension Test Suite', () => { + before(() => { + vscode.window.showInformationMessage('Start all tests.'); + }); + + test('Sample test', () => { + assert.equal(-1, [1, 2, 3].indexOf(5)); + assert.equal(-1, [1, 2, 3].indexOf(0)); + }); +}); diff --git a/generators/app/templates/ext-command-js/test/suite/index.js b/generators/app/templates/ext-command-js/test/suite/index.js new file mode 100644 index 00000000..33271c75 --- /dev/null +++ b/generators/app/templates/ext-command-js/test/suite/index.js @@ -0,0 +1,32 @@ +const path = require('path'); +const Mocha = require('mocha'); +const glob = require('glob'); + +function run(testsRoot, cb) { + // Create the mocha test + const mocha = new Mocha({ + ui: 'tdd' + }); + // Use any mocha API + mocha.useColors(true); + + glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { + if (err) { + return cb(err); + } + + // Add files to the test suite + files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); + + try { + // Run the mocha test + mocha.run(failures => cb(null, failures)); + } catch (err) { + cb(err); + } + }); +} + +module.exports = { + run +}; diff --git a/generators/app/templates/ext-command-ts/package.json b/generators/app/templates/ext-command-ts/package.json index 5bc58e9e..e51e486e 100644 --- a/generators/app/templates/ext-command-ts/package.json +++ b/generators/app/templates/ext-command-ts/package.json @@ -23,14 +23,17 @@ "vscode:prepublish": "<%= pkgManager %> run compile", "compile": "tsc -p ./", "watch": "tsc -watch -p ./", - "postinstall": "node ./node_modules/vscode/bin/install", - "test": "<%= pkgManager %> run compile && node ./node_modules/vscode/bin/test" + "test": "<%= pkgManager %> run compile && node ./out/test/runTest.js" }, "devDependencies": { + "@types/glob": "^7.1.1", + "@types/mocha": "^5.2.6", + "@types/node": "^10.12.21", + "@types/vscode": "^1.32.0", + "glob": "^7.1.4", + "mocha": "^6.1.4", "typescript": "^3.3.1", - "vscode": "^1.1.28", "tslint": "^5.12.1", - "@types/node": "^10.12.21", - "@types/mocha": "^2.2.42" + "vscode-test": "^0.4.2" } } diff --git a/generators/app/templates/ext-command-ts/src/test/extension.test.ts b/generators/app/templates/ext-command-ts/src/test/extension.test.ts deleted file mode 100644 index a7a297f7..00000000 --- a/generators/app/templates/ext-command-ts/src/test/extension.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -// -// Note: This example test is leveraging the Mocha test framework. -// Please refer to their documentation on https://mochajs.org/ for help. -// - -// The module 'assert' provides assertion methods from node -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'; - -// Defines a Mocha test suite to group tests of similar kind together -suite("Extension Tests", function () { - - // Defines a Mocha unit test - test("Something 1", function() { - assert.equal(-1, [1, 2, 3].indexOf(5)); - assert.equal(-1, [1, 2, 3].indexOf(0)); - }); -}); \ No newline at end of file diff --git a/generators/app/templates/ext-command-ts/src/test/index.ts b/generators/app/templates/ext-command-ts/src/test/index.ts deleted file mode 100644 index 4cda15ce..00000000 --- a/generators/app/templates/ext-command-ts/src/test/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -// -// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING -// -// This file is providing the test runner to use when running extension tests. -// By default the test runner in use is Mocha based. -// -// You can provide your own test runner if you want to override it by exporting -// a function run(testsRoot: string, clb: (error: Error, failures?: number) => void): void -// that the extension host can call to run the tests. The test runner is expected to use console.log -// to report the results back to the caller. When the tests are finished, return -// a possible error to the callback or null if none. - -import * as testRunner from 'vscode/lib/testrunner'; - -// You can directly control Mocha options by configuring the test runner below -// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options -// for more info -testRunner.configure({ - ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.) - useColors: true // colored output from test results -}); - -module.exports = testRunner; \ No newline at end of file diff --git a/generators/app/templates/ext-command-ts/src/test/runTest.ts b/generators/app/templates/ext-command-ts/src/test/runTest.ts new file mode 100644 index 00000000..475b0d36 --- /dev/null +++ b/generators/app/templates/ext-command-ts/src/test/runTest.ts @@ -0,0 +1,23 @@ +import * as path from 'path'; + +import { runTests } from 'vscode-test'; + +async function main() { + try { + // The folder containing the Extension Manifest package.json + // Passed to `--extensionDevelopmentPath` + const extensionPath = path.resolve(__dirname, '../../'); + + // The path to test runner + // Passed to --extensionTestsPath + const testRunnerPath = path.resolve(__dirname, './suite'); + + // Download VS Code, unzip it and run the integration test + await runTests({ extensionPath, testRunnerPath }); + } catch (err) { + console.error('Failed to run tests'); + process.exit(1); + } +} + +main(); diff --git a/generators/app/templates/ext-command-ts/src/test/suite/extension.test.ts b/generators/app/templates/ext-command-ts/src/test/suite/extension.test.ts new file mode 100644 index 00000000..820cf906 --- /dev/null +++ b/generators/app/templates/ext-command-ts/src/test/suite/extension.test.ts @@ -0,0 +1,18 @@ +import * as assert from 'assert'; +import { before } from 'mocha'; + +// 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', () => { + before(() => { + vscode.window.showInformationMessage('Start all tests.'); + }); + + test('Sample test', () => { + assert.equal(-1, [1, 2, 3].indexOf(5)); + assert.equal(-1, [1, 2, 3].indexOf(0)); + }); +}); diff --git a/generators/app/templates/ext-command-ts/src/test/suite/index.ts b/generators/app/templates/ext-command-ts/src/test/suite/index.ts new file mode 100644 index 00000000..236a4e7f --- /dev/null +++ b/generators/app/templates/ext-command-ts/src/test/suite/index.ts @@ -0,0 +1,28 @@ +import * as path from 'path'; +import * as Mocha from 'mocha'; +import * as glob from 'glob'; + +export function run(testsRoot: string, cb: (error: any, failures?: number) => void): void { + // Create the mocha test + const mocha = new Mocha({ + ui: 'tdd' + }); + // Use any mocha API + mocha.useColors(true); + + glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { + if (err) { + return cb(err); + } + + // Add files to the test suite + files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); + + try { + // Run the mocha test + mocha.run(failures => cb(null, failures)); + } catch (err) { + cb(err); + } + }); +} diff --git a/package-lock.json b/package-lock.json index b5b857ce..987c1c3f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1554,6 +1554,11 @@ "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" }, + "fast-plist": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/fast-plist/-/fast-plist-0.1.2.tgz", + "integrity": "sha1-pFr/NFGWAG1AbKbNzQX2kFHvNbg=" + }, "figures": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", diff --git a/test/test.js b/test/test.js index 1836b99d..627bef41 100644 --- a/test/test.js +++ b/test/test.js @@ -626,19 +626,22 @@ describe('test code generator', function () { "onCommand:extension.helloWorld" ], "devDependencies": { + "@types/glob": "^7.1.1", + "@types/mocha": "^5.2.6", + "@types/node": "^10.12.21", + "@types/vscode": "^1.32.0", + "glob": "^7.1.4", + "mocha": "^6.1.4", "typescript": "^3.3.1", - "vscode": "^1.1.28", "tslint": "^5.12.1", - "@types/node": "^10.12.21", - "@types/mocha": "^2.2.42" + "vscode-test": "^0.4.2" }, "main": "./out/extension.js", "scripts": { "vscode:prepublish": "npm run compile", "compile": "tsc -p ./", "watch": "tsc -watch -p ./", - "postinstall": "node ./node_modules/vscode/bin/install", - "test": "npm run compile && node ./node_modules/vscode/bin/test" + "test": "npm run compile && node ./out/test/runTest.js" }, "categories": [ "Other" @@ -653,7 +656,7 @@ describe('test code generator', function () { try { - assert.file(['package.json', 'README.md', 'CHANGELOG.md', '.vscodeignore', 'src/extension.ts', 'src/test/extension.test.ts', 'src/test/index.ts', 'tsconfig.json']); + assert.file(['package.json', 'README.md', 'CHANGELOG.md', '.vscodeignore', 'src/extension.ts', 'src/test/suite/extension.test.ts', 'src/test/suite/index.ts', 'tsconfig.json']); var packageJSONBody = fs.readFileSync('package.json', 'utf8') var actualPackageJSON = JSON.parse(packageJSONBody); @@ -692,19 +695,22 @@ describe('test code generator', function () { "onCommand:extension.helloWorld" ], "devDependencies": { + "@types/glob": "^7.1.1", + "@types/mocha": "^5.2.6", + "@types/node": "^10.12.21", + "@types/vscode": "^1.32.0", + "glob": "^7.1.4", + "mocha": "^6.1.4", "typescript": "^3.3.1", - "vscode": "^1.1.28", "tslint": "^5.12.1", - "@types/node": "^10.12.21", - "@types/mocha": "^2.2.42" + "vscode-test": "^0.4.2" }, "main": "./out/extension.js", "scripts": { "vscode:prepublish": "yarn run compile", "compile": "tsc -p ./", "watch": "tsc -watch -p ./", - "postinstall": "node ./node_modules/vscode/bin/install", - "test": "yarn run compile && node ./node_modules/vscode/bin/test" + "test": "yarn run compile && node ./out/test/runTest.js" }, "categories": [ "Other" @@ -734,7 +740,7 @@ describe('test code generator', function () { ] }; try { - assert.file(['package.json', 'README.md', 'CHANGELOG.md', '.vscodeignore', 'src/extension.ts', 'src/test/extension.test.ts', 'src/test/index.ts', 'tsconfig.json', 'tslint.json', '.vscode/extensions.json']); + assert.file(['package.json', 'README.md', 'CHANGELOG.md', '.vscodeignore', 'src/extension.ts', 'src/test/suite/extension.test.ts', 'src/test/suite/index.ts', 'tsconfig.json', 'tslint.json', '.vscode/extensions.json']); var packageJSONBody = fs.readFileSync('package.json', 'utf8') var actualPackageJSON = JSON.parse(packageJSONBody); @@ -778,16 +784,19 @@ describe('test code generator', function () { "onCommand:extension.helloWorld" ], "devDependencies": { - "typescript": "^3.3.1", - "vscode": "^1.1.28", - "eslint": "^5.13.0", + "@types/glob": "^7.1.1", + "@types/mocha": "^5.2.6", "@types/node": "^10.12.21", - "@types/mocha": "^2.2.42" + "@types/vscode": "^1.32.0", + "eslint": "^5.13.0", + "glob": "^7.1.4", + "mocha": "^6.1.4", + "typescript": "^3.3.1", + "vscode-test": "^0.4.2" }, "main": "./extension.js", "scripts": { - "postinstall": "node ./node_modules/vscode/bin/install", - "test": "node ./node_modules/vscode/bin/test" + "test": "node ./test/runTest.js" }, "categories": [ "Other" @@ -802,7 +811,7 @@ describe('test code generator', function () { try { - assert.file(['package.json', 'README.md', 'CHANGELOG.md', '.vscodeignore', 'extension.js', 'test/extension.test.js', 'test/index.js', 'jsconfig.json']); + assert.file(['package.json', 'README.md', 'CHANGELOG.md', '.vscodeignore', 'extension.js', 'test/suite/extension.test.js', 'test/suite/index.js', 'jsconfig.json']); var body = fs.readFileSync('package.json', 'utf8'); @@ -988,4 +997,4 @@ describe('test code generator', function () { } }, done); }); -}); \ No newline at end of file +});