Environment ‐ Browsers - uhop/tape-six GitHub Wiki
The tape-six
tests can be run in a browser using a web server. A server can be something like nginx
or Apache
. Or you can use tape6-server
to serve a project directory as root. See other command line environments for how to run the server.
Example:
tape6-server --trace
See notes on how to run tape6-server
in different environments:
tape6-server
will serve the web application that executes tests and shows results. Just navigate
to (the typical location): http://localhost:3000/
Don't forget to set up the importmap
to specify paths used by your tests.
See Set-up tests for details.
Individual tests can be run using a shim HTML and a web server (e.g., tape6-server
).
Example of a shim located at /tests/web/test-simple.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Tape-six tests</title>
<script type="importmap">
{
"imports": {
"tape-six": "/node_modules/tape-six/index.js",
"tape-six/": "/node_modules/tape-six/src/"
}
}
</script>
<script type="module" src="../manual/test-three-tests.js"></script>
<!-- <script type="module" src="/tests/test-sample.js"></script> -->
<!-- could be more tests scripts -->
</head>
<body>
<h1>Tape-six tests</h1>
<p>See the console.</p>
</body>
</html>
The results can be viewed in the browser console. If you used localhost:3000
as the host,
it can be reached at http://localhost:3000/tests/web/test-simple.html
Puppeteer is a browser automation library. It can be used to run individual tests in a browser using a command-line interface. If you want to use it, you need to install Puppeteer.
Example of a Puppeteer script for the previous test, which 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/web/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.