puppeteer/utils/testrunner
Andrey Lushnikov be438c59c1
chore(testrunner): support first-class test debugging (#1606)
This patch teaches testrunner to override both timeout and
parallel execution option if there's attached inspector.
2017-12-15 14:25:06 -08:00
..
examples test: nicer matchers output (#1605) 2017-12-15 14:14:27 -08:00
index.js tests: drop jasmine test runner (#1519) 2017-12-07 16:37:22 -08:00
Matchers.js test: nicer matchers output (#1605) 2017-12-15 14:14:27 -08:00
Multimap.js tests: drop jasmine test runner (#1519) 2017-12-07 16:37:22 -08:00
README.md test: migrate test.js to support concurrent test execution (#1531) 2017-12-12 13:34:21 -08:00
Reporter.js tests: drop jasmine test runner (#1519) 2017-12-07 16:37:22 -08:00
TestRunner.js chore(testrunner): support first-class test debugging (#1606) 2017-12-15 14:25:06 -08:00

TestRunner

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

Example

const {TestRunner, Reporter, Matchers} = require('../utils/testrunner');

// 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;

beforeAll(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.parallel; // 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();