-
Notifications
You must be signed in to change notification settings - Fork 325
Enable intellisense and improve web smoke tests #9623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
const path = require('path'); | ||
const test_web = require('@vscode/test-web'); | ||
async function go() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this, we don't need to compile the ts file anymore, we can just run webpack and that's it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Besides TS is smart enough to give decent completions for this. |
||
try { | ||
const extensionDevelopmentPath = path.resolve(__dirname, '../'); | ||
await test_web.runTests({ | ||
browserType: 'chromium', | ||
extensionDevelopmentPath, | ||
extensionTestsPath: path.join(extensionDevelopmentPath, 'out', 'extension.web.bundle') | ||
}); | ||
} catch (err) { | ||
console.error('Failed to run tests'); | ||
process.exit(1); | ||
} | ||
} | ||
void go(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,23 @@ const webpack = require('webpack'); | |
const constants = require('../constants'); | ||
const CleanTerminalPlugin = require('clean-terminal-webpack-plugin'); | ||
|
||
const prodEntry = { | ||
extension: './src/extension.web.ts', | ||
'test/smoke.test/index': './src/test/web/smoke.test/index.ts' // source of the web extension test runner | ||
}; | ||
const testEntry = { | ||
extension: './src/test/web/smoke.test/index.ts' // source of the web extension test runner | ||
}; | ||
|
||
// When running web tests, the entry point for the tests and extension are the same. | ||
const entry = process.env.VSC_TEST_BUNDLE ? testEntry : prodEntry; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the magic happens |
||
|
||
// tslint:disable-next-line:no-var-requires no-require-imports | ||
const configFileName = path.join(constants.ExtensionRootDir, 'tsconfig.extension.web.json'); | ||
const config = { | ||
mode: 'none', | ||
mode: process.env.VSC_TEST_BUNDLE ? 'development' : 'none', | ||
target: 'webworker', | ||
entry: { | ||
extension: './src/extension.web.ts', | ||
'test/vscode.test/index': './src/test/web/vscode.test/index.ts', // source of the web extension test runner | ||
'test/smoke.test/index': './src/test/web/smoke.test/index.ts' // source of the web extension test runner | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well not yet. I was going to use it to host the vscode tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's a vscode test? |
||
}, | ||
entry, | ||
devtool: 'nosources-source-map', // create a source map that points to the original source file | ||
node: { | ||
__dirname: false, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ import { INotebookEditorProvider } from '../notebooks/types'; | |
import { IDataViewerDataProvider, IDataViewerFactory } from '../webviews/extension-side/dataviewer/types'; | ||
import { IExportedKernelService } from './api/extension'; | ||
import { IExportedKernelServiceFactory, IPythonApiProvider, PythonApi } from './api/types'; | ||
import { IApplicationShell } from './common/application/types'; | ||
import { isTestExecution } from './common/constants'; | ||
import { IExtensionContext } from './common/types'; | ||
import { IServiceContainer, IServiceManager } from './ioc/types'; | ||
|
@@ -102,14 +101,6 @@ export function buildApi( | |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
(api as any).serviceContainer = serviceContainer; | ||
(api as any).serviceManager = serviceManager; | ||
(api as any).getSymbol = (symbol: String) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gone now |
||
// Needed for web tests. Eval for the extension happens in another web worker so | ||
// the symbol objects have different values | ||
switch (symbol) { | ||
case 'IApplicationShell': | ||
return IApplicationShell; | ||
} | ||
}; | ||
/* eslint-enable @typescript-eslint/no-explicit-any */ | ||
} | ||
return api; | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,64 @@ | ||
// imports mocha for the browser, defining the `mocha` global. | ||
require('mocha/mocha'); | ||
// Re-export extension entry point, so that the output from this file | ||
// when bundled can be used as entry point for extension as well as tests. | ||
// The same objects/types will be used as the module is only ever loaded once by nodejs. | ||
import * as extension from '../../../extension.web'; | ||
import * as vscode from 'vscode'; | ||
import type { IExtensionApi } from '../../../platform/api'; | ||
import type { IExtensionContext } from '../../../platform/common/types'; | ||
import { IExtensionTestApi } from '../../common'; | ||
import { JVSC_EXTENSION_ID } from '../../../platform/common/constants'; | ||
|
||
export function run(): Promise<void> { | ||
return new Promise((c, e) => { | ||
mocha.setup({ | ||
ui: 'tdd', | ||
reporter: undefined | ||
}); | ||
let activatedResponse: undefined | IExtensionApi; | ||
|
||
// bundles all files in the current directory matching `*.test` | ||
const importAll = (r: __WebpackModuleApi.RequireContext) => r.keys().forEach(r); | ||
importAll(require.context('.', true, /\.web.test$/)); | ||
// Basically this is the entry point for the extension. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This bundle will be the entry point for the extension, and everything uses the same bundle and tests are in here too. |
||
export async function activate(context: IExtensionContext): Promise<IExtensionApi> { | ||
if (activatedResponse) { | ||
return activatedResponse; | ||
} | ||
vscode.commands.registerCommand('jupyter.web.runTests', async () => { | ||
// imports mocha for the browser, defining the `mocha` global. | ||
require('mocha/mocha'); | ||
|
||
try { | ||
// Run the mocha test | ||
mocha.run((failures) => { | ||
if (failures > 0) { | ||
e(new Error(`${failures} tests failed.`)); | ||
} else { | ||
c(); | ||
} | ||
return new Promise<void>((resolve, reject) => { | ||
mocha.setup({ | ||
ui: 'tdd', | ||
reporter: undefined | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
e(err); | ||
} | ||
|
||
// bundles all files in the current directory matching `*.test` | ||
const importAll = (r: __WebpackModuleApi.RequireContext) => r.keys().forEach(r); | ||
importAll(require.context('.', true, /\.web.test$/)); | ||
|
||
try { | ||
// Run the mocha test | ||
mocha.run((failures) => { | ||
if (failures > 0) { | ||
reject(new Error(`${failures} tests failed.`)); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
activatedResponse = await extension.activate(context); | ||
return activatedResponse; | ||
} | ||
|
||
export async function deactivate(): Promise<void> { | ||
return extension.deactivate(); | ||
} | ||
|
||
export async function run(): Promise<void> { | ||
// Activate the extension so that the commands are registered. | ||
// Also this will not slow down the suite-setups. | ||
const extension = vscode.extensions.getExtension<IExtensionTestApi>(JVSC_EXTENSION_ID)!; | ||
const api = await extension.activate(); | ||
await api.ready; | ||
// Run the tests from within the context of the extension bundle. | ||
// We achieve this by getting the extension to run the tests (then its guaranteed to use the same context as the extension). | ||
await vscode.commands.executeCommand('jupyter.web.runTests'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,7 @@ suite('Web Extension Smoke Test Suite', () => { | |
}); | ||
|
||
test('Verify containers', () => { | ||
const appShellSymbol = extensionApi.getSymbol<IApplicationShell>('IApplicationShell'); | ||
assert.ok(appShellSymbol, `Cannot get the symbol for IApplicationShell`); | ||
const appShell = extensionApi.serviceManager?.get<IApplicationShell>(appShellSymbol!); | ||
const appShell = extensionApi.serviceManager?.get<IApplicationShell>(IApplicationShell); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note; Previously we didn't get any intellisense in here at all, now we do. |
||
assert.ok(appShell, 'Dependency Injection container not initialized in web context'); | ||
}); | ||
}); |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
"resolveJsonModule": true, | ||
"removeComments": true, | ||
"useUnknownInCatchVariables": false, | ||
"types": ["@types/vscode-notebook-renderer/preload"] | ||
"types": ["@types/vscode-notebook-renderer/preload", "webpack-env"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better development experience (i.e. during editing we'll get code completions) |
||
}, | ||
"exclude": [ | ||
"node_modules", | ||
|
@@ -35,7 +35,6 @@ | |
"src/ipywidgets", | ||
"src/smoke", | ||
"src/test/datascience/extensionapi", | ||
"src/test/web", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better development experience (i.e. during editing we'll get code completions) |
||
"build", | ||
"out", | ||
"ipywidgets", | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently this doesn't work because of node-fetch.
We can use
cross-fetch
(via webpack) to get around this, however i think its a bug caused by vscode.node-fetch works in tests when run from the CLI, however when you debug it fails, something to do with global variables (in webworker,
self
is available, but when debuggingself
is not available, could be something vscode is shadowing or removing deliberately).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I.e. a bug in vscode.