Skip to content

Commit 60c8348

Browse files
authored
Modify package.json to run ds tests with VSCNotebook (#12270)
1 parent e0476b5 commit 60c8348

File tree

8 files changed

+73
-9
lines changed

8 files changed

+73
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2997,7 +2997,8 @@
29972997
"test:cover:report": "nyc --nycrc-path build/.nycrc report --reporter=text --reporter=html --reporter=text-summary --reporter=cobertura",
29982998
"testDebugger": "node ./out/test/testBootstrap.js ./out/test/debuggerTest.js",
29992999
"testSingleWorkspace": "node ./out/test/testBootstrap.js ./out/test/standardTest.js",
3000-
"testDataScience": "cross-env CODE_TESTS_WORKSPACE=src/test/datascience VSC_PYTHON_CI_TEST_VSC_CHANNEL=insiders TEST_FILES_SUFFIX=ds.test node ./out/test/testBootstrap.js ./out/test/standardTest.js",
3000+
"pretestDataScience": "node ./out/test/datascience/dsTestSetup.js",
3001+
"testDataScience": "cross-env CODE_TESTS_WORKSPACE=src/test/datascience VSC_PYTHON_CI_TEST_VSC_CHANNEL=insiders TEST_FILES_SUFFIX=ds.test VSC_PYTHON_LOAD_EXPERIMENTS_FROM_FILE=true node ./out/test/testBootstrap.js ./out/test/standardTest.js",
30013002
"testMultiWorkspace": "node ./out/test/testBootstrap.js ./out/test/multiRootTest.js",
30023003
"testPerformance": "node ./out/test/testBootstrap.js ./out/test/performanceTest.js",
30033004
"testSmoke": "node ./out/test/smokeTest.js",

src/client/common/experiments/manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export class ExperimentsManager implements IExperimentsManager {
131131
this.populateUserExperiments();
132132
for (const exp of this.userExperiments || []) {
133133
// We need to know whether an experiment influences the logs we observe in github issues, so log the experiment group
134+
// tslint:disable-next-line: no-console
134135
this.output.appendLine(Experiments.inGroup().format(exp.name));
135136
}
136137
this.initializeInBackground().ignoreErrors();

src/test/datascience/.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"python.formatting.provider": "yapf",
1414
"python.pythonPath": "python",
1515
"python.experiments.optInto": [
16+
"LocalZMQKernel - experiment",
1617
"NativeNotebook - experiment"
1718
],
1819
// Do not set this to "Microsoft", else it will result in LS being downloaded on CI

src/test/datascience/dsTestSetup.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import * as fs from 'fs-extra';
5+
import * as path from 'path';
6+
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../constants';
7+
/**
8+
* Modify package.json to ensure VSC Notebooks have been setup so tests can run.
9+
* This is required because we modify package.json during runtime, hence we need to do the same thing for tests.
10+
*/
11+
12+
const packageJsonFile = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'package.json');
13+
const content = JSON.parse(fs.readFileSync(packageJsonFile).toString());
14+
15+
// This code is temporary.
16+
if (
17+
!content.enableProposedApi ||
18+
!Array.isArray(content.contributes.notebookOutputRenderer) ||
19+
!Array.isArray(content.contributes.notebookProvider)
20+
) {
21+
content.enableProposedApi = true;
22+
content.contributes.notebookOutputRenderer = [
23+
{
24+
viewType: 'jupyter-notebook-renderer',
25+
displayName: 'Jupyter Notebook Renderer',
26+
mimeTypes: [
27+
'application/geo+json',
28+
'application/vdom.v1+json',
29+
'application/vnd.dataresource+json',
30+
'application/vnd.plotly.v1+json',
31+
'application/vnd.vega.v2+json',
32+
'application/vnd.vega.v3+json',
33+
'application/vnd.vega.v4+json',
34+
'application/vnd.vega.v5+json',
35+
'application/vnd.vegalite.v1+json',
36+
'application/vnd.vegalite.v2+json',
37+
'application/vnd.vegalite.v3+json',
38+
'application/vnd.vegalite.v4+json',
39+
'application/x-nteract-model-debug+json',
40+
'image/gif',
41+
'text/latex',
42+
'text/vnd.plotly.v1+html'
43+
]
44+
}
45+
];
46+
content.contributes.notebookProvider = [
47+
{
48+
viewType: 'jupyter-notebook',
49+
displayName: 'Jupyter Notebook',
50+
selector: [
51+
{
52+
filenamePattern: '*.ipynb'
53+
}
54+
]
55+
}
56+
];
57+
}
58+
59+
// Update package.json to pick experiments from our custom settings.json file.
60+
content.contributes.configuration.properties['python.experiments.optInto'].scope = 'resource';
61+
62+
fs.writeFileSync(packageJsonFile, JSON.stringify(content, undefined, 4));

src/test/datascience/notebook/executionService.ds.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ const vscodeNotebookEnums = require('vscode') as typeof import('vscode-proposed'
3030

3131
// tslint:disable: no-any no-invalid-this
3232
suite('DataScience - VSCode Notebook - (Execution)', function () {
33-
this.timeout(15_000);
33+
this.timeout(60_000);
3434

3535
let api: IExtensionTestApi;
3636
let editorProvider: INotebookEditorProvider;
3737
const disposables: IDisposable[] = [];
3838
let vscodeNotebook: IVSCodeNotebook;
3939
suiteSetup(async function () {
40-
this.timeout(15_000);
40+
this.timeout(60_000);
4141
api = await initialize();
4242
if (!(await canRunTests())) {
4343
return this.skip();

src/test/datascience/notebook/helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export async function createTemporaryFile(options: {
135135

136136
export async function createTemporaryNotebook(templateFile: string, disposables: IDisposable[]): Promise<string> {
137137
const extension = path.extname(templateFile);
138+
fs.ensureDirSync(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'tmp'));
138139
const tempFile = tmp.tmpNameSync({ postfix: extension, dir: path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'tmp') });
139140
await fs.copyFile(templateFile, tempFile);
140141
disposables.push({ dispose: () => swallowExceptions(() => fs.unlinkSync(tempFile)) });

src/test/datascience/notebook/interrupRestart.ds.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const vscodeNotebookEnums = require('vscode') as typeof import('vscode-proposed'
3636
* This is done by stubbing out some methods.
3737
*/
3838
suite('DataScience - VSCode Notebook - Restart/Interrupt/Cancel/Errors', function () {
39-
this.timeout(15_000);
39+
this.timeout(60_000);
4040

4141
let api: IExtensionTestApi;
4242
let editorProvider: INotebookEditorProvider;
@@ -46,7 +46,7 @@ suite('DataScience - VSCode Notebook - Restart/Interrupt/Cancel/Errors', functio
4646
let vscodeNotebook: IVSCodeNotebook;
4747
const suiteDisposables: IDisposable[] = [];
4848
suiteSetup(async function () {
49-
this.timeout(15_000);
49+
this.timeout(60_000);
5050
api = await initialize();
5151
if (!(await canRunTests())) {
5252
return this.skip();

src/test/datascience/notebook/saving.ds.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ const vscodeNotebookEnums = require('vscode') as typeof import('vscode-proposed'
3535

3636
// tslint:disable: no-any no-invalid-this
3737
suite('DataScience - VSCode Notebook - (Saving)', function () {
38-
this.timeout(15_000);
39-
this.retries(0);
38+
this.timeout(60_000);
4039
const templateIPynb = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'test', 'datascience', 'test.ipynb');
4140
let api: IExtensionTestApi;
4241
let testIPynb: Uri;
4342
let editorProvider: INotebookEditorProvider;
4443
const disposables: IDisposable[] = [];
4544
let vscodeNotebook: IVSCodeNotebook;
4645
suiteSetup(async function () {
47-
this.timeout(15_000);
48-
this.retries(0);
46+
this.timeout(60_000);
4947
api = await initialize();
5048
if (!(await canRunTests())) {
5149
return this.skip();

0 commit comments

Comments
 (0)