Skip to content

Commit 86244d3

Browse files
committed
add API tests that run on a workspace
1 parent faa7f4c commit 86244d3

16 files changed

+128
-12
lines changed

.vscode/launch.json

+16-2
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,26 @@
8181
{
8282
"type": "extensionHost",
8383
"request": "launch",
84-
"name": "VS Code API Tests",
84+
"name": "VS Code API Tests (single folder)",
8585
"runtimeExecutable": "${execPath}",
8686
"args": [
8787
"${workspaceFolder}/extensions/vscode-api-tests/testWorkspace",
8888
"--extensionDevelopmentPath=${workspaceFolder}/extensions/vscode-api-tests",
89-
"--extensionTestsPath=${workspaceFolder}/extensions/vscode-api-tests/out"
89+
"--extensionTestsPath=${workspaceFolder}/extensions/vscode-api-tests/out/singlefolder-tests"
90+
],
91+
"outFiles": [
92+
"${workspaceFolder}/out/**/*.js"
93+
]
94+
},
95+
{
96+
"type": "extensionHost",
97+
"request": "launch",
98+
"name": "VS Code API Tests (workspace)",
99+
"runtimeExecutable": "${execPath}",
100+
"args": [
101+
"${workspaceFolder}/extensions/vscode-api-tests/testWorkspace.code-workspace",
102+
"--extensionDevelopmentPath=${workspaceFolder}/extensions/vscode-api-tests",
103+
"--extensionTestsPath=${workspaceFolder}/extensions/vscode-api-tests/out/workspace-tests"
90104
],
91105
"outFiles": [
92106
"${workspaceFolder}/out/**/*.js"

build/gulpfile.hygiene.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ const indentationFilter = [
7777
'!extensions/**/syntaxes/**',
7878
'!extensions/**/themes/**',
7979
'!extensions/**/colorize-fixtures/**',
80-
'!extensions/vscode-api-tests/testWorkspace/**'
80+
'!extensions/vscode-api-tests/testWorkspace/**',
81+
'!extensions/vscode-api-tests/testWorkspace2/**'
8182
];
8283

8384
const copyrightFilter = [
@@ -95,6 +96,7 @@ const copyrightFilter = [
9596
'!**/*.xpm',
9697
'!**/*.opts',
9798
'!**/*.disabled',
99+
'!**/*.code-workspace',
98100
'!build/**/*.init',
99101
'!resources/linux/snap/snapcraft.yaml',
100102
'!resources/win32/bin/code.js',
@@ -124,6 +126,7 @@ const tslintFilter = [
124126
'!**/node_modules/**',
125127
'!extensions/typescript/test/colorize-fixtures/**',
126128
'!extensions/vscode-api-tests/testWorkspace/**',
129+
'!extensions/vscode-api-tests/testWorkspace2/**',
127130
'!extensions/**/*.test.ts',
128131
'!extensions/html/server/lib/jquery.d.ts'
129132
];

extensions/vscode-api-tests/src/editor.test.ts extensions/vscode-api-tests/src/singlefolder-tests/editor.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as assert from 'assert';
99
import { workspace, window, Position, Range, commands, TextEditor, TextDocument, TextEditorCursorStyle, TextEditorLineNumbersStyle, SnippetString, Selection } from 'vscode';
10-
import { createRandomFile, deleteFile, closeAllEditors } from './utils';
10+
import { createRandomFile, deleteFile, closeAllEditors } from '../utils';
1111

1212
suite('editor tests', () => {
1313

extensions/vscode-api-tests/src/languages.test.ts extensions/vscode-api-tests/src/singlefolder-tests/languages.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ suite('languages namespace tests', () => {
2121
constructor() {
2222
super(new Range(0, 2, 0, 7), 'sonntag');
2323
}
24-
};
24+
}
2525

2626
let diag1 = new Diagnostic(new Range(0, 0, 0, 5), 'montag');
2727
let diag2 = new D2();

extensions/vscode-api-tests/src/window.test.ts extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import * as assert from 'assert';
99
import { workspace, window, commands, ViewColumn, TextEditorViewColumnChangeEvent, Uri, Selection, Position, CancellationTokenSource, TextEditorSelectionChangeKind } from 'vscode';
1010
import { join } from 'path';
11-
import { closeAllEditors, pathEquals, createRandomFile } from './utils';
11+
import { closeAllEditors, pathEquals, createRandomFile } from '../utils';
1212

1313
suite('window namespace tests', () => {
1414

extensions/vscode-api-tests/src/workspace.test.ts extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
import * as assert from 'assert';
99
import * as vscode from 'vscode';
10-
import { createRandomFile, deleteFile, closeAllEditors, pathEquals } from './utils';
10+
import { createRandomFile, deleteFile, closeAllEditors, pathEquals } from '../utils';
1111
import { join, basename } from 'path';
1212
import * as fs from 'fs';
13-
import { Uri } from 'vscode';
1413

1514
suite('workspace-namespace', () => {
1615

@@ -39,11 +38,27 @@ suite('workspace-namespace', () => {
3938

4039
test('rootPath', () => {
4140
if (vscode.workspace.rootPath) {
42-
assert.ok(pathEquals(vscode.workspace.rootPath, join(__dirname, '../testWorkspace')));
41+
assert.ok(pathEquals(vscode.workspace.rootPath, join(__dirname, '../../testWorkspace')));
4342
}
4443
assert.throws(() => vscode.workspace.rootPath = 'farboo');
4544
});
4645

46+
test('workspaceFolders', () => {
47+
if (vscode.workspace.workspaceFolders) {
48+
assert.equal(vscode.workspace.workspaceFolders.length, 1);
49+
assert.ok(pathEquals(vscode.workspace.workspaceFolders[0].uri.fsPath, join(__dirname, '../../testWorkspace')));
50+
}
51+
});
52+
53+
test('getWorkspaceFolder', () => {
54+
const folder = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(join(__dirname, '../../testWorkspace/far.js')));
55+
assert.ok(!!folder);
56+
57+
if (folder) {
58+
assert.ok(pathEquals(folder.uri.fsPath, join(__dirname, '../../testWorkspace')));
59+
}
60+
});
61+
4762
test('openTextDocument', () => {
4863
let len = vscode.workspace.textDocuments.length;
4964
return vscode.workspace.openTextDocument(join(vscode.workspace.rootPath || '', './simple.txt')).then(doc => {
@@ -536,7 +551,7 @@ suite('workspace-namespace', () => {
536551

537552
test('applyEdit should fail when editing renamed from resource', async () => {
538553
const resource = await createRandomFile();
539-
const newResource = Uri.parse(resource.fsPath + '.1');
554+
const newResource = vscode.Uri.parse(resource.fsPath + '.1');
540555
const edit = new vscode.WorkspaceEdit();
541556
edit.renameResource(resource, newResource);
542557
try {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
8+
//
9+
// This file is providing the test runner to use when running extension tests.
10+
// By default the test runner in use is Mocha based.
11+
//
12+
// You can provide your own test runner if you want to override it by exporting
13+
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
14+
// host can call to run the tests. The test runner is expected to use console.log
15+
// to report the results back to the caller. When the tests are finished, return
16+
// a possible error to the callback or null if none.
17+
18+
const testRunner = require('vscode/lib/testrunner');
19+
20+
// You can directly control Mocha options by uncommenting the following lines
21+
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
22+
testRunner.configure({
23+
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
24+
useColors: process.platform !== 'win32', // colored output from test results (only windows cannot handle)
25+
timeout: 60000
26+
});
27+
28+
export = testRunner;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
'use strict';
7+
8+
import * as assert from 'assert';
9+
import * as vscode from 'vscode';
10+
import { closeAllEditors, pathEquals } from '../utils';
11+
import { join } from 'path';
12+
13+
suite('workspace-namespace', () => {
14+
15+
teardown(closeAllEditors);
16+
17+
test('rootPath', () => {
18+
if (vscode.workspace.rootPath) {
19+
assert.ok(pathEquals(vscode.workspace.rootPath, join(__dirname, '../../testWorkspace')));
20+
}
21+
});
22+
23+
test('workspaceFolders', () => {
24+
if (vscode.workspace.workspaceFolders) {
25+
assert.equal(vscode.workspace.workspaceFolders.length, 2);
26+
assert.ok(pathEquals(vscode.workspace.workspaceFolders[0].uri.fsPath, join(__dirname, '../../testWorkspace')));
27+
assert.ok(pathEquals(vscode.workspace.workspaceFolders[1].uri.fsPath, join(__dirname, '../../testWorkspace2')));
28+
assert.ok(pathEquals(vscode.workspace.workspaceFolders[1].name, 'Test Workspace 2'));
29+
}
30+
});
31+
32+
test('getWorkspaceFolder', () => {
33+
const folder = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(join(__dirname, '../../testWorkspace2/far.js')));
34+
assert.ok(!!folder);
35+
36+
if (folder) {
37+
assert.ok(pathEquals(folder.uri.fsPath, join(__dirname, '../../testWorkspace2')));
38+
}
39+
});
40+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Just a simple file...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "testWorkspace"
5+
},
6+
{
7+
"path": "testWorkspace2",
8+
"name": "Test Workspace 2"
9+
}
10+
]
11+
}

scripts/test-integration.bat

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ if not "%APPVEYOR%" == "" (
99
set VSCODEUSERDATADIR=%TMP%\vscodeuserfolder-%RANDOM%-%TIME:~6,5%
1010

1111
:: Tests in the extension host
12-
call .\scripts\code.bat %~dp0\..\extensions\vscode-api-tests\testWorkspace --extensionDevelopmentPath=%~dp0\..\extensions\vscode-api-tests --extensionTestsPath=%~dp0\..\extensions\vscode-api-tests\out --disableExtensions --user-data-dir=%VSCODEUSERDATADIR%
12+
call .\scripts\code.bat %~dp0\..\extensions\vscode-api-tests\testWorkspace --extensionDevelopmentPath=%~dp0\..\extensions\vscode-api-tests --extensionTestsPath=%~dp0\..\extensions\vscode-api-tests\out\singlefolder-tests --disableExtensions --user-data-dir=%VSCODEUSERDATADIR%
13+
if %errorlevel% neq 0 exit /b %errorlevel%
14+
15+
call .\scripts\code.bat %~dp0\..\extensions\vscode-api-tests\testWorkspace.code-workspace --extensionDevelopmentPath=%~dp0\..\extensions\vscode-api-tests --extensionTestsPath=%~dp0\..\extensions\vscode-api-tests\out\workspace-tests --disableExtensions --user-data-dir=%VSCODEUSERDATADIR%
1316
if %errorlevel% neq 0 exit /b %errorlevel%
1417

1518
call .\scripts\code.bat %~dp0\..\extensions\vscode-colorize-tests\test --extensionDevelopmentPath=%~dp0\..\extensions\vscode-colorize-tests --extensionTestsPath=%~dp0\..\extensions\vscode-colorize-tests\out --disableExtensions --user-data-dir=%VSCODEUSERDATADIR%

scripts/test-integration.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ fi
1313
cd $ROOT
1414

1515
# Tests in the extension host
16-
./scripts/code.sh $ROOT/extensions/vscode-api-tests/testWorkspace --extensionDevelopmentPath=$ROOT/extensions/vscode-api-tests --extensionTestsPath=$ROOT/extensions/vscode-api-tests/out --disableExtensions --user-data-dir=$VSCODEUSERDATADIR --skip-getting-started
16+
./scripts/code.sh $ROOT/extensions/vscode-api-tests/testWorkspace --extensionDevelopmentPath=$ROOT/extensions/vscode-api-tests --extensionTestsPath=$ROOT/extensions/vscode-api-tests/out/singlefolder-tests --disableExtensions --user-data-dir=$VSCODEUSERDATADIR --skip-getting-started
17+
./scripts/code.sh $ROOT/extensions/vscode-api-tests/testWorkspace.code-workspace --extensionDevelopmentPath=$ROOT/extensions/vscode-api-tests --extensionTestsPath=$ROOT/extensions/vscode-api-tests/out/workspace-tests --disableExtensions --user-data-dir=$VSCODEUSERDATADIR --skip-getting-started
1718
./scripts/code.sh $ROOT/extensions/vscode-colorize-tests/test --extensionDevelopmentPath=$ROOT/extensions/vscode-colorize-tests --extensionTestsPath=$ROOT/extensions/vscode-colorize-tests/out --disableExtensions --user-data-dir=$VSCODEUSERDATADIR --skip-getting-started
1819
./scripts/code.sh $ROOT/extensions/emmet/test-fixtures --extensionDevelopmentPath=$ROOT/extensions/emmet --extensionTestsPath=$ROOT/extensions/emmet/out/test --disableExtensions --user-data-dir=$VSCODEUSERDATADIR --skip-getting-started
1920

0 commit comments

Comments
 (0)