From cf477847244cf291aa13fa447f1c9cf834f302c8 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 4 Mar 2019 14:15:54 +0100 Subject: [PATCH] add tests to webpack-sample --- webpack-sample/.vscode/launch.json | 14 ++++++++++++++ webpack-sample/package-lock.json | 22 ++++++++++++++-------- webpack-sample/package.json | 4 +++- webpack-sample/src/test/extension.test.ts | 22 ++++++++++++++++++++++ webpack-sample/src/test/index.ts | 23 +++++++++++++++++++++++ webpack-sample/tsconfig.json | 14 ++++++++++---- webpack-sample/webpack.config.js | 5 +++++ 7 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 webpack-sample/src/test/extension.test.ts create mode 100644 webpack-sample/src/test/index.ts diff --git a/webpack-sample/.vscode/launch.json b/webpack-sample/.vscode/launch.json index 58147dcd..f3f93a4a 100644 --- a/webpack-sample/.vscode/launch.json +++ b/webpack-sample/.vscode/launch.json @@ -14,6 +14,20 @@ "${workspaceFolder}/dist/**/*.js" ], "preLaunchTask": "npm: webpack" + }, + { + "name": "Extension Tests", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}", + "--extensionTestsPath=${workspaceFolder}/out/test" + ], + "outFiles": [ + "${workspaceFolder}/out/test/**/*.js" + ], + "preLaunchTask": "npm: test-compile" } ] } diff --git a/webpack-sample/package-lock.json b/webpack-sample/package-lock.json index 93503d1f..b2875edc 100644 --- a/webpack-sample/package-lock.json +++ b/webpack-sample/package-lock.json @@ -4,6 +4,12 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/mocha": { + "version": "2.2.48", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.48.tgz", + "integrity": "sha512-nlK/iyETgafGli8Zh9zJVCTicvU3iajSkRwOh3Hhiva598CMqNJ4NcVCGMTGKpGpTYj/9R8RLzS9NAykSSCqGw==", + "dev": true + }, "@types/node": { "version": "7.0.70", "resolved": "https://registry.npmjs.org/@types/node/-/node-7.0.70.tgz", @@ -1642,7 +1648,7 @@ }, "deep-assign": { "version": "1.0.0", - "resolved": "http://registry.npmjs.org/deep-assign/-/deep-assign-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/deep-assign/-/deep-assign-1.0.0.tgz", "integrity": "sha1-sJJ0O+hCfcYh6gBnzex+cN0Z83s=", "dev": true, "requires": { @@ -1928,7 +1934,7 @@ }, "expand-range": { "version": "1.8.2", - "resolved": "http://registry.npmjs.org/expand-range/-/expand-range-1.8.2.tgz", + "resolved": "https://registry.npmjs.org/expand-range/-/expand-range-1.8.2.tgz", "integrity": "sha1-opnv/TNf4nIeuujiV+x5ZE/IUzc=", "dev": true, "requires": { @@ -2837,13 +2843,13 @@ }, "string_decoder": { "version": "0.10.31", - "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", "dev": true }, "through2": { "version": "0.6.5", - "resolved": "http://registry.npmjs.org/through2/-/through2-0.6.5.tgz", + "resolved": "https://registry.npmjs.org/through2/-/through2-0.6.5.tgz", "integrity": "sha1-QaucZ7KdVyCQcUEOHXp6lozTrUg=", "dev": true, "requires": { @@ -2923,13 +2929,13 @@ }, "string_decoder": { "version": "0.10.31", - "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", "dev": true }, "through2": { "version": "0.6.5", - "resolved": "http://registry.npmjs.org/through2/-/through2-0.6.5.tgz", + "resolved": "https://registry.npmjs.org/through2/-/through2-0.6.5.tgz", "integrity": "sha1-QaucZ7KdVyCQcUEOHXp6lozTrUg=", "dev": true, "requires": { @@ -3803,7 +3809,7 @@ }, "kind-of": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", "integrity": "sha1-FAo9LUGjbS78+pN3tiwk+ElaXEQ=", "dev": true }, @@ -6005,7 +6011,7 @@ }, "tar": { "version": "2.2.1", - "resolved": "http://registry.npmjs.org/tar/-/tar-2.2.1.tgz", + "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz", "integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=", "dev": true, "requires": { diff --git a/webpack-sample/package.json b/webpack-sample/package.json index f2014c1c..7640febc 100644 --- a/webpack-sample/package.json +++ b/webpack-sample/package.json @@ -26,6 +26,7 @@ "vscode:prepublish": "webpack --mode production", "webpack": "webpack --mode development", "webpack-dev": "webpack --mode development --watch", + "test-compile": "tsc -p ./", "postinstall": "node ./node_modules/vscode/bin/install" }, "devDependencies": { @@ -35,6 +36,7 @@ "typescript": "3.0.3", "vscode": "^1.1.22", "webpack": "^4.19.1", - "webpack-cli": "^3.1.0" + "webpack-cli": "^3.1.0", + "@types/mocha": "^2.2.42" } } diff --git a/webpack-sample/src/test/extension.test.ts b/webpack-sample/src/test/extension.test.ts new file mode 100644 index 00000000..a7a297f7 --- /dev/null +++ b/webpack-sample/src/test/extension.test.ts @@ -0,0 +1,22 @@ +// +// 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/webpack-sample/src/test/index.ts b/webpack-sample/src/test/index.ts new file mode 100644 index 00000000..fb0bc96b --- /dev/null +++ b/webpack-sample/src/test/index.ts @@ -0,0 +1,23 @@ +// +// 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(testRoot: string, clb: (error:Error) => 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/webpack-sample/tsconfig.json b/webpack-sample/tsconfig.json index c0f1d59b..1ea19d39 100644 --- a/webpack-sample/tsconfig.json +++ b/webpack-sample/tsconfig.json @@ -1,11 +1,17 @@ { "compilerOptions": { - "module": "es6", + "module": "commonjs", "target": "es6", "outDir": "out", - "lib": ["es6"], + "lib": [ + "es6" + ], "sourceMap": true, - "rootDir": "." + "rootDir": "src" }, - "include": ["src/**/*.ts", "./node_modules/vscode/vscode.d.ts"] + "include": [ + "src/**/*.ts", + "./node_modules/vscode/vscode.d.ts", + "./node_modules/vscode/lib/*", + ] } diff --git a/webpack-sample/webpack.config.js b/webpack-sample/webpack.config.js index 56eb17df..423b7818 100644 --- a/webpack-sample/webpack.config.js +++ b/webpack-sample/webpack.config.js @@ -33,6 +33,11 @@ const config = { exclude: /node_modules/, use: [{ loader: 'ts-loader', + options: { + compilerOptions: { + "module": "es6" // override `tsconfig.json` so that TypeScript emits native JavaScript modules. + } + } }] }] },