puppeteer/utils/testrunner
Andrey Lushnikov 0b94fa70eb
chore: stop using console.assert everywhere (#2646)
Since Node 10, `console.assert` no longer throws an AssertionError.
(This is generally good since it aligns Node.js with Browsers.)

This patch migrates all usages of `console.assert` in our codebase.
- All the `lib/` and testing code is migrated onto a handmade `assert`
function. This is to make Puppeteer transpilation / bundling easier.
- All the tooling is switched to use Node's `assert` module.

Fixes #2547.
2018-05-31 16:53:51 -07:00
..
examples chore: testrunner's ".not" should print appropriate message (#2459) 2018-04-26 11:13:22 -07:00
index.js tests: drop jasmine test runner (#1519) 2017-12-07 16:37:22 -08:00
Matchers.js chore: stop using console.assert everywhere (#2646) 2018-05-31 16:53:51 -07:00
Multimap.js tests: drop jasmine test runner (#1519) 2017-12-07 16:37:22 -08:00
README.md chore(testrunner): fix typo in readme 2018-04-10 12:25:14 -07:00
Reporter.js feat(test): enable dumpio in tests #2610 2018-05-29 15:45:03 -07:00
TestRunner.js chore: stop using console.assert everywhere (#2646) 2018-05-31 16:53:51 -07: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.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();