Skip to content
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

Add browser unit tests to product build #90353

Merged
merged 3 commits into from Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions build/azure-pipelines/darwin/product-build-darwin.yml
Expand Up @@ -99,6 +99,12 @@ steps:
displayName: Run unit tests (Electron)
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))

- script: |
set -e
yarn test-browser --build --browser chromium --browser webkit
displayName: Run unit tests (Browser)
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))

- script: |
# Figure out the full absolute path of the product we just built
# including the remote server and configure the integration tests
Expand Down
6 changes: 6 additions & 0 deletions build/azure-pipelines/linux/product-build-linux.yml
Expand Up @@ -104,6 +104,12 @@ steps:
displayName: Run unit tests (Electron)
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))

- script: |
set -e
DISPLAY=:10 yarn test-browser --build --browser chromium
displayName: Run unit tests (Browser)
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))

- script: |
# Figure out the full absolute path of the product we just built
# including the remote server and configure the integration tests
Expand Down
7 changes: 7 additions & 0 deletions build/azure-pipelines/win32/product-build-win32.yml
Expand Up @@ -112,6 +112,13 @@ steps:
displayName: Run unit tests (Electron)
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))

- powershell: |
. build/azure-pipelines/win32/exec.ps1
$ErrorActionPreference = "Stop"
exec { yarn test-browser --build --browser chromium }
displayName: Run unit tests (Browser)
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))

- powershell: |
# Figure out the full absolute path of the product we just built
# including the remote server and configure the integration tests
Expand Down
5 changes: 4 additions & 1 deletion test/unit/browser/index.js
Expand Up @@ -18,7 +18,7 @@ const playwright = require('playwright');
const defaultReporterName = process.platform === 'win32' ? 'list' : 'spec';
const optimist = require('optimist')
// .describe('grep', 'only run tests matching <pattern>').alias('grep', 'g').alias('grep', 'f').string('grep')
// .describe('build', 'run with build output (out-build)').boolean('build')
.describe('build', 'run with build output (out-build)').boolean('build')
.describe('run', 'only run tests matching <relative_file_path>').string('run')
.describe('glob', 'only run tests matching <glob_pattern>').string('glob')
.describe('debug', 'do not run browsers headless').boolean('debug')
Expand Down Expand Up @@ -122,6 +122,9 @@ async function runTestsInBrowser(testModules, browserType) {
const browser = await playwright[browserType].launch({ headless: !Boolean(argv.debug) });
const page = (await browser.defaultContext().pages())[0]
const target = url.pathToFileURL(path.join(__dirname, 'renderer.html'));
if (argv.build) {
target.search = `?build=true`;
}
await page.goto(target.href);

const emitter = new events.EventEmitter();
Expand Down
33 changes: 19 additions & 14 deletions test/unit/browser/renderer.html
Expand Up @@ -37,15 +37,21 @@
});
</script>

<!-- Depending on --build or not, load loader from known locations -->
<script src="../../../out/vs/loader.js"></script>
<script src="../../../out-build/vs/loader.js"></script>

<script>
const urlParams = new URLSearchParams(window.location.search);
const isBuild = urlParams.get('build');

// configure loader
const baseUrl = window.location.href;
require.config({
catchError: true,
baseUrl: new URL('../../../src', baseUrl).href,
paths: {
'vs': new URL('../../../out/vs', baseUrl).href,
'vs': new URL(`../../../${!!isBuild ? 'out-build' : 'out'}/vs`, baseUrl).href,
assert: new URL('../assert.js', baseUrl).href,
sinon: new URL('../../../node_modules/sinon/pkg/sinon-1.17.7.js', baseUrl).href
}
Expand Down Expand Up @@ -104,19 +110,19 @@

window.loadAndRun = async function loadAndRun(modules, manual = false) {
// load
// await Promise.all(modules.map(module => new Promise((resolve, reject) =>{
// require([module], resolve, err => {
// console.log("BAD " + module + JSON.stringify(err, undefined, '\t'));
// // console.log(module);
// resolve({});
// });
// })));
await new Promise((resolve, reject) => {
require(modules, resolve, err => {
console.log(err);
reject(err);
await Promise.all(modules.map(module => new Promise((resolve, reject) => {
require([module], resolve, err => {
console.log("BAD " + module + JSON.stringify(err, undefined, '\t'));
// console.log(module);
resolve({});
});
});
})));
// await new Promise((resolve, reject) => {
// require(modules, resolve, err => {
// console.log(err);
// reject(err);
// });
// });

// run
return new Promise((resolve, reject) => {
Expand All @@ -127,7 +133,6 @@
});
}


const modules = new URL(window.location.href).searchParams.getAll('m');
if (Array.isArray(modules) && modules.length > 0) {
console.log('MANUALLY running tests', modules);
Expand Down