puppeteer/utils/testrunner
Andrey Lushnikov 852c46c1e4
feat(testrunner): async suite descriptions (#4721)
This patch teaches TestRunner to support async suite
descriptions. This is needed to require tests using ES6 dynamic
imports:

```js
const t = new TestRunner();

await t.describe('tests', async () => {
  (await import('./some.spec.js')).addTests(t);
  (await import('./other.spec.js')).addTests(t);
});
```
2019-07-18 11:25:06 -07:00
..
examples chore: testrunner's ".not" should print appropriate message (#2459) 2018-04-26 11:13:22 -07:00
.npmignore chore: add .npmignore for testrunner (#3290) 2018-09-21 17:27:10 -07:00
index.js tests: drop jasmine test runner (#1519) 2017-12-07 16:37:22 -08:00
LICENSE chore: prepare testrunner to be published to npm (#3289) 2018-09-21 14:51:22 -07:00
Matchers.js chore(testrunner): newline for toEqual matcher (#3959) 2019-02-08 16:18:45 -08:00
Multimap.js tests: drop jasmine test runner (#1519) 2017-12-07 16:37:22 -08:00
package.json chore: release next testrunner (#4697) 2019-07-12 12:50:48 -07:00
README.md chore(testrunner): fix readme description (#3293) 2018-09-21 20:44:43 -07:00
Reporter.js fix(testreporter): Test Reporter should not terminate node.js process (#4716) 2019-07-16 16:34:41 -07:00
TestRunner.js feat(testrunner): async suite descriptions (#4721) 2019-07-18 11:25:06 -07:00

TestRunner

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

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

Installation

npm install --save-dev @pptr/testrunner

Example

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

node test.js
const {TestRunner, Reporter, Matchers} = require('@pptr/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;

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