Skip to content

Commit

Permalink
Fix Baseline calculation when support was added then removed
Browse files Browse the repository at this point in the history
  • Loading branch information
ddbeck committed Apr 15, 2024
1 parent 1674f3a commit c6e092a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 deletions.
29 changes: 26 additions & 3 deletions packages/compute-baseline/src/baseline/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,40 @@ describe("computeBaseline", function () {
});

it("finds discrepancies with ancestors (checkAncestors)", function () {
const compatKeys: [string, ...string[]] = ["api.Notification.body"];
const result = computeBaseline({ compatKeys, checkAncestors: false });
const result = computeBaseline({
compatKeys: ["api.Notification.body"],
checkAncestors: false,
});
const resultExplicit = computeBaseline({
compatKeys: ["api.Notification", "api.Notification.body"],
checkAncestors: false,
});
const resultWithAncestors = computeBaseline({
compatKeys,
compatKeys: ["api.Notification.body"],
checkAncestors: true,
});

assert.equal(resultExplicit.toJSON(), resultWithAncestors.toJSON());
assert.notEqual(result.toJSON(), resultWithAncestors.toJSON());

assert.notEqual(result.baseline, resultWithAncestors.baseline);
assert.notEqual(
result.baseline_low_date?.toString(),
resultWithAncestors.baseline_low_date?.toString(),
);

chai.expect(result).to.matchSnapshot();
chai.expect(resultExplicit).to.matchSnapshot();
chai.expect(resultWithAncestors).to.matchSnapshot();
});

it("disregards support that's been removed", function () {
const result = computeBaseline({
compatKeys: ["api.AudioTrack"],
checkAncestors: false,
});
chai.expect(result).to.matchSnapshot();
assert.notEqual(Boolean(result.baseline), true);
});
});

Expand Down
51 changes: 51 additions & 0 deletions packages/compute-baseline/src/baseline/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`computeBaseline disregards support that's been removed 1`] = `
"{
\\"baseline\\": false,
\\"support\\": {}
}"
`;

exports[`computeBaseline finds discrepancies with ancestors (checkAncestors) 1`] = `
"{
\\"baseline\\": \\"low\\",
\\"baseline_low_date\\": \\"2023-03-27\\",
\\"support\\": {
\\"chrome\\": \\"33\\",
\\"chrome_android\\": \\"42\\",
\\"edge\\": \\"14\\",
\\"firefox\\": \\"26\\",
\\"firefox_android\\": \\"26\\",
\\"safari\\": \\"11\\",
\\"safari_ios\\": \\"16.4\\"
}
}"
`;

exports[`computeBaseline finds discrepancies with ancestors (checkAncestors) 2`] = `
"{
\\"baseline\\": false,
\\"support\\": {
\\"chrome\\": \\"33\\",
\\"edge\\": \\"14\\",
\\"firefox\\": \\"26\\",
\\"firefox_android\\": \\"26\\",
\\"safari\\": \\"11\\",
\\"safari_ios\\": \\"16.4\\"
}
}"
`;

exports[`computeBaseline finds discrepancies with ancestors (checkAncestors) 3`] = `
"{
\\"baseline\\": false,
\\"support\\": {
\\"chrome\\": \\"33\\",
\\"edge\\": \\"14\\",
\\"firefox\\": \\"26\\",
\\"firefox_android\\": \\"26\\",
\\"safari\\": \\"11\\",
\\"safari_ios\\": \\"16.4\\"
}
}"
`;

exports[`computeBaseline returns something sensible for the least complex features 1`] = `
Object {
"css.properties.counter-reset.reset_does_not_affect_siblings": "{
Expand Down
9 changes: 7 additions & 2 deletions packages/compute-baseline/src/baseline/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ export function support(feature: Feature, browsers: Browser[]): Support {
}
}

logReleaseOmissions(feature, qualifiedReleases, unqualifiedReleases);
const currentlySupported = unqualifiedReleases.includes(b.current());
if (currentlySupported) {
support.set(b, lastInitialRelease(unqualifiedReleases));
} else {
support.set(b, undefined);
}

support.set(b, lastInitialRelease(unqualifiedReleases));
logReleaseOmissions(feature, qualifiedReleases, unqualifiedReleases);
}

return support;
Expand Down

0 comments on commit c6e092a

Please sign in to comment.