playwright/utils/testrunner
2020-08-12 22:01:37 -07:00
..
examples Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
test Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
.npmignore Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
diffstyle.css Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
GoldenUtils.js Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
index.js Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
Location.js Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
Matchers.js Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
README.md Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
Reporter.js Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
SourceMap.js Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
SourceMapSupport.js Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
Test.js Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
TestCollector.js Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00
TestRunner.js Revert "chore(test): run doclint tests with mocha, delete utils/testrunner (#3428)" (#3432) 2020-08-12 22:01:37 -07:00

TestRunner

This test runner is used internally by Playwright to test Playwright itself.

  • testrunner is a library: tests are node.js scripts
  • parallel wrt IO operations
  • supports async/await
  • modular
  • well-isolated state per execution thread

Example

Save the following as test.js and run using node:

node test.js
const {TestRunner, Reporter, Matchers} = require('.');

// Runner holds and runs all the tests
const runner = new TestRunner({
  parallel: 2, // run 2 parallel threads
  timeout: 1000, // setup timeout of 1 second per test
});
// Simple expect-like matchers
const {expect} = new Matchers();

// Extract jasmine-like DSL into the global namespace
const {describe, xdescribe, fdescribe} = runner;
const {it, fit, xit} = runner;
const {beforeAll, beforeEach, afterAll, afterEach} = runner;

// Test hooks can be async.
beforeAll(async state => {
  state.parallelIndex; // either 0 or 1 in this example, depending on the executing thread
  state.foo = 'bar'; // set state for every test
});

describe('math', () => {
  it('to be sane', async (state, test) => {
    state.parallelIndex; // Very first test will always be ran by the 0's thread
    state.foo; // this will be 'bar'
    expect(2 + 2).toBe(4);
  });
});

// Reporter subscribes to TestRunner events and displays information in terminal
const reporter = new Reporter(runner);

// Run all tests.
runner.run();