0.2.13 • Published 4 years ago

@web/test-runner-browser-lib v0.2.13

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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,
  sessionFailed,
} 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
    sessionFailed(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, sessionFailed } 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
        sessionFailed(error);
        return;
      }
    </script>
  </body>
</html>

Types

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

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago