Skip to content

Commit

Permalink
Update test setup
Browse files Browse the repository at this point in the history
With VS Code v1.36 the vscode package was splitted into different packages:

- vscode
- @types/vscode
- vscode-test

To get updates in the future for these components, the test setup was updated for this extension.
  • Loading branch information
PKief committed Jul 28, 2019
1 parent 5a3ff7e commit 2f1e5d1
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 45 deletions.
34 changes: 25 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,9 @@
"lint": "tslint -c tslint.json ./src/**/*.ts",
"postcompile": "npm run generateJson && npm run check",
"postinstall": "node ./node_modules/vscode/bin/install",
"pretest": "npm run build && npm run test-compile",
"pretest": "npm run build && tsc -p ./",
"preview": "ts-node ./src/scripts/preview",
"test": "node ./node_modules/vscode/bin/test",
"test-compile": "tsc -p ./",
"test": "node ./out/test/runTest.js",
"vscode:prepublish": "npm run lint && npm run compile"
},
"dependencies": {
Expand All @@ -208,15 +207,18 @@
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.2",
"@types/puppeteer": "^1.12.4",
"@types/vscode": "^1.5.0",
"clean-webpack-plugin": "^3.0.0",
"mocha": "^6.1.4",
"glob": "^7.1.4",
"mocha": "^6.2.0",
"puppeteer": "^1.18.1",
"rimraf": "^2.6.3",
"ts-loader": "^6.0.4",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"typescript": "^3.5.3",
"vscode": "^1.1.35",
"vscode-test": "^1.0.2",
"webpack": "^4.35.3",
"webpack-cli": "^3.3.5"
}
Expand Down
23 changes: 0 additions & 23 deletions src/test/index.ts

This file was deleted.

22 changes: 22 additions & 0 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as path from 'path';
import { runTests } from 'vscode-test';

const main = async () => {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

// The path to the extension test script
// 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();
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as assert from 'assert';
import { getObjectPropertyValue } from '../../helpers/objects';
import * as i18n from '../../i18n';
import { getObjectPropertyValue } from '../../../helpers/objects';
import * as i18n from '../../../i18n';

suite('i18n', () => {
test('shoud initialize translations', () => {
test('should initialize translations', () => {
return i18n.initTranslations();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { getDefaultIconOptions, getFileIconDefinitions } from '../../icons/index';
import { FileIcons, IconConfiguration, IconPack } from '../../models/index';
import { getDefaultIconOptions, getFileIconDefinitions } from '../../../icons/index';
import { FileIcons, IconConfiguration, IconPack } from '../../../models/index';

suite('file icons', () => {
test('should configure icon definitions', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { getDefaultIconOptions, getFolderIconDefinitions } from '../../icons/index';
import { FolderTheme, IconConfiguration, IconPack } from '../../models/index';
import { getDefaultIconOptions, getFolderIconDefinitions } from '../../../icons/index';
import { FolderTheme, IconConfiguration, IconPack } from '../../../models/index';

suite('folder icons', () => {
const folderIcons: FolderTheme[] = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import { getDefaultIconOptions, getLanguageIconDefinitions } from '../../icons/index';
import { IconConfiguration, IconPack, LanguageIcon } from '../../models/index';
import { getDefaultIconOptions, getLanguageIconDefinitions } from '../../../icons/index';
import { IconConfiguration, IconPack, LanguageIcon } from '../../../models/index';

suite('language icons', () => {
const iconConfig = new IconConfiguration();
Expand Down
37 changes: 37 additions & 0 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as glob from 'glob';
import * as Mocha from 'mocha';
import * as path from 'path';

export const run = (): Promise<void> => {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
});
mocha.useColors(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) {
e(err);
}
});
});
};

0 comments on commit 2f1e5d1

Please sign in to comment.