Skip to content

Commit

Permalink
Add blessed Baseline calculation method
Browse files Browse the repository at this point in the history
  • Loading branch information
ddbeck committed Jun 6, 2024
1 parent 74dd497 commit 53fd8ba
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/compute-baseline/src/baseline/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@ import { Temporal } from "@js-temporal/polyfill";
import * as chai from "chai";
import chaiJestSnapshot from "chai-jest-snapshot";

import { computeBaseline, keystoneDateToStatus } from "./index.js";
import { computeBaseline, getStatus, keystoneDateToStatus } from "./index.js";

chai.use(chaiJestSnapshot);

describe("getStatus", function () {
before(function () {
chaiJestSnapshot.resetSnapshotRegistry();
});

beforeEach(function () {
chaiJestSnapshot.configureUsingMochaContext(this);
});

it("returns a status", function () {
const result = getStatus("fetch", "api.Response.json");
assert.equal(result.baseline, "high");
chai.expect(result).to.matchSnapshot();
});
});

describe("computeBaseline", function () {
before(function () {
chaiJestSnapshot.resetSnapshotRegistry();
Expand Down
17 changes: 17 additions & 0 deletions packages/compute-baseline/src/baseline/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,20 @@ Object {
}",
}
`;

exports[`getStatus returns a status 1`] = `
Object {
"baseline": "high",
"baseline_high_date": "2019-09-27",
"baseline_low_date": "2017-03-27",
"support": Object {
"chrome": "42",
"chrome_android": "42",
"edge": "14",
"firefox": "39",
"firefox_android": "39",
"safari": "10.1",
"safari_ios": "10.3",
},
}
`;
26 changes: 26 additions & 0 deletions packages/compute-baseline/src/baseline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ interface SupportStatus {
toJSON: () => string;
}

/**
* Calculate a Baseline status for specific browser compat data keys within a
* web-features feature. Use this method to calculate fine-grained support
* statuses. This is the only method approved to compute Baseline statuses not
* otherwise published in the `web-features` package.
*
* For example, suppose you want to show a Baseline status for a specific method
* in a feature, which might've been supported earlier or later than the broader
* feature overall. Then you'd call `getStatus('example-feature',
* 'api.ExampleManager.doExample')`.
*/
export function getStatus(
featureId: string,
compatKey: string,
compat: Compat = defaultCompat,
) {
// TODO: actually check that featureId is a valid feature
// TODO: actually check that compatKey is tagged as featureId in BCD _or_ listed in web-features
return JSON.parse(
computeBaseline(
{ compatKeys: [compatKey], checkAncestors: true },
compat,
).toJSON(),
);
}

/**
* Given a set of compat keys, compute the aggregate Baseline support ("high",
* "low" or false, dates, and releases) for those keys.
Expand Down

0 comments on commit 53fd8ba

Please sign in to comment.