Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bazel/api-golden/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ts_project(
deps = [
"//bazel:node_modules/@microsoft/api-extractor",
"//bazel:node_modules/@types/node",
"//bazel:node_modules/diff",
"//bazel:node_modules/piscina",
"//bazel:node_modules/typescript",
],
Expand Down
20 changes: 17 additions & 3 deletions bazel/api-golden/index_npm_packages.cts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {testApiGolden} from './test_api_report.js';
import * as fs from 'fs';
import {Piscina} from 'piscina';
import {styleText} from 'util';
import {createPatch} from 'diff';

/** Interface describing contents of a `package.json`. */
export interface PackageJson {
Expand Down Expand Up @@ -89,15 +90,16 @@ async function main(
const expected = await fs.promises.readFile(goldenFilePath, 'utf8');
if (actual !== expected) {
// Keep track of outdated goldens for error message.
outdatedGoldens.push(goldenName);
const patch = createPatch(goldenName, expected, actual);
outdatedGoldens.push({name: goldenName, diff: patch});
return false;
}
}

return true;
};

const outdatedGoldens: string[] = [];
const outdatedGoldens: {name: string; diff: string}[] = [];
const tasks: Promise<boolean>[] = [];
// Process in batches. Otherwise we risk out of memory errors.
const batchSize = 10;
Expand All @@ -122,16 +124,28 @@ async function main(
console.error(Array(80).fill('=').join(''));
console.error(`${Array(35).fill('=').join('')} RESULTS ${Array(36).fill('=').join('')}`);
console.error(Array(80).fill('=').join(''));

if (singleFileMode) {
console.error(red(`Diff:`));
console.error(outdatedGoldens[0].diff);
console.info();
Comment thread
clydin marked this conversation as resolved.
console.error(
red(
`The golden is out of date and can be updated by running:\n - bazel run ${process.env.TEST_TARGET}.accept`,
),
);
} else {
console.error(red(`The following goldens are outdated:`));
outdatedGoldens.forEach((name) => console.info(`- ${name}`));
outdatedGoldens.forEach(({name}) => console.info(`- ${name}`));
console.info();
Comment thread
clydin marked this conversation as resolved.

console.error(red(`Diffs:`));
outdatedGoldens.forEach(({name, diff}) => {
console.error(`\n--- Diff for ${name} ---`);
console.error(diff);
});
console.info();
Comment thread
clydin marked this conversation as resolved.

console.info(
yellow(
`The goldens can be updated by running:\n - bazel run ${process.env.TEST_TARGET}.accept`,
Expand Down
1 change: 1 addition & 0 deletions bazel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@devinfra/bazel",
"dependencies": {
"@microsoft/api-extractor": "7.58.2",
"diff": "^9.0.0",
"@types/babel__core": "7.20.5",
"@types/browser-sync": "2.29.1",
"@types/node": "24.12.2",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading