Skip to content

Commit

Permalink
Revert "chore(test): run doclint tests with mocha, delete utils/testr…
Browse files Browse the repository at this point in the history
…unner (#3428)" (#3432)
  • Loading branch information
pavelfeldman authored Aug 13, 2020
1 parent 15fa27e commit 51bd370
Show file tree
Hide file tree
Showing 24 changed files with 3,732 additions and 45 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"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 test/runner utils/doclint/check_public_api/test/test.js && node test/runner utils/doclint/preprocessor/test.js",
"test-infra": "node utils/doclint/check_public_api/test/test.js && node 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
2 changes: 1 addition & 1 deletion test/runner/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const path = require('path');
const Mocha = require('mocha');
const { fixturesUI, fixturePool } = require('./fixturesUI');
const { gracefullyCloseAll } = require('../../lib/server/processLauncher');
const GoldenUtils = require('./GoldenUtils');
const GoldenUtils = require('../../utils/testrunner/GoldenUtils');

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

registerWorkerFixture('page', async({}, test) => {
const browser = await playwright.chromium.launch();
const page = await browser.newPage();
await test(page);
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() {
await browser.close();
});

describe('checkPublicAPI', function() {
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');
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);
});

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'));
});
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 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 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 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'));
});
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'));
}

/**
Expand Down
11 changes: 10 additions & 1 deletion utils/doclint/preprocessor/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@
* limitations under the License.
*/

const {runCommands} = require('.');
const {runCommands, ensureTipOfTreeAPILinks} = 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 @@ -195,3 +202,5 @@ describe('runCommands', function() {
});
});

runner.run();

13 changes: 13 additions & 0 deletions utils/testrunner/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# exclude all examples and README.md
examples/
README.md

# repeats from .gitignore
node_modules
.npmignore
.DS_Store
*.swp
*.pyc
.vscode
package-lock.json
yarn.lock
File renamed without changes.
88 changes: 88 additions & 0 deletions utils/testrunner/Location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Copyright 2017 Google Inc. All rights reserved.
* Modifications copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const path = require('path');

// Hack for our own tests.
const testRunnerTestFile = path.join(__dirname, 'test', 'testrunner.spec.js');

class Location {
constructor() {
this._fileName = '';
this._filePath = '';
this._lineNumber = 0;
this._columnNumber = 0;
}

fileName() {
return this._fileName;
}

filePath() {
return this._filePath;
}

lineNumber() {
return this._lineNumber;
}

columnNumber() {
return this._columnNumber;
}

toString() {
return this._fileName + ':' + this._lineNumber;
}

toDetailedString() {
return this._fileName + ':' + this._lineNumber + ':' + this._columnNumber;
}

static getCallerLocation(ignorePrefix = __dirname) {
const error = new Error();
const stackFrames = error.stack.split('\n').slice(1);
const location = new Location();
// Find first stackframe that doesn't point to this file.
for (let frame of stackFrames) {
frame = frame.trim();
if (!frame.startsWith('at '))
return null;
if (frame.endsWith(')')) {
const from = frame.indexOf('(');
frame = frame.substring(from + 1, frame.length - 1);
} else {
frame = frame.substring('at '.length);
}

const match = frame.match(/^(.*):(\d+):(\d+)$/);
if (!match)
return null;
const filePath = match[1];
if (filePath === __filename || (filePath.startsWith(ignorePrefix) && filePath !== testRunnerTestFile))
continue;

location._filePath = filePath;
location._fileName = filePath.split(path.sep).pop();
location._lineNumber = parseInt(match[2], 10);
location._columnNumber = parseInt(match[3], 10);
return location;
}
return location;
}
}

module.exports = Location;
Loading

0 comments on commit 51bd370

Please sign in to comment.