Skip to content

Commit b9eafe5

Browse files
committed
intergration tests.
1 parent ab42ffc commit b9eafe5

16 files changed

Lines changed: 1085 additions & 2 deletions

File tree

.vscode/launch.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@
159159
"order": 5
160160
}
161161
},
162+
{
163+
"type": "extensionHost",
164+
"request": "launch",
165+
"name": "VS Code Notebook Tests",
166+
"runtimeExecutable": "${execPath}",
167+
"args": [
168+
"${workspaceFolder}/extensions/vscode-notebook-tests/test",
169+
"--extensionDevelopmentPath=${workspaceFolder}/extensions/vscode-notebook-tests",
170+
"--extensionTestsPath=${workspaceFolder}/extensions/vscode-notebook-tests/out"
171+
],
172+
"outFiles": [
173+
"${workspaceFolder}/out/**/*.js"
174+
],
175+
"presentation": {
176+
"group": "6_tests",
177+
"order": 6
178+
}
179+
},
162180
{
163181
"type": "chrome",
164182
"request": "attach",

build/lib/extensions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ const excludedExtensions = [
186186
'vscode-test-resolver',
187187
'ms-vscode.node-debug',
188188
'ms-vscode.node-debug2',
189+
'vscode-notebook-tests'
189190
];
190191
const builtInExtensions = JSON.parse(fs.readFileSync(path.join(__dirname, '../../product.json'), 'utf8')).builtInExtensions;
191192
function packageLocalExtensionsStream() {

build/lib/extensions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ const excludedExtensions = [
220220
'vscode-test-resolver',
221221
'ms-vscode.node-debug',
222222
'ms-vscode.node-debug2',
223+
'vscode-notebook-tests'
223224
];
224225

225226
interface IBuiltInExtension {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
{
3+
"version": "0.1.0",
4+
"configurations": [
5+
{
6+
"name": "Launch Tests",
7+
"type": "extensionHost",
8+
"request": "launch",
9+
"runtimeExecutable": "${execPath}",
10+
"args": ["${workspaceFolder}/../../", "${workspaceFolder}/test", "--extensionDevelopmentPath=${workspaceFolder}", "--extensionTestsPath=${workspaceFolder}/out" ],
11+
"stopOnEntry": false,
12+
"sourceMaps": true,
13+
"outDir": "${workspaceFolder}/out",
14+
"preLaunchTask": "npm"
15+
}
16+
]
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "2.0.0",
3+
"command": "npm",
4+
"type": "shell",
5+
"presentation": {
6+
"reveal": "silent"
7+
},
8+
"args": ["run", "compile"],
9+
"isBackground": true,
10+
"problemMatcher": "$tsc-watch"
11+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "vscode-notebook-tests",
3+
"description": "Notebook tests for VS Code",
4+
"version": "0.0.1",
5+
"publisher": "vscode",
6+
"license": "MIT",
7+
"private": true,
8+
"activationEvents": [
9+
"*"
10+
],
11+
"main": "./out/notebookTestMain",
12+
"enableProposedApi": true,
13+
"engines": {
14+
"vscode": "^1.25.0"
15+
},
16+
"scripts": {
17+
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
18+
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:vscode-notebook-tests ./tsconfig.json"
19+
},
20+
"dependencies": {},
21+
"devDependencies": {
22+
"typescript": "^3.8.3",
23+
"@types/node": "^12.11.7",
24+
"mocha-junit-reporter": "^1.17.0",
25+
"mocha-multi-reporters": "^1.1.7",
26+
"vscode": "~1.1.36",
27+
"mocha": "^2.3.3"
28+
},
29+
"contributes": {
30+
"notebookProvider": [
31+
{
32+
"viewType": "notebookTest",
33+
"displayName": "Notebook Test",
34+
"selector": [
35+
{
36+
"filenamePattern": "*.ipynb",
37+
"excludeFileNamePattern": "*.test.ipynb"
38+
}
39+
]
40+
}
41+
]
42+
}
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
const path = require('path');
7+
const testRunner = require('vscode/lib/testrunner');
8+
9+
const suite = 'Integration Notebook Tests';
10+
11+
const options: any = {
12+
ui: 'tdd',
13+
useColors: (!process.env.BUILD_ARTIFACTSTAGINGDIRECTORY && process.platform !== 'win32'),
14+
timeout: 60000
15+
};
16+
17+
if (process.env.BUILD_ARTIFACTSTAGINGDIRECTORY) {
18+
options.reporter = 'mocha-multi-reporters';
19+
options.reporterOptions = {
20+
reporterEnabled: 'spec, mocha-junit-reporter',
21+
mochaJunitReporterReporterOptions: {
22+
testsuitesTitle: `${suite} ${process.platform}`,
23+
mochaFile: path.join(process.env.BUILD_ARTIFACTSTAGINGDIRECTORY, `test-results/${process.platform}-${suite.toLowerCase().replace(/[^\w]/g, '-')}-results.xml`)
24+
}
25+
};
26+
}
27+
28+
testRunner.configure(options);
29+
30+
export = testRunner;
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
import 'mocha';
7+
import * as assert from 'assert';
8+
import * as vscode from 'vscode';
9+
import { join } from 'path';
10+
11+
function waitFor(ms: number): Promise<void> {
12+
let resolveFunc: () => void;
13+
14+
const promise = new Promise<void>(resolve => {
15+
resolveFunc = resolve;
16+
});
17+
setTimeout(() => {
18+
resolveFunc!();
19+
}, ms);
20+
21+
return promise;
22+
}
23+
24+
suite('notebook workflow', () => {
25+
test('notebook open', async function () {
26+
const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './first.ipynb'));
27+
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookTest');
28+
29+
await waitFor(500);
30+
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
31+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, 'test');
32+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
33+
34+
await vscode.commands.executeCommand('workbench.notebook.code.insertCellBelow');
35+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, '');
36+
37+
await vscode.commands.executeCommand('workbench.notebook.code.insertCellAbove');
38+
const activeCell = vscode.notebook.activeNotebookEditor!.selection;
39+
assert.notEqual(vscode.notebook.activeNotebookEditor!.selection, undefined);
40+
assert.equal(activeCell!.source, '');
41+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3);
42+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1);
43+
44+
await vscode.commands.executeCommand('workbench.action.files.save');
45+
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
46+
});
47+
48+
test('notebook cell actions', async function () {
49+
const resource = vscode.Uri.parse(join(vscode.workspace.rootPath || '', './second.ipynb'));
50+
await vscode.commands.executeCommand('vscode.openWith', resource, 'notebookTest');
51+
52+
await waitFor(500);
53+
assert.equal(vscode.notebook.activeNotebookEditor !== undefined, true, 'notebook first');
54+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, 'test');
55+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.language, 'typescript');
56+
57+
// ---- insert cell below and focus ---- //
58+
await vscode.commands.executeCommand('workbench.notebook.code.insertCellBelow');
59+
assert.equal(vscode.notebook.activeNotebookEditor!.selection?.source, '');
60+
61+
// ---- insert cell above and focus ---- //
62+
await vscode.commands.executeCommand('workbench.notebook.code.insertCellAbove');
63+
let activeCell = vscode.notebook.activeNotebookEditor!.selection;
64+
assert.notEqual(vscode.notebook.activeNotebookEditor!.selection, undefined);
65+
assert.equal(activeCell!.source, '');
66+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 3);
67+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1);
68+
69+
// ---- focus bottom ---- //
70+
await vscode.commands.executeCommand('workbench.action.notebook.focusBottom');
71+
activeCell = vscode.notebook.activeNotebookEditor!.selection;
72+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 2);
73+
74+
// ---- focus top and then copy down ---- //
75+
await vscode.commands.executeCommand('workbench.action.notebook.focusTop');
76+
activeCell = vscode.notebook.activeNotebookEditor!.selection;
77+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 0);
78+
79+
await vscode.commands.executeCommand('workbench.notebook.cell.copyDown');
80+
activeCell = vscode.notebook.activeNotebookEditor!.selection;
81+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1);
82+
assert.equal(activeCell?.source, 'test');
83+
84+
await vscode.commands.executeCommand('workbench.notebook.cell.delete');
85+
activeCell = vscode.notebook.activeNotebookEditor!.selection;
86+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 1);
87+
assert.equal(activeCell?.source, '');
88+
89+
// ---- focus top and then copy up ---- //
90+
await vscode.commands.executeCommand('workbench.action.notebook.focusTop');
91+
await vscode.commands.executeCommand('workbench.notebook.cell.copyUp');
92+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.length, 4);
93+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[0].source, 'test');
94+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[1].source, 'test');
95+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[2].source, '');
96+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[3].source, '');
97+
activeCell = vscode.notebook.activeNotebookEditor!.selection;
98+
assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 0);
99+
100+
101+
// ---- move up and down ---- //
102+
103+
// await vscode.commands.executeCommand('workbench.notebook.cell.moveDown');
104+
// await vscode.commands.executeCommand('workbench.notebook.cell.moveDown');
105+
// activeCell = vscode.notebook.activeNotebookEditor!.selection;
106+
107+
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells.indexOf(activeCell!), 2);
108+
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[0].source, 'test');
109+
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[1].source, '');
110+
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[2].source, 'test');
111+
// assert.equal(vscode.notebook.activeNotebookEditor!.document.cells[3].source, '');
112+
113+
114+
// ---- ---- //
115+
116+
await vscode.commands.executeCommand('workbench.action.closeActiveEditor');
117+
});
118+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
import * as vscode from 'vscode';
7+
8+
export function activate(context: vscode.ExtensionContext): any {
9+
context.subscriptions.push(vscode.notebook.registerNotebookProvider('notebookTest', {
10+
resolveNotebook: async (editor: vscode.NotebookEditor) => {
11+
await editor.edit(eb => {
12+
eb.insert(0, 'test', 'typescript', vscode.CellKind.Code, [], {});
13+
});
14+
return;
15+
},
16+
executeCell: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell | undefined, _token: vscode.CancellationToken) => {
17+
return;
18+
},
19+
save: async (_document: vscode.NotebookDocument) => {
20+
return true;
21+
}
22+
}));
23+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
/// <reference path="../../../../src/vs/vscode.d.ts" />
7+
/// <reference path="../../../../src/vs/vscode.proposed.d.ts" />
8+
/// <reference types='@types/node'/>
9+

0 commit comments

Comments
 (0)