Environment ‐ Puppeteer - uhop/tape-six GitHub Wiki

This environment is based on Environment - browsers. Read it first to learn how to run a server and write tests.

Puppeteer

Puppeteer is a browser automation library. It can run individual tests in a browser using a command-line interface.

For automated testing, consider the dedicated package: tape-six-puppeteer.

Example of a custom Puppeteer script for the test shown in Environment - browsers (it assumes that the server is running at http://localhost:3000):

import process from 'node:process';
import puppeteer from 'puppeteer';

const main = async () => {
  const browser = await puppeteer.launch({headless: true, args: ['--no-sandbox']});
  const page = await browser.newPage();

  page.on('console', msg =>
    console[typeof console[msg.type()] == 'function' ? msg.type() : 'log'](msg.text())
  );
  page.on('error', e => console.error(e));

  await page.exposeFunction('__tape6_reportResults', async text => {
    await browser.close();
    switch (text) {
      case 'success':
        process.exit(0);
        break;
      case 'failure':
        process.exit(1);
        break;
    }
  });

  await page.goto('http://localhost:3000/tests/browser/test-simple.html?flags=M');
};

main().then(
  () => console.log('Done.'),
  error => console.error('ERROR:', error)
);

Running the above script with Node will produce results in the console.