Skip to content

Commit

Permalink
[browser tests] update Puppeteer
Browse files Browse the repository at this point in the history
The version of Puppeteer we had is quite old and includes a version of
Chromium that does not support some of the DOM API functions we use in the
code base. e.g. HTMLElement.replaceChildren() [1], that we use in
hover-service.ts

The latest version seems to work well, and supports the example above,
so I went with that. Note that Puppeteer now bundles its typing file, and
that some of the APIs have changed slightly, requiring a small adaptation
on our end.

[1]: https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren#browser_compatibility

Signed-off-by: Marc Dumais <marc.dumais@ericsson.com>
  • Loading branch information
marcdumais-work committed Feb 27, 2023
1 parent 7fd510e commit 4f7db9e
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 78 deletions.
9 changes: 4 additions & 5 deletions dev-packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,23 @@
"@types/chai": "^4.2.7",
"@types/mocha": "^10.0.0",
"@types/node-fetch": "^2.5.7",
"@types/puppeteer": "^2.0.0",
"chai": "^4.2.0",
"chalk": "4.0.0",
"decompress": "^4.2.1",
"glob": "^8.0.3",
"limiter": "^2.1.0",
"log-update": "^4.0.0",
"mocha": "^10.1.0",
"puppeteer": "^2.0.0",
"puppeteer-to-istanbul": "^1.2.2",
"puppeteer": "^19.7.2",
"puppeteer-core": "^19.7.2",
"puppeteer-to-istanbul": "^1.4.0",
"temp": "^0.9.1",
"yargs": "^15.3.1"
},
"devDependencies": {
"@types/chai": "^4.2.7",
"@types/mocha": "^10.0.0",
"@types/node-fetch": "^2.5.7",
"@types/proxy-from-env": "^1.0.1",
"@types/puppeteer": "^2.0.0"
"@types/proxy-from-env": "^1.0.1"
}
}
12 changes: 9 additions & 3 deletions dev-packages/cli/src/run-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import * as net from 'net';
import * as puppeteer from 'puppeteer';
import * as puppeteer from 'puppeteer-core';
import newTestPage, { TestFileOptions } from './test-page';

export interface TestOptions {
start: () => Promise<net.AddressInfo>
launch?: puppeteer.LaunchOptions
launch?: puppeteer.PuppeteerLaunchOptions
files?: Partial<TestFileOptions>
coverage?: boolean
}
Expand Down Expand Up @@ -50,8 +50,14 @@ export default async function runTest(options: TestOptions): Promise<void> {
// the app has focus, to avoid failures of tests that query the UI's state.
if (launch && launch.devtools) {
promises.push(testPage.waitForSelector('#theia-app-shell.p-Widget.theia-ApplicationShell')
.then(e => e.click()));
.then(e => {
// eslint-disable-next-line no-null/no-null
if (e !== null) {
e.click();
}
}));
}

// Clear application's local storage to avoid reusing previous state
promises.push(testPage.evaluate(() => localStorage.clear()));
await Promise.all(promises);
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/cli/src/test-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/* eslint-disable @typescript-eslint/no-explicit-any */

import * as puppeteer from 'puppeteer';
import * as puppeteer from 'puppeteer-core';
const collectFiles: (options: TestFileOptions) => string[] = require('mocha/lib/cli/collect-files');

export interface TestFileOptions {
Expand Down
5 changes: 4 additions & 1 deletion dev-packages/cli/src/theia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import downloadPlugins from './download-plugins';
import runTest from './run-test';
import { LocalizationManager, extract } from '@theia/localization-manager';

const { executablePath } = require('puppeteer');

process.on('unhandledRejection', (reason, promise) => {
throw reason;
});
Expand Down Expand Up @@ -527,7 +529,8 @@ async function theiaCli(): Promise<void> {
args: ['--no-sandbox'],
// eslint-disable-next-line no-null/no-null
defaultViewport: null, // view port can take available space instead of 800x600 default
devtools: testInspect
devtools: testInspect,
executablePath: executablePath()
},
files: {
extension: testExtension,
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@types/chai-string": "^1.4.0",
"@types/jsdom": "^11.0.4",
"@types/node": "16",
"@types/puppeteer": "^2.0.0",
"@types/sinon": "^10.0.6",
"@types/temp": "^0.8.29",
"@types/uuid": "^7.0.3",
Expand Down Expand Up @@ -45,8 +44,9 @@
"node-gyp": "^9.0.0",
"nsfw": "^2.2.4",
"nyc": "^15.0.0",
"puppeteer": "^2.0.0",
"puppeteer-to-istanbul": "^1.2.2",
"puppeteer": "^19.7.2",
"puppeteer-core": "^19.7.2",
"puppeteer-to-istanbul": "^1.4.0",
"rimraf": "^2.6.1",
"sinon": "^12.0.0",
"temp": "^0.8.3",
Expand Down
Loading

0 comments on commit 4f7db9e

Please sign in to comment.