JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q13193F
  • License MIT

Browser library for Web Test Runner

Package Exports

  • @web/test-runner-browser-lib

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@web/test-runner-browser-lib) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Test Runner Browser Lib

Browser library to communicate with the test runner.

See @web/test-runner for a default implementation and CLI for the test runner.

Usage

For a simple setup, you can use this library directly in your project and avoid using a testing framework.

You can also use this as a wrapper around an existing testing framework. To kick off the test execution and report the results back. See @web/test-runner-mocha as an example of that.

JS tests

This is a simple example implementation for JS tests:

import {
  getConfig,
  sessionStarted,
  sessionFinished,
  sessionError,
} from '@web/test-runner-browser-lib';

(async () => {
  // notify the test runner that we're alive
  sessionStarted();

  // fetch the config for this test run
  const { testFile, debug } = await getConfig();
  const failedImports = [];

  // load the test file, catching errors
  await import(new URL(testFile, document.baseURI).href).catch(error => {
    failedImports.push({ file: testFile, error: { message: error.message, stack: error.stack } });
  });

  try {
    // run the actual tests, this is what you will implement
    const testResults = await runTests();

    // notify tests run finished
    sessionFinished({
      passed: failedImports.length === 0 && testResults.passed,
      failedImports,
      tests: testResults,
    });
  } catch (error) {
    // notify an error occurred
    sessionError(error);
    return;
  }
})();

HTML tests

If you want to use this library directly in a HTML test, you can do something like this:

<html>
  <body>
    <script type="module">
      import { sessionStarted, sessionFinished, sessionError } from '@web/test-runner-browser-lib';
      try {
        // notify the test runner that we're alive
        sessionStarted();

        // run the actual tests, this is what you will implement
        const testResults = await runTests();

        // notify tests run finished
        sessionFinished({
          passed: testResults.passed,
          failedImports,
          tests: testResults,
        });
      } catch (error) {
        // notify an error occurred
        sessionError(error);
        return;
      }
    </script>
  </body>
</html>

Types

Check out the type declarations for the full interface of the test results.