Skip to content

Commit 60bc966

Browse files
author
Arnold Trakhtenberg
authored
Upgrade to newest vscode testing framework, enable unit tests on CI (#25)
* testing ci * set display * migrate to vscode-test * testing * ok, we need the deps * set display in same command * continue testing * use default xvfb * create xvfb.init * libnss3 * more libs * fix
1 parent 1738d15 commit 60bc966

File tree

6 files changed

+126
-185
lines changed

6 files changed

+126
-185
lines changed

.circleci/config.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ jobs:
1717
paths:
1818
- node_modules
1919
- run:
20-
name: Install vscode dependencies
21-
command: 'sudo apt install libgtk-3-0 libxss1 libgconf-2-4 libnss3 libasound2'
20+
name: Setup build environment
21+
command: |
22+
sudo apt-get update
23+
sudo apt-get install -y libxkbfile-dev pkg-config libsecret-1-dev libxss1 dbus xvfb libgtk-3-0 libnss3 libasound2
24+
sudo cp test/xvfb.init /etc/init.d/xvfb
25+
sudo chmod +x /etc/init.d/xvfb
26+
sudo update-rc.d xvfb defaults
27+
sudo service xvfb start
2228
- run:
2329
name: Build
2430
command: 'yarn run vscode:prepublish'
25-
# Temporarily disabled until we set vscode testing with circleci
26-
# - run:
27-
# name: Download vscode executable
28-
# command: 'mkdir -p .vscode-test/stable && wget -qO- https://vscode-update.azurewebsites.net/1.27.2/linux-x64/stable | tar zxv -C .vscode-test/stable/ && chmod 0755 .vscode-test/stable/VSCode-linux-x64/code && tail -c +4 .vscode-test/stable/VSCode-linux-x64/code > .vscode-test/stable/VSCode-linux-x64/code'
29-
# - run:
30-
# name: Test
31-
# command: 'yarn test'
31+
- run:
32+
name: Test
33+
command: 'DISPLAY=:1 yarn test'
3234
- run:
3335
name: Lint
3436
command: 'yarn run prettier:check'

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,21 @@
9494
"compile": "webpack --mode none",
9595
"watch": "webpack --mode none --watch",
9696
"test-compile": "tsc -p ./ && cp ./package.json ./out/package.json",
97-
"postinstall": "node ./node_modules/vscode/bin/install",
98-
"test": "yarn run prettier:check && yarn run test-compile && node ./node_modules/vscode/bin/test",
97+
"test": "yarn run test-compile && node ./out/test/runTest.js",
9998
"prettier:write": "prettier --single-quote true --print-width 120 --use-tabs true --trailing-comma all --write \"{src,tests}/**/*.ts\"",
10099
"prettier:check": "prettier --single-quote true --print-width 120 --use-tabs true --trailing-comma all --list-different \"{src,tests}/**/*.ts\""
101100
},
102101
"devDependencies": {
103102
"@types/mocha": "^2.2.32",
104103
"@types/node": "^6.0.40",
104+
"@types/vscode": "1.34.0",
105+
"glob": "7.1.6",
105106
"mocha": "5.2.0",
106107
"prettier": "^1.5.3",
107108
"pretty-error": "^2.1.1",
108109
"ts-loader": "6.0.4",
109110
"typescript": "^2.4.2",
110-
"vscode": "^1.1.34",
111+
"vscode-test": "1.3.0",
111112
"webpack": "4.35.0",
112113
"webpack-cli": "3.3.5"
113114
},
@@ -124,4 +125,4 @@
124125
"node.extend": "^1.1.7",
125126
"lodash": "^4.17.12"
126127
}
127-
}
128+
}

test/index.ts

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
1-
//
2-
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
3-
//
4-
// This file is providing the test runner to use when running extension tests.
5-
// By default the test runner in use is Mocha based.
6-
//
7-
// You can provide your own test runner if you want to override it by exporting
8-
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
9-
// host can call to run the tests. The test runner is expected to use console.log
10-
// to report the results back to the caller. When the tests are finished, return
11-
// a possible error to the callback or null if none.
1+
import * as path from 'path';
2+
import * as Mocha from 'mocha';
3+
import * as glob from 'glob';
124

13-
var testRunner = require('vscode/lib/testrunner');
5+
export function run(): Promise<void> {
6+
// Create the mocha test
7+
const mocha = new Mocha({
8+
ui: 'tdd',
9+
});
10+
mocha.useColors(true);
1411

15-
// You can directly control Mocha options by uncommenting the following lines
16-
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
17-
testRunner.configure({
18-
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
19-
useColors: true, // colored output from test results
20-
});
12+
const testsRoot = path.resolve(__dirname, '..');
2113

22-
module.exports = testRunner;
14+
return new Promise((c, e) => {
15+
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
16+
if (err) {
17+
return e(err);
18+
}
19+
20+
// Add files to the test suite
21+
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
22+
23+
try {
24+
// Run the mocha test
25+
mocha.run(failures => {
26+
if (failures > 0) {
27+
e(new Error(`${failures} tests failed.`));
28+
} else {
29+
c();
30+
}
31+
});
32+
} catch (err) {
33+
console.error(err);
34+
e(err);
35+
}
36+
});
37+
});
38+
}

test/runTest.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as path from 'path';
2+
3+
import { runTests } from 'vscode-test';
4+
5+
async function main() {
6+
try {
7+
// The folder containing the Extension Manifest package.json
8+
// Passed to `--extensionDevelopmentPath`
9+
const extensionDevelopmentPath = path.resolve(__dirname, '../');
10+
11+
// The path to the extension test script
12+
// Passed to --extensionTestsPath
13+
const extensionTestsPath = path.resolve(__dirname, './index');
14+
15+
// Download VS Code, unzip it and run the integration test
16+
await runTests({ extensionDevelopmentPath, extensionTestsPath });
17+
} catch (err) {
18+
console.error('Failed to run tests');
19+
process.exit(1);
20+
}
21+
}
22+
23+
main();

test/xvfb.init

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# https://gist.github.com/jterrace/2911875
2+
3+
XVFB=/usr/bin/Xvfb
4+
XVFBARGS=":1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset"
5+
PIDFILE=/var/run/xvfb.pid
6+
case "$1" in
7+
start)
8+
echo -n "Starting virtual X frame buffer: Xvfb"
9+
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
10+
echo "."
11+
;;
12+
stop)
13+
echo -n "Stopping virtual X frame buffer: Xvfb"
14+
start-stop-daemon --stop --quiet --pidfile $PIDFILE
15+
echo "."
16+
;;
17+
restart)
18+
$0 stop
19+
$0 start
20+
;;
21+
*)
22+
echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
23+
exit 1
24+
esac
25+
26+
exit 0

0 commit comments

Comments
 (0)