Skip to content

Commit

Permalink
Silences warning logs and adds additional earlier skip check if no de…
Browse files Browse the repository at this point in the history
…tected BCD updates (#909)
  • Loading branch information
ChrisC authored Dec 14, 2023
1 parent 291479e commit 82add35
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 6 deletions.
145 changes: 145 additions & 0 deletions scripts/update-bcd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
findEntry,
getSupportMap,
getSupportMatrix,
hasSupportUpdates,
inferSupportStatements,
splitRange,
update,
Expand Down Expand Up @@ -825,6 +826,150 @@ describe("BCD updater", () => {
});
});

describe("hasSupportUpdates", () => {
it("detects updates with nonexistent support statements", () => {
assert.isTrue(
hasSupportUpdates(new Map([["80", true]]), {
version_added: null,
}),
);

assert.isTrue(hasSupportUpdates(new Map([["80", true]]), undefined));
});

it("skips null support claims", () => {
assert.isFalse(
hasSupportUpdates(new Map([["80", null]]), {
version_added: "≤80",
}),
);

assert.isFalse(
hasSupportUpdates(
new Map([
["79", false],
["80", true],
["81", true],
["82", null],
]),
{
version_added: "≤80",
},
),
"skips new null test result",
);
});

it("detects updates in statements with boolean values", () => {
assert.isFalse(
hasSupportUpdates(new Map([["80", false]]), {
version_added: false,
}),
"skips generic false statements",
);

assert.isTrue(
hasSupportUpdates(new Map([["80", true]]), {
version_added: true,
}),
"catches specific support updates over generic true statements",
);

assert.isTrue(
hasSupportUpdates(
new Map([
["80", false],
["81", true],
]),
{version_added: false},
),
);
});

it("detects updates in statements with string values", () => {
assert.isTrue(
hasSupportUpdates(
new Map([
["79", false],
["80", false],
["81", true],
]),
{
version_added: "≤80",
},
),
);

assert.isFalse(
hasSupportUpdates(
new Map([
["79", false],
["80", false],
["81", true],
]),
{
version_added: "81",
},
),
);

assert.isFalse(
hasSupportUpdates(
new Map([
["79", false],
["80", true],
["81", true],
]),
{
version_added: "≤80",
},
),
);

assert.isTrue(
hasSupportUpdates(
new Map([
["79", false],
["80", true],
["81", true],
["82", false],
]),
{
version_added: "≤80",
},
),
"detects possible support removal",
);

assert.isTrue(
hasSupportUpdates(
new Map([
["79", false],
["80", true],
["81", true],
]),
{
version_added: "preview",
},
),
);
});

it("detects updates for preview statements", () => {
assert.isTrue(
hasSupportUpdates(new Map([["81", true]]), {
version_added: "preview",
}),
);

assert.isFalse(
hasSupportUpdates(new Map([["81", false]]), {
version_added: "preview",
}),
);
});
});

describe("update", () => {
const supportMatrix = getSupportMatrix(reports, bcd.browsers, overrides);
let bcdCopy;
Expand Down
83 changes: 77 additions & 6 deletions scripts/update-bcd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,12 @@ const reason = (
message: ReasonMessageFactory,
args: Omit<Reason, "message"> = {},
): ReasonFactory => {
return (value) => ({message: message(value), skip: true, ...args});
return (value) => ({
message: message(value),
skip: true,
quiet: true,
...args,
});
};

/**
Expand Down Expand Up @@ -803,6 +808,48 @@ const skipCurrentBeforeSupport = skip("currentBeforeSupport", ({
}
});

export const hasSupportUpdates = (
versionMap: BrowserSupportMap,
simpleStatement?: SimpleSupportStatement,
) => {
if (!simpleStatement || simpleStatement.version_added === null) {
return true;
}

const updates: string[] = [];
for (const [version, hasSupport] of versionMap.entries()) {
if (hasSupport === null) {
continue;
}

if (typeof simpleStatement.version_added === "boolean") {
if (!simpleStatement.version_added && !hasSupport) {
continue;
} else {
updates.push(version);
}
}

if (typeof simpleStatement.version_added === "string") {
if (simpleStatement.version_added === "preview") {
if (hasSupport) {
updates.push(version);
}
continue;
}

const simpleAdded = simpleStatement.version_added.replace("≤", "");
if (compareVersions(version, simpleAdded, "<") && hasSupport) {
updates.push(version);
}
if (compareVersions(version, simpleAdded, ">=") && !hasSupport) {
updates.push(version);
}
}
}
return updates.length > 0;
};

const persistInferredRange = provideStatements(
"inferredRange",
({
Expand Down Expand Up @@ -1072,6 +1119,19 @@ export const update = (
}
}),
skipBrowserMismatch(options.browser),
provideAllStatements,
provideDefaultStatements,
skip("supportMatrixMatchesDefaultStatements", ({
shared: {versionMap},
defaultStatements: [simpleStatement],
}) => {
if (!hasSupportUpdates(versionMap, simpleStatement)) {
return reason(
({path, browser}) =>
`$${path} skipped for ${browser} because support matrix matches current BCD support data`,
);
}
}),
provide("inferredStatements", ({shared: {versionMap}}) =>
inferSupportStatements(versionMap),
),
Expand All @@ -1084,8 +1144,6 @@ export const update = (
}
}),
skipReleaseMismatch(options.release),
provideAllStatements,
provideDefaultStatements,
skip("zeroDefaultStatements", ({
inferredStatements: [inferredStatement],
defaultStatements,
Expand Down Expand Up @@ -1124,13 +1182,26 @@ export const update = (
persistAddedOver,
persistRemoved,
clearNonExact(options.exactOnly),
skip("noStatement", ({statements}) => {
skip("noStatement", ({
statements,
defaultStatements: [simpleStatement],
shared: {versionMap},
}) => {
if (!statements?.length) {
if (hasSupportUpdates(versionMap, simpleStatement)) {
return reason(
({browser, path}) =>
`${path} skipped for ${browser} with unresolved differences between support matrix and BCD data. Possible intervention required.`,
{
quiet: false,
},
);
}
return reason(
({browser, path}) =>
`${path} skipped for ${browser}: no reason identified`,
`${path} skipped for ${browser}: no known reason identified. Possible intervention required.`,
{
quiet: true,
quiet: false,
},
);
}
Expand Down

0 comments on commit 82add35

Please sign in to comment.