Skip to content

Commit 94ca7e7

Browse files
Clean up npm scripts and start running tests
Since the repo started, we've had a single NPM script that ran on postinstall. All this did was run the VS Code install script and then launch tsc. Now, postinstall just runs the VS Code install script. The idea here is that install should really just lay down dependencies, not compile code. Compilation is split off into a separate script. Here are the new npm scripts: * `postinstall`: As described above, this now just runs the VS Code install script after `npm install`. * `compile`: Runs the VS Code compile script to transpile TypeScript to JavaScript. Run this with `npm run compile`. * `watch`: Runs the VS Code compile script with the '-watch' flag to transpile TypeScript to JavaScript, and then watch for file changes and incrementally compile. Run this with `npm run watch`. * `test`: Runs the tests with Mocha. Note: This will only run tests that are already transpiled to JavaScript. Run with `npm test`. * Unit tests can be written in the 'test' folder. See 'test/sanity.tests.ts' for an example. * The launch.json has been updated to allow debugging of unit tests with the "Launch Tests" configuration. * The "test" task is now configured so that you can use the "Tasks: Run Test Task" command in VS Code. * Whitespace is a bit out of control. I've made an executable decision that the repo should have spaces with an indent size of 4. This is now added to the settings.json. * The 'out' folder is now excluded in settings.json so you won't see it show up in your directory tree. * The 'node_modules' folder is now excluded from search. This has been bothering me for awhile.
1 parent c980f13 commit 94ca7e7

File tree

11 files changed

+95
-36
lines changed

11 files changed

+95
-36
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ os:
1010

1111
install:
1212
- npm install
13+
- npm run compile
1314
- npm install -g vsce
1415
- vsce package
1516

.vscode/launch.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@
1111
],
1212
"stopOnEntry": false,
1313
"sourceMaps": true,
14-
"outDir": "${workspaceRoot}/out"
14+
"outDir": "${workspaceRoot}/out/src"
15+
},
16+
{
17+
"name": "Launch Tests",
18+
"type": "extensionHost",
19+
"request": "launch",
20+
"runtimeExecutable": "${execPath}",
21+
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
22+
"stopOnEntry": false,
23+
"sourceMaps": true,
24+
"outDir": "${workspaceRoot}/out/test"
1525
}
1626
]
1727
}

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
{
2+
"editor.tabSize": 4,
3+
"editor.insertSpaces": true,
4+
5+
"files.exclude": {
6+
"out": true,
7+
"typings": false
8+
},
9+
10+
"search.exclude": {
11+
"**/node_modules": true,
12+
"out/": true
13+
},
14+
215
"tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib"
316
}

.vscode/tasks.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"command": "gulp",
44
"isShellCommand": true,
55
"tasks": [
6+
{
7+
"taskName": "test",
8+
"showOutput": "always",
9+
"isTestCommand": true
10+
},
611
{
712
"taskName": "tslint",
813
"args": [],

.vscodeignore

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
**/*.gitignore
2-
tsconfig.json
3-
1+
.vscode/**
2+
typings/**
3+
out/test/**
4+
test/**
45
src/**
56
**/*.map
67

7-
.vscode/**
8+
.gitignore
9+
.travis.yml
10+
tsconfig.json
811

912
**/.nyc_output/**
1013
**/coverage/**

gulpfile.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ const path = require('path');
1010
const del = require('del');
1111
const gulp = require('gulp');
1212
const gulpUtil = require('gulp-util');
13+
const mocha = require('gulp-mocha');
1314
const tslint = require('gulp-tslint');
1415
const vsce = require('vsce');
15-
const debugUtil = require('./out/coreclr-debug/util.js');
16-
const debugInstall = require('./out/coreclr-debug/install.js');
16+
const debugUtil = require('./out/src/coreclr-debug/util');
17+
const debugInstall = require('./out/src/coreclr-debug/install');
1718
const fs_extra = require('fs-extra-promise');
18-
const omnisharp = require('./out/omnisharp/omnisharp');
19-
const download = require('./out/omnisharp/download');
20-
const logger = require('./out/omnisharp/logger');
21-
const platform = require('./out/platform');
19+
const omnisharp = require('./out/src/omnisharp/omnisharp');
20+
const download = require('./out/src/omnisharp/download');
21+
const logger = require('./out/src/omnisharp/logger');
22+
const platform = require('./out/src/platform');
2223
const child_process = require('child_process');
2324

2425
const Flavor = omnisharp.Flavor;
@@ -154,6 +155,18 @@ gulp.task('package:offline', ['clean'], () => {
154155
return promise;
155156
});
156157

158+
/// Test Task
159+
gulp.task('test', () => {
160+
gulp.src('out/test/*.tests.js')
161+
.pipe(mocha({ui: "tdd"}))
162+
.once('error', () => {
163+
process.exit(1);
164+
})
165+
.once('end', () => {
166+
process.exit();
167+
});
168+
});
169+
157170
/// Misc Tasks
158171
const allTypeScript = [
159172
'src/**/*.ts',

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
],
2020
"main": "./out/main",
2121
"scripts": {
22-
"postinstall": "node ./node_modules/vscode/bin/install && tsc"
22+
"compile": "node ./node_modules/vscode/bin/compile -p ./",
23+
"watch": "node ./node_modules/vscode/bin/compile -watch -p ./",
24+
"test": "mocha --timeout 15000 -u tdd ./out/test/*.tests.js",
25+
"postinstall": "node ./node_modules/vscode/bin/install"
2326
},
2427
"dependencies": {
2528
"decompress": "^4.0.0",
@@ -35,6 +38,7 @@
3538
},
3639
"devDependencies": {
3740
"gulp": "^3.9.1",
41+
"gulp-mocha": "^2.1.3",
3842
"gulp-tslint": "^4.3.0",
3943
"mocha": "^2.2.5",
4044
"tslint": "^3.3.0",

test/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
16
//
27
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
38
//

test/sanity.test.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/sanity.tests.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
//
7+
// Note: This example test is leveraging the Mocha test framework.
8+
// Please refer to their documentation on https://mochajs.org/ for help.
9+
//
10+
11+
// The module 'assert' provides assertion methods from node
12+
import * as assert from 'assert';
13+
14+
// You can import and use all API from the 'vscode' module
15+
// as well as import your extension to test it
16+
import * as vscode from 'vscode';
17+
import * as myExtension from '../src/main';
18+
19+
suite("Sanity Tests", () => {
20+
test("Boolean checks", () => {
21+
assert.equal(true, true, "true is not true");
22+
assert.notEqual(true, false, "true is false");
23+
assert.equal(false, false, "false is not false");
24+
assert.notEqual(false, true, "false is true");
25+
});
26+
});

0 commit comments

Comments
 (0)