Skip to content

Commit

Permalink
chore(test): run doclint tests with mocha, delete testrunner again (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelEinbinder committed Aug 13, 2020
1 parent e2cfb05 commit 84441f8
Show file tree
Hide file tree
Showing 24 changed files with 47 additions and 3,734 deletions.
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -18,9 +18,8 @@
"tsc-installer": "tsc -p ./src/install/tsconfig.json",
"doc": "node utils/doclint/cli.js",
"doc-no-channel": "node utils/doclint/cli.js --no-channel",
"test-infra": "node utils/doclint/check_public_api/test/test.js && node utils/doclint/preprocessor/test.js",
"test-infra": "node test/runner utils/doclint/check_public_api/test/test.js && node test/runner utils/doclint/preprocessor/test.js",
"lint": "npm run eslint && npm run tsc && npm run doc && npm run doc-no-channel && npm run check-deps && npm run generate-channels && npm run test-types && npm run test-infra",
"debug-test": "node --inspect-brk test/test.js",
"clean": "rimraf lib && rimraf types",
"prepare": "node install-from-github.js",
"build": "node utils/runWebpack.js --mode='development' && tsc -p . && npm run generate-types",
Expand Down
Expand Up @@ -92,8 +92,8 @@ function compare(actual, golden) {
const goldenPath = path.normalize(golden.goldenPath);
const outputPath = path.normalize(golden.outputPath);
const goldenName = golden.goldenName;
const expectedPath = path.join(goldenPath, goldenName);
const actualPath = path.join(outputPath, goldenName);
const expectedPath = path.resolve(goldenPath, goldenName);
const actualPath = path.resolve(outputPath, goldenName);

const messageSuffix = 'Output is saved in "' + path.basename(outputPath + '" directory');

Expand Down
2 changes: 1 addition & 1 deletion test/runner/worker.js
Expand Up @@ -19,7 +19,7 @@ const Mocha = require('mocha');
const { registerWorkerFixture } = require('./fixturePool');
const { fixturesUI, fixturePool } = require('./fixturesUI');
const { gracefullyCloseAll } = require('../../lib/server/processLauncher');
const GoldenUtils = require('../../utils/testrunner/GoldenUtils');
const GoldenUtils = require('./GoldenUtils');

const browserName = process.env.BROWSER || 'chromium';
const goldenPath = path.join(__dirname, '..', 'golden-' + browserName);
Expand Down
96 changes: 42 additions & 54 deletions utils/doclint/check_public_api/test/test.js
Expand Up @@ -21,70 +21,58 @@ const Source = require('../../Source');
const mdBuilder = require('../MDBuilder');
const jsBuilder = require('../JSBuilder');

const TestRunner = require('../../../testrunner/');
const runner = new TestRunner({
goldenPath: __dirname,
outputPath: __dirname
});

const {describe, xdescribe, fdescribe} = runner.api();
const {it, fit, xit} = runner.api();
const {beforeAll, beforeEach, afterAll, afterEach} = runner.api();
const {expect} = runner.api();

let browser;
let page;

beforeAll(async function() {
browser = await playwright.chromium.launch();
page = await browser.newPage();
});

afterAll(async function() {
registerWorkerFixture('page', async({}, test) => {
const browser = await playwright.chromium.launch();
const page = await browser.newPage();
await test(page);
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('check-nullish', testLint);
it('js-builder-common', testJSBuilder);
it('js-builder-inheritance', testJSBuilder);
it('md-builder-common', testMDBuilder);
it('md-builder-comments', testMDBuilder);
testLint('diff-classes');
testLint('diff-methods');
testLint('diff-properties');
testLint('diff-arguments');
testLint('diff-events');
testLint('check-duplicates');
testLint('check-sorting');
testLint('check-returns');
testLint('check-nullish');
testJSBuilder('js-builder-common');
testJSBuilder('js-builder-inheritance');
testMDBuilder('md-builder-common');
testMDBuilder('md-builder-comments');
});

runner.run();

async function testLint(state, testRun) {
const dirPath = path.join(__dirname, testRun.test().name());
const mdSources = await Source.readdir(dirPath, '.md');
const tsSources = await Source.readdir(dirPath, '.ts');
const jsSources = await Source.readdir(dirPath, '.js');
const messages = await checkPublicAPI(page, mdSources, jsSources.concat(tsSources));
const errors = messages.map(message => message.text);
expect(errors.join('\n')).toBeGolden(path.join(testRun.test().name(), 'result.txt'));
async function testLint(name) {
it(name, async({page}) => {
const dirPath = path.join(__dirname, name);
const mdSources = await Source.readdir(dirPath, '.md');
const tsSources = await Source.readdir(dirPath, '.ts');
const jsSources = await Source.readdir(dirPath, '.js');
const messages = await checkPublicAPI(page, mdSources, jsSources.concat(tsSources));
const errors = messages.map(message => message.text);
expect(errors.join('\n')).toBeGolden(path.join(dirPath, 'result.txt'));
});
}

async function testMDBuilder(state, testRun) {
const dirPath = path.join(__dirname, testRun.test().name());
const sources = await Source.readdir(dirPath, '.md');
const {documentation} = await mdBuilder(page, sources);
expect(serialize(documentation)).toBeGolden(path.join(testRun.test().name(), 'result.txt'));
async function testMDBuilder(name) {
it(name, async({page}) => {
const dirPath = path.join(__dirname, name);
const sources = await Source.readdir(dirPath, '.md');
const {documentation} = await mdBuilder(page, sources);
expect(serialize(documentation)).toBeGolden(path.join(dirPath, 'result.txt'));
});
}

async function testJSBuilder(state, testRun) {
const dirPath = path.join(__dirname, testRun.test().name());
const jsSources = await Source.readdir(dirPath, '.js');
const tsSources = await Source.readdir(dirPath, '.ts');
const {documentation} = await jsBuilder.checkSources(jsSources.concat(tsSources));
expect(serialize(documentation)).toBeGolden(path.join(testRun.test().name(), 'result.txt'));
async function testJSBuilder(name) {
it(name, async() => {
const dirPath = path.join(__dirname, name);
const jsSources = await Source.readdir(dirPath, '.js');
const tsSources = await Source.readdir(dirPath, '.ts');
const {documentation} = await jsBuilder.checkSources(jsSources.concat(tsSources));
expect(serialize(documentation)).toBeGolden(path.join(dirPath, 'result.txt'));
});
}

/**
Expand Down
11 changes: 1 addition & 10 deletions utils/doclint/preprocessor/test.js
Expand Up @@ -14,15 +14,8 @@
* limitations under the License.
*/

const {runCommands, ensureTipOfTreeAPILinks} = require('.');
const {runCommands} = require('.');
const Source = require('../Source');
const TestRunner = require('../../testrunner/');
const runner = new TestRunner();

const {describe, xdescribe, fdescribe} = runner.api();
const {it, fit, xit} = runner.api();
const {beforeAll, beforeEach, afterAll, afterEach} = runner.api();
const {expect} = runner.api();

describe('runCommands', function() {
const OPTIONS_REL = {
Expand Down Expand Up @@ -202,5 +195,3 @@ describe('runCommands', function() {
});
});

runner.run();

13 changes: 0 additions & 13 deletions utils/testrunner/.npmignore

This file was deleted.

88 changes: 0 additions & 88 deletions utils/testrunner/Location.js

This file was deleted.

0 comments on commit 84441f8

Please sign in to comment.