Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@web/test-runner-chrome

Package Overview
Dependencies
Maintainers
7
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web/test-runner-chrome - npm Package Compare versions

Comparing version 0.6.4 to 0.6.5

6

CHANGELOG.md
# @web/test-runner-chrome
## 0.6.5
### Patch Changes
- 41d895f: capture native browser errors
## 0.6.4

@@ -4,0 +10,0 @@

48

dist/ChromeLauncherPage.js

@@ -6,2 +6,15 @@ "use strict";

const browser_logs_1 = require("@web/browser-logs");
// these warnings are generated by mocha
const filteredBrowserWarnings = [
"'window.webkitStorageInfo' is deprecated.",
'onmozfullscreenchange is deprecated.',
'onmozfullscreenerror is deprecated.',
];
function filterBrowserLogs(browserLogs) {
return browserLogs.filter(log => {
return !(log.length === 1 &&
typeof log[0] === 'string' &&
filteredBrowserWarnings.some(warn => log[0].includes(warn)));
});
}
class ChromeLauncherPage {

@@ -19,15 +32,21 @@ constructor(config, testFiles, product, puppeteerPage) {

}
const logsPromise = message.args().map(arg => arg
// serialize the log message in the browser to a string
// __wtr_browser_logs__ is injected by a script, but in some cases we're setting it isn't available
// for example for browser native warnings
.evaluateHandle(e => window.__wtr_browser_logs__
? window.__wtr_browser_logs__.serialize(e)
: JSON.stringify(e))
// pass along the message from the browser to NodeJS as a string
.then(handle => handle.jsonValue())
// deserialize the string to an array of logs
.then(str => browser_logs_1.deserialize(str))
.catch(err => `Error while collecting browser logs: ${err.message}`));
this.logs.push(Promise.all(logsPromise));
const args = message.args();
if (args.length > 0) {
const logsPromise = message.args().map(arg => arg
// serialize the log message in the browser to a string
// __wtr_browser_logs__ is injected by a script, but in some cases we're setting it isn't available
// for example for browser native warnings
.evaluateHandle(e => window.__wtr_browser_logs__
? window.__wtr_browser_logs__.serialize(e)
: JSON.stringify(e))
// pass along the message from the browser to NodeJS as a string
.then(handle => handle.jsonValue())
// deserialize the string to an array of logs
.then(str => browser_logs_1.deserialize(str))
.catch(err => `Error while collecting browser logs: ${err.message}`));
this.logs.push(Promise.all(logsPromise));
}
else {
this.logs.push(Promise.resolve([message.text()]));
}
};

@@ -58,3 +77,4 @@ // inject serialization script

]);
return { testCoverage, browserLogs };
const filteredLogs = filterBrowserLogs(browserLogs);
return { testCoverage, browserLogs: filteredLogs };
}

@@ -61,0 +81,0 @@ async collectTestCoverage(config, testFiles) {

{
"name": "@web/test-runner-chrome",
"version": "0.6.4",
"version": "0.6.5",
"publishConfig": {

@@ -5,0 +5,0 @@ "access": "public"

# Web Test Runner Chrome
Browser launcher for `@web/test-runner`. Looks for a locally installed instance of Chrome, and controls it using [puppeteer-core](https://www.npmjs.com/package/puppeteer-core). This avoids the postinstall step of `puppeteer` or `playwright`, speeding up installation of projects.
Browser launcher for web test runner. Looks for a locally installed instance of Chrome, and controls it using [puppeteer-core](https://www.npmjs.com/package/puppeteer-core). This avoids the postinstall step of `puppeteer` or `playwright`, speeding up installation of projects.
If you don't want to install Chrome globally, for example in a CI environment, you can use [@web/test-runner-puppeeteer](https://github.com/modernweb-dev/web/tree/master/packages/test-runner-puppeteer) or [@web/test-runner-playwright](https://github.com/modernweb-dev/web/tree/master/packages/test-runner-playwright)
See [@web/test-runner](https://github.com/modernweb-dev/web/tree/master/packages/test-runner) for a default implementation and CLI for the test runner.
## Usage
If you are using [@web/test-runner](https://github.com/modernweb-dev/web/tree/master/packages/test-runner), the chrome launcher is used by default. You can instantiate it yourself from the config to use on the advanced options.
### Customizing launcher options
If you want to customize the puppeteer launcher options, you can add the browser launcher in the config.
You can find all possible launch options in the [official documentation](https://github.com/microsoft/puppeteer/blob/master/docs/api.md#browsertypelaunchoptions)
```js
const { chromeLauncher } = require('@web/test-runner-chrome');
module.exports = {
browsers: [
chromeLauncher({
launchOptions: {
headless: false,
args: ['--some-flag'],
},
}),
],
};
```
### Customizing page creation
You can use a custom function to create the puppeteer `Page`. You can use this for example to set up injecting scripts for environment variables or to expose functions to the browser to control the page.
```js
const { chromeLauncher } = require('@web/test-runner-chrome');
module.exports = {
browsers: [
chromeLauncher({
async createPage({ browser, config }) {
const page = await browser.newPage();
// expose websocket endpoint as an environment variable in the browser
page.evaluateOnNewDocument(wsEndpoint => {
window.__ENV__ = { wsEndpoint };
}, browser.wsEndpoint());
// expose a function in the browser, which calls a function on the
// puppeteer page in NodeJS
page.exposeFunction('puppeteerBringToFront', () => {
page.bringToFront();
});
return page;
},
}),
],
};
```
See [our website](https://modern-web.dev/docs/test-runner/browsers/chrome/) for full documentation.

@@ -7,2 +7,19 @@ import { Page, ConsoleMessage } from 'puppeteer-core';

// these warnings are generated by mocha
const filteredBrowserWarnings = [
"'window.webkitStorageInfo' is deprecated.",
'onmozfullscreenchange is deprecated.',
'onmozfullscreenerror is deprecated.',
];
function filterBrowserLogs(browserLogs: any[][]) {
return browserLogs.filter(log => {
return !(
log.length === 1 &&
typeof log[0] === 'string' &&
filteredBrowserWarnings.some(warn => log[0].includes(warn))
);
});
}
export class ChromeLauncherPage {

@@ -46,3 +63,5 @@ private nativeInstrumentationEnabledOnPage = false;

]);
return { testCoverage, browserLogs };
const filteredLogs = filterBrowserLogs(browserLogs);
return { testCoverage, browserLogs: filteredLogs };
}

@@ -102,20 +121,24 @@

const logsPromise = message.args().map(arg =>
arg
// serialize the log message in the browser to a string
// __wtr_browser_logs__ is injected by a script, but in some cases we're setting it isn't available
// for example for browser native warnings
.evaluateHandle(e =>
(window as any).__wtr_browser_logs__
? (window as any).__wtr_browser_logs__.serialize(e)
: JSON.stringify(e),
)
// pass along the message from the browser to NodeJS as a string
.then(handle => handle.jsonValue())
// deserialize the string to an array of logs
.then(str => deserialize(str as string))
.catch(err => `Error while collecting browser logs: ${err.message}`),
);
this.logs.push(Promise.all(logsPromise));
const args = message.args();
if (args.length > 0) {
const logsPromise = message.args().map(arg =>
arg
// serialize the log message in the browser to a string
// __wtr_browser_logs__ is injected by a script, but in some cases we're setting it isn't available
// for example for browser native warnings
.evaluateHandle(e =>
(window as any).__wtr_browser_logs__
? (window as any).__wtr_browser_logs__.serialize(e)
: JSON.stringify(e),
)
// pass along the message from the browser to NodeJS as a string
.then(handle => handle.jsonValue())
// deserialize the string to an array of logs
.then(str => deserialize(str as string))
.catch(err => `Error while collecting browser logs: ${err.message}`),
);
this.logs.push(Promise.all(logsPromise));
} else {
this.logs.push(Promise.resolve([message.text()]));
}
};

@@ -122,0 +145,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc