From 41fd4b529ec3418072f3a1639a41f6a5ab987f55 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Mon, 2 Oct 2017 11:37:16 -0700 Subject: [PATCH] chore(doclint): move doclint tests expectations into test folders (#932) This makes for much easier work with doclint tests. --- test/golden-utils.js | 12 +++++++++--- utils/doclint/check_public_api/test/.gitignore | 2 ++ .../{01-class-errors.txt => result.txt} | 0 .../result.txt} | 0 .../result.txt} | 0 .../result.txt} | 0 .../result.txt} | 0 .../06-duplicates.txt => 06-duplicates/result.txt} | 0 .../{golden/07-sorting.txt => 07-sorting/result.txt} | 0 .../{golden/08-return.txt => 08-return/result.txt} | 0 .../check_public_api/test/golden/01-class-errors.txt | 3 --- utils/doclint/check_public_api/test/test.js | 7 ++----- 12 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 utils/doclint/check_public_api/test/.gitignore rename utils/doclint/check_public_api/test/01-class-errors/{01-class-errors.txt => result.txt} (100%) rename utils/doclint/check_public_api/test/{golden/02-method-errors.txt => 02-method-errors/result.txt} (100%) rename utils/doclint/check_public_api/test/{golden/03-property-errors.txt => 03-property-errors/result.txt} (100%) rename utils/doclint/check_public_api/test/{golden/04-bad-arguments.txt => 04-bad-arguments/result.txt} (100%) rename utils/doclint/check_public_api/test/{golden/05-event-errors.txt => 05-event-errors/result.txt} (100%) rename utils/doclint/check_public_api/test/{golden/06-duplicates.txt => 06-duplicates/result.txt} (100%) rename utils/doclint/check_public_api/test/{golden/07-sorting.txt => 07-sorting/result.txt} (100%) rename utils/doclint/check_public_api/test/{golden/08-return.txt => 08-return/result.txt} (100%) delete mode 100644 utils/doclint/check_public_api/test/golden/01-class-errors.txt diff --git a/test/golden-utils.js b/test/golden-utils.js index be920074..096ee526 100644 --- a/test/golden-utils.js +++ b/test/golden-utils.js @@ -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); @@ -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); diff --git a/utils/doclint/check_public_api/test/.gitignore b/utils/doclint/check_public_api/test/.gitignore new file mode 100644 index 00000000..17526b11 --- /dev/null +++ b/utils/doclint/check_public_api/test/.gitignore @@ -0,0 +1,2 @@ +result-actual.txt +result-diff.html diff --git a/utils/doclint/check_public_api/test/01-class-errors/01-class-errors.txt b/utils/doclint/check_public_api/test/01-class-errors/result.txt similarity index 100% rename from utils/doclint/check_public_api/test/01-class-errors/01-class-errors.txt rename to utils/doclint/check_public_api/test/01-class-errors/result.txt diff --git a/utils/doclint/check_public_api/test/golden/02-method-errors.txt b/utils/doclint/check_public_api/test/02-method-errors/result.txt similarity index 100% rename from utils/doclint/check_public_api/test/golden/02-method-errors.txt rename to utils/doclint/check_public_api/test/02-method-errors/result.txt diff --git a/utils/doclint/check_public_api/test/golden/03-property-errors.txt b/utils/doclint/check_public_api/test/03-property-errors/result.txt similarity index 100% rename from utils/doclint/check_public_api/test/golden/03-property-errors.txt rename to utils/doclint/check_public_api/test/03-property-errors/result.txt diff --git a/utils/doclint/check_public_api/test/golden/04-bad-arguments.txt b/utils/doclint/check_public_api/test/04-bad-arguments/result.txt similarity index 100% rename from utils/doclint/check_public_api/test/golden/04-bad-arguments.txt rename to utils/doclint/check_public_api/test/04-bad-arguments/result.txt diff --git a/utils/doclint/check_public_api/test/golden/05-event-errors.txt b/utils/doclint/check_public_api/test/05-event-errors/result.txt similarity index 100% rename from utils/doclint/check_public_api/test/golden/05-event-errors.txt rename to utils/doclint/check_public_api/test/05-event-errors/result.txt diff --git a/utils/doclint/check_public_api/test/golden/06-duplicates.txt b/utils/doclint/check_public_api/test/06-duplicates/result.txt similarity index 100% rename from utils/doclint/check_public_api/test/golden/06-duplicates.txt rename to utils/doclint/check_public_api/test/06-duplicates/result.txt diff --git a/utils/doclint/check_public_api/test/golden/07-sorting.txt b/utils/doclint/check_public_api/test/07-sorting/result.txt similarity index 100% rename from utils/doclint/check_public_api/test/golden/07-sorting.txt rename to utils/doclint/check_public_api/test/07-sorting/result.txt diff --git a/utils/doclint/check_public_api/test/golden/08-return.txt b/utils/doclint/check_public_api/test/08-return/result.txt similarity index 100% rename from utils/doclint/check_public_api/test/golden/08-return.txt rename to utils/doclint/check_public_api/test/08-return/result.txt diff --git a/utils/doclint/check_public_api/test/golden/01-class-errors.txt b/utils/doclint/check_public_api/test/golden/01-class-errors.txt deleted file mode 100644 index 2852a437..00000000 --- a/utils/doclint/check_public_api/test/golden/01-class-errors.txt +++ /dev/null @@ -1,3 +0,0 @@ -[MarkDown] Non-existing class found: Bar -[MarkDown] Non-existing class found: Baz -[MarkDown] Class not found: Other \ No newline at end of file diff --git a/utils/doclint/check_public_api/test/test.js b/utils/doclint/check_public_api/test/test.js index 744c8fd7..9457d41d 100644 --- a/utils/doclint/check_public_api/test/test.js +++ b/utils/doclint/check_public_api/test/test.js @@ -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)); @@ -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