Repository navigation
Load a preview in the webview first #9009
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| const path = require('path'); | ||
| const glob = require('glob'); | ||
| const Mocha = require('mocha'); | ||
| const webpack = require('webpack'); | ||
| const installJsDomGlobal = require('jsdom-global'); | ||
|
|
||
| async function main() { | ||
| const root = path.resolve(__dirname, '..'); | ||
| const tests = glob.sync('webviews/**/test/**/*.test.{ts,tsx}', { cwd: root, absolute: true }).sort(); | ||
| if (!tests.length) { | ||
| throw new Error('No webview test files found.'); | ||
| } | ||
|
|
||
| const configs = await require('../webpack.config')({ esbuild: true }, { mode: 'development' }); | ||
| const config = configs.find(config => config.name === 'webviews'); | ||
| config.entry = [path.join(root, 'src', 'test', 'webviews', 'setup.ts'), ...tests]; | ||
| config.target = 'node'; | ||
| config.output = { path: path.join(root, 'out', 'webview-tests'), filename: 'index.js' }; | ||
| config.externals = [({ request }, callback) => { | ||
| if (!request.startsWith('.') && !path.isAbsolute(request)) { | ||
| callback(null, 'commonjs ' + request); | ||
| } else { | ||
| callback(); | ||
| } | ||
| }]; | ||
|
|
||
| await new Promise((resolve, reject) => { | ||
| const compiler = webpack(config); | ||
| compiler.run((error, stats) => compiler.close(closeError => { | ||
| if (error || closeError) { | ||
| reject(error ?? closeError); | ||
| } else if (stats.hasErrors()) { | ||
| reject(new Error(stats.toString('errors-warnings'))); | ||
| } else { | ||
| if (stats.hasWarnings()) { | ||
| process.stderr.write(stats.toString('errors-warnings') + '\n'); | ||
| } | ||
| resolve(); | ||
| } | ||
| })); | ||
| }); | ||
|
|
||
| const mocha = new Mocha({ ui: 'bdd', color: true, failZero: true }); | ||
| if (process.env.TEST_JUNIT_XML_PATH) { | ||
| const report = process.env.TEST_JUNIT_XML_PATH; | ||
| mocha.reporter('mocha-multi-reporters', { | ||
| reporterEnabled: 'mocha-junit-reporter, spec', | ||
| mochaJunitReporterReporterOptions: { | ||
| mochaFile: path.join(path.dirname(report), `webviews-${path.basename(report)}`), | ||
| suiteTitleSeparatedBy: ' / ', | ||
| outputs: true, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| const cleanup = installJsDomGlobal('', { pretendToBeVisual: true }); | ||
| // Match JSDOM's APIs rather than exposing Node's MessageChannel to React's scheduler. | ||
| const messageChannel = global.MessageChannel; | ||
| global.MessageChannel = window.MessageChannel; | ||
| try { | ||
| require('source-map-support').install(); | ||
| mocha.addFile(path.join(config.output.path, config.output.filename)); | ||
| const failures = await new Promise(resolve => mocha.run(resolve)); | ||
| process.exitCode = failures ? 1 : 0; | ||
| } finally { | ||
| mocha.dispose(); | ||
| window.close(); | ||
| cleanup(); | ||
| global.MessageChannel = messageChannel; | ||
| } | ||
| } | ||
|
|
||
| main().catch(error => { | ||
| process.stderr.write(`${error.stack ?? error}\n`); | ||
| process.exitCode = 1; | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.