Skip to content

Commit

Permalink
chore(doclint): move doclint tests expectations into test folders (#932)
Browse files Browse the repository at this point in the history
This makes for much easier work with doclint tests.
  • Loading branch information
aslushnikov committed Oct 2, 2017
1 parent f9640a5 commit 41fd4b5
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 11 deletions.
12 changes: 9 additions & 3 deletions test/golden-utils.js
Expand Up @@ -85,6 +85,8 @@ function compareText(actual, expectedBuffer) {
* @return {!{pass: boolean, message: (undefined|string)}}
*/
function compare(goldenPath, outputPath, actual, goldenName) {
goldenPath = path.normalize(goldenPath);
outputPath = path.normalize(outputPath);
const expectedPath = path.join(goldenPath, goldenName);
const actualPath = path.join(outputPath, goldenName);

Expand All @@ -110,9 +112,13 @@ function compare(goldenPath, outputPath, actual, goldenName) {
if (!result)
return { pass: true };
ensureOutputDir();
fs.writeFileSync(actualPath, actual);
// Copy expected to the output/ folder for convenience.
fs.writeFileSync(addSuffix(actualPath, '-expected'), expected);
if (goldenPath === outputPath) {
fs.writeFileSync(addSuffix(actualPath, '-actual'), actual);
} else {
fs.writeFileSync(actualPath, actual);
// Copy expected to the output/ folder for convenience.
fs.writeFileSync(addSuffix(actualPath, '-expected'), expected);
}
if (result.diff) {
const diffPath = addSuffix(actualPath, '-diff', result.diffExtension);
fs.writeFileSync(diffPath, result.diff);
Expand Down
2 changes: 2 additions & 0 deletions utils/doclint/check_public_api/test/.gitignore
@@ -0,0 +1,2 @@
result-actual.txt
result-diff.html

This file was deleted.

7 changes: 2 additions & 5 deletions utils/doclint/check_public_api/test/test.js
Expand Up @@ -44,10 +44,6 @@ afterAll(SX(async function() {
await browser.close();
}));

beforeEach(function() {
GoldenUtils.addMatchers(jasmine, GOLDEN_DIR, OUTPUT_DIR);
});

describe('checkPublicAPI', function() {
it('01-class-errors', SX(test));
it('02-method-errors', SX(test));
Expand All @@ -61,12 +57,13 @@ describe('checkPublicAPI', function() {

async function test() {
const dirPath = path.join(__dirname, specName);
GoldenUtils.addMatchers(jasmine, dirPath, dirPath);
const factory = new SourceFactory();
const mdSources = await factory.readdir(dirPath, '.md');
const jsSources = await factory.readdir(dirPath, '.js');
const messages = await checkPublicAPI(page, mdSources, jsSources);
const errors = messages.map(message => message.text);
expect(errors.join('\n')).toBeGolden(specName + '.txt');
expect(errors.join('\n')).toBeGolden('result.txt');
}

// Since Jasmine doesn't like async functions, they should be wrapped
Expand Down

0 comments on commit 41fd4b5

Please sign in to comment.