mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
tests: drop jasmine test runner (#1519)
This patch introduces a tiny test runner to run puppeteer tests. The test runner is self-container and allows parallel (wrt IO) test execution. It will also allow us to split tests into multiple files if necessary. Comparing to the jasmine, the testrunner supports parallel execution, properly handles "unhandled promise rejection" event and signals. Comparing to ava/jest, the testrunner doesn't run multiple node processes, which makes it simpler but sufficient for our goals.
This commit is contained in:
@@ -14,8 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const rm = require('rimraf').sync;
|
||||
const path = require('path');
|
||||
const puppeteer = require('../../../..');
|
||||
const checkPublicAPI = require('..');
|
||||
@@ -24,45 +22,48 @@ const mdBuilder = require('../MDBuilder');
|
||||
const jsBuilder = require('../JSBuilder');
|
||||
const GoldenUtils = require('../../../../test/golden-utils');
|
||||
|
||||
const OUTPUT_DIR = path.join(__dirname, 'output');
|
||||
const GOLDEN_DIR = path.join(__dirname, 'golden');
|
||||
const {TestRunner, Reporter, Matchers} = require('../../../testrunner/');
|
||||
const runner = new TestRunner();
|
||||
const reporter = new Reporter(runner);
|
||||
|
||||
const {describe, xdescribe, fdescribe} = runner;
|
||||
const {it, fit, xit} = runner;
|
||||
const {beforeAll, beforeEach, afterAll, afterEach} = runner;
|
||||
|
||||
let browser;
|
||||
let page;
|
||||
let specName;
|
||||
|
||||
jasmine.getEnv().addReporter({
|
||||
specStarted: result => specName = result.description
|
||||
});
|
||||
|
||||
beforeAll(SX(async function() {
|
||||
beforeAll(async function() {
|
||||
browser = await puppeteer.launch({args: ['--no-sandbox']});
|
||||
page = await browser.newPage();
|
||||
if (fs.existsSync(OUTPUT_DIR))
|
||||
rm(OUTPUT_DIR);
|
||||
}));
|
||||
|
||||
afterAll(SX(async function() {
|
||||
await browser.close();
|
||||
}));
|
||||
|
||||
describe('checkPublicAPI', function() {
|
||||
it('diff-classes', SX(testLint));
|
||||
it('diff-methods', SX(testLint));
|
||||
it('diff-properties', SX(testLint));
|
||||
it('diff-arguments', SX(testLint));
|
||||
it('diff-events', SX(testLint));
|
||||
it('check-duplicates', SX(testLint));
|
||||
it('check-sorting', SX(testLint));
|
||||
it('check-returns', SX(testLint));
|
||||
it('js-builder-common', SX(testJSBuilder));
|
||||
it('js-builder-inheritance', SX(testJSBuilder));
|
||||
it('md-builder-common', SX(testMDBuilder));
|
||||
});
|
||||
|
||||
async function testLint() {
|
||||
const dirPath = path.join(__dirname, specName);
|
||||
GoldenUtils.addMatchers(jasmine, dirPath, dirPath);
|
||||
afterAll(async function() {
|
||||
await browser.close();
|
||||
});
|
||||
|
||||
describe('checkPublicAPI', function() {
|
||||
it('diff-classes', testLint);
|
||||
it('diff-methods', testLint);
|
||||
it('diff-properties', testLint);
|
||||
it('diff-arguments', testLint);
|
||||
it('diff-events', testLint);
|
||||
it('check-duplicates', testLint);
|
||||
it('check-sorting', testLint);
|
||||
it('check-returns', testLint);
|
||||
it('js-builder-common', testJSBuilder);
|
||||
it('js-builder-inheritance', testJSBuilder);
|
||||
it('md-builder-common', testMDBuilder);
|
||||
});
|
||||
|
||||
runner.run();
|
||||
|
||||
async function testLint(state, test) {
|
||||
const dirPath = path.join(__dirname, test.name);
|
||||
const {expect} = new Matchers({
|
||||
toBeGolden: GoldenUtils.compare.bind(null, dirPath, dirPath)
|
||||
});
|
||||
|
||||
const factory = new SourceFactory();
|
||||
const mdSources = await factory.readdir(dirPath, '.md');
|
||||
const jsSources = await factory.readdir(dirPath, '.js');
|
||||
@@ -71,18 +72,22 @@ async function testLint() {
|
||||
expect(errors.join('\n')).toBeGolden('result.txt');
|
||||
}
|
||||
|
||||
async function testMDBuilder() {
|
||||
const dirPath = path.join(__dirname, specName);
|
||||
GoldenUtils.addMatchers(jasmine, dirPath, dirPath);
|
||||
async function testMDBuilder(state, test) {
|
||||
const dirPath = path.join(__dirname, test.name);
|
||||
const {expect} = new Matchers({
|
||||
toBeGolden: GoldenUtils.compare.bind(null, dirPath, dirPath)
|
||||
});
|
||||
const factory = new SourceFactory();
|
||||
const sources = await factory.readdir(dirPath, '.md');
|
||||
const {documentation} = await mdBuilder(page, sources);
|
||||
expect(serialize(documentation)).toBeGolden('result.txt');
|
||||
}
|
||||
|
||||
async function testJSBuilder() {
|
||||
const dirPath = path.join(__dirname, specName);
|
||||
GoldenUtils.addMatchers(jasmine, dirPath, dirPath);
|
||||
async function testJSBuilder(state, test) {
|
||||
const dirPath = path.join(__dirname, test.name);
|
||||
const {expect} = new Matchers({
|
||||
toBeGolden: GoldenUtils.compare.bind(null, dirPath, dirPath)
|
||||
});
|
||||
const factory = new SourceFactory();
|
||||
const sources = await factory.readdir(dirPath, '.js');
|
||||
const {documentation} = await jsBuilder(sources);
|
||||
@@ -110,8 +115,3 @@ function serialize(doc) {
|
||||
return JSON.stringify(result, null, 2);
|
||||
}
|
||||
|
||||
// Since Jasmine doesn't like async functions, they should be wrapped
|
||||
// in a SX function.
|
||||
function SX(fun) {
|
||||
return done => Promise.resolve(fun()).then(done).catch(done.fail);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,15 @@ const SourceFactory = require('../SourceFactory');
|
||||
const factory = new SourceFactory();
|
||||
const VERSION = require('../../../package.json').version;
|
||||
|
||||
const {TestRunner, Reporter, Matchers} = require('../../testrunner/');
|
||||
const runner = new TestRunner();
|
||||
new Reporter(runner);
|
||||
|
||||
const {describe, xdescribe, fdescribe} = runner;
|
||||
const {it, fit, xit} = runner;
|
||||
const {beforeAll, beforeEach, afterAll, afterEach} = runner;
|
||||
const {expect} = new Matchers();
|
||||
|
||||
describe('preprocessor', function() {
|
||||
it('should throw for unknown command', function() {
|
||||
const source = factory.createForTest('doc.md', getCommand('unknownCommand()'));
|
||||
@@ -54,6 +63,8 @@ describe('preprocessor', function() {
|
||||
});
|
||||
});
|
||||
|
||||
runner.run();
|
||||
|
||||
function getCommand(name, body = '') {
|
||||
return `<!--gen:${name}-->${body}<!--gen:stop-->`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user