Skip to content

Commit cdf4026

Browse files
author
Benjamin Pasero
authored
Add browser unit tests to product build (microsoft#90353)
* wip - add browser unit tests to product build * run with more output * load loader via script tag
1 parent 7b8c5cd commit cdf4026

5 files changed

Lines changed: 42 additions & 15 deletions

File tree

build/azure-pipelines/darwin/product-build-darwin.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ steps:
9999
displayName: Run unit tests (Electron)
100100
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))
101101

102+
- script: |
103+
set -e
104+
yarn test-browser --build --browser chromium --browser webkit
105+
displayName: Run unit tests (Browser)
106+
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))
107+
102108
- script: |
103109
# Figure out the full absolute path of the product we just built
104110
# including the remote server and configure the integration tests

build/azure-pipelines/linux/product-build-linux.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ steps:
104104
displayName: Run unit tests (Electron)
105105
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))
106106

107+
- script: |
108+
set -e
109+
DISPLAY=:10 yarn test-browser --build --browser chromium
110+
displayName: Run unit tests (Browser)
111+
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))
112+
107113
- script: |
108114
# Figure out the full absolute path of the product we just built
109115
# including the remote server and configure the integration tests

build/azure-pipelines/win32/product-build-win32.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ steps:
112112
displayName: Run unit tests (Electron)
113113
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))
114114

115+
- powershell: |
116+
. build/azure-pipelines/win32/exec.ps1
117+
$ErrorActionPreference = "Stop"
118+
exec { yarn test-browser --build --browser chromium }
119+
displayName: Run unit tests (Browser)
120+
condition: and(succeeded(), eq(variables['VSCODE_STEP_ON_IT'], 'false'))
121+
115122
- powershell: |
116123
# Figure out the full absolute path of the product we just built
117124
# including the remote server and configure the integration tests

test/unit/browser/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const playwright = require('playwright');
1818
const defaultReporterName = process.platform === 'win32' ? 'list' : 'spec';
1919
const optimist = require('optimist')
2020
// .describe('grep', 'only run tests matching <pattern>').alias('grep', 'g').alias('grep', 'f').string('grep')
21-
// .describe('build', 'run with build output (out-build)').boolean('build')
21+
.describe('build', 'run with build output (out-build)').boolean('build')
2222
.describe('run', 'only run tests matching <relative_file_path>').string('run')
2323
.describe('glob', 'only run tests matching <glob_pattern>').string('glob')
2424
.describe('debug', 'do not run browsers headless').boolean('debug')
@@ -122,6 +122,9 @@ async function runTestsInBrowser(testModules, browserType) {
122122
const browser = await playwright[browserType].launch({ headless: !Boolean(argv.debug) });
123123
const page = (await browser.defaultContext().pages())[0]
124124
const target = url.pathToFileURL(path.join(__dirname, 'renderer.html'));
125+
if (argv.build) {
126+
target.search = `?build=true`;
127+
}
125128
await page.goto(target.href);
126129

127130
const emitter = new events.EventEmitter();

test/unit/browser/renderer.html

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,21 @@
3737
});
3838
</script>
3939

40+
<!-- Depending on --build or not, load loader from known locations -->
4041
<script src="../../../out/vs/loader.js"></script>
42+
<script src="../../../out-build/vs/loader.js"></script>
43+
4144
<script>
45+
const urlParams = new URLSearchParams(window.location.search);
46+
const isBuild = urlParams.get('build');
47+
4248
// configure loader
4349
const baseUrl = window.location.href;
4450
require.config({
4551
catchError: true,
4652
baseUrl: new URL('../../../src', baseUrl).href,
4753
paths: {
48-
'vs': new URL('../../../out/vs', baseUrl).href,
54+
'vs': new URL(`../../../${!!isBuild ? 'out-build' : 'out'}/vs`, baseUrl).href,
4955
assert: new URL('../assert.js', baseUrl).href,
5056
sinon: new URL('../../../node_modules/sinon/pkg/sinon-1.17.7.js', baseUrl).href
5157
}
@@ -104,19 +110,19 @@
104110

105111
window.loadAndRun = async function loadAndRun(modules, manual = false) {
106112
// load
107-
// await Promise.all(modules.map(module => new Promise((resolve, reject) =>{
108-
// require([module], resolve, err => {
109-
// console.log("BAD " + module + JSON.stringify(err, undefined, '\t'));
110-
// // console.log(module);
111-
// resolve({});
112-
// });
113-
// })));
114-
await new Promise((resolve, reject) => {
115-
require(modules, resolve, err => {
116-
console.log(err);
117-
reject(err);
113+
await Promise.all(modules.map(module => new Promise((resolve, reject) => {
114+
require([module], resolve, err => {
115+
console.log("BAD " + module + JSON.stringify(err, undefined, '\t'));
116+
// console.log(module);
117+
resolve({});
118118
});
119-
});
119+
})));
120+
// await new Promise((resolve, reject) => {
121+
// require(modules, resolve, err => {
122+
// console.log(err);
123+
// reject(err);
124+
// });
125+
// });
120126

121127
// run
122128
return new Promise((resolve, reject) => {
@@ -127,7 +133,6 @@
127133
});
128134
}
129135

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

0 commit comments

Comments
 (0)