-
Notifications
You must be signed in to change notification settings - Fork 199
compute-baseline: add method to expand a support statement into per-release support information
#1312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compute-baseline: add method to expand a support statement into per-release support information
#1312
Changes from all commits
3b28a74
9f271ec
222fd82
5129251
fd53190
c1124f9
72dc14b
1b41409
3cfd35d
7c2bbad
4e0110b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,16 @@ describe("Release", function () { | |
| }); | ||
|
|
||
| describe("compare()", function () { | ||
| it("throws when comparing between two browsers", function () { | ||
| const cr = browser("chrome"); | ||
| const ed = browser("edge"); | ||
|
|
||
| assert.throws( | ||
| () => cr.version("100").inRange(ed.version("79"), cr.version("125")), | ||
| Error, | ||
| ); | ||
| }); | ||
|
|
||
| it("returns 0 for equivalent releases", function () { | ||
| const chrome100 = browser("chrome").version("100"); | ||
| assert.equal(chrome100.compare(chrome100), 0); | ||
|
|
@@ -87,4 +97,46 @@ describe("Release", function () { | |
| assert.equal(safariPreview.isPrerelease(), true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("inRange()", function () { | ||
| it("throws when comparing between two browsers", function () { | ||
| const cr = browser("chrome"); | ||
| const fx = browser("firefox"); | ||
|
|
||
| assert.throws(() => cr.version("50").inRange(fx.version("50")), Error); | ||
| }); | ||
|
|
||
| it("handles closed ranges", function () { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test for when the version equals the end version, to show the range is exclusive of the end point?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with 7c2bbad. |
||
| const cr = browser("chrome"); | ||
|
|
||
| // Start of range is inclusive | ||
| assert.equal( | ||
| cr.version("1").inRange(cr.version("1"), cr.version("125")), | ||
| true, | ||
| ); | ||
|
|
||
| // End of range is exclusive | ||
| assert.equal( | ||
| cr.version("20").inRange(cr.version("1"), cr.version("20")), | ||
| false, | ||
| ); | ||
|
|
||
| assert.equal( | ||
| cr.version("1").inRange(cr.version("10"), cr.version("15")), | ||
| false, | ||
| ); | ||
| assert.equal( | ||
| cr.version("100").inRange(cr.version("10"), cr.version("15")), | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| it("handles open ranges", function () { | ||
| const cr = browser("chrome"); | ||
| assert.equal(cr.version("1").inRange(cr.version("1")), true); | ||
| assert.equal(cr.version("1").inRange(cr.version("10")), false); | ||
| assert.equal(cr.version("100").inRange(cr.version("10")), true); | ||
| assert.equal(cr.version("preview").inRange(cr.version("10")), true); | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,10 +96,18 @@ describe("statements", function () { | |
| assert.equal(s.version_removed, "2"); | ||
| }); | ||
|
|
||
| it("returns false for undefined", function () { | ||
| const s = new SupportStatement({ version_added: "1" }); | ||
| it("returns false", function () { | ||
| const s = new SupportStatement({ | ||
| version_added: "1", | ||
| version_removed: false, | ||
| }); | ||
| assert.equal(s.version_removed, false); | ||
| }); | ||
|
|
||
| it("returns undefined", function () { | ||
| const s = new SupportStatement({ version_added: "1" }); | ||
| assert.equal(s.version_removed, undefined); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -163,6 +171,7 @@ describe("statements", function () { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("#supportedBy", function () { | ||
| it("returns an array of releases represented by the statement", function () { | ||
| const st = new RealSupportStatement( | ||
|
|
@@ -186,5 +195,148 @@ describe("statements", function () { | |
| assert.equal(rels.length, browser("chrome").releases.length - 10); | ||
| }); | ||
| }); | ||
|
|
||
| describe("supportedIn()", function () { | ||
| it("throws when browser is undefined", function () { | ||
| const cr = browser("chrome"); | ||
| const statement = new RealSupportStatement({ version_added: "1" }); | ||
| assert.throws(() => statement.supportedIn(cr.current()), Error); | ||
| }); | ||
|
|
||
| it("throws when release does not correspond to the statement's browser", function () { | ||
| const statement = new RealSupportStatement( | ||
| { version_added: "1" }, | ||
| browser("chrome"), | ||
| ); | ||
| assert.throws( | ||
| () => statement.supportedIn(browser("firefox").current()), | ||
| Error, | ||
| ); | ||
| }); | ||
|
|
||
| it("returns supported when release is on after version_added", function () { | ||
| const cr = browser("chrome"); | ||
| const unranged = new RealSupportStatement({ version_added: "100" }, cr); | ||
| const ranged = new RealSupportStatement({ version_added: "≤100" }, cr); | ||
|
|
||
| assert.equal(unranged.supportedIn(cr.version("100")).supported, true); | ||
| assert.equal(unranged.supportedIn(cr.version("101")).supported, true); | ||
| assert.equal(unranged.supportedIn(cr.current()).supported, true); | ||
| assert.equal( | ||
| unranged.supportedIn(cr.releases.at(-1) as any).supported, | ||
| true, | ||
| ); | ||
|
|
||
| assert.equal(ranged.supportedIn(cr.version("99")).supported, null); | ||
| assert.equal(ranged.supportedIn(cr.version("100")).supported, true); | ||
| assert.equal(ranged.supportedIn(cr.version("101")).supported, true); | ||
| assert.equal(ranged.supportedIn(cr.current()).supported, true); | ||
| assert.equal( | ||
| ranged.supportedIn(cr.releases.at(-1) as any).supported, | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| it("returns supported when release is on after version_added and before version_removed", function () { | ||
| const cr = browser("chrome"); | ||
| const unranged = new RealSupportStatement( | ||
| { version_added: "100", version_removed: "125" }, | ||
| cr, | ||
| ); | ||
| const ranged = new RealSupportStatement( | ||
| { version_added: "≤100", version_removed: "125" }, | ||
| cr, | ||
| ); | ||
|
|
||
| assert.equal(unranged.supportedIn(cr.version("99")).supported, false); | ||
| assert.equal(unranged.supportedIn(cr.version("100")).supported, true); | ||
| assert.equal(unranged.supportedIn(cr.version("101")).supported, true); | ||
| assert.equal(unranged.supportedIn(cr.version("124")).supported, true); | ||
| assert.equal(unranged.supportedIn(cr.version("125")).supported, false); | ||
|
|
||
| assert.equal(ranged.supportedIn(cr.version("99")).supported, null); | ||
| assert.equal(ranged.supportedIn(cr.version("100")).supported, true); | ||
| assert.equal(ranged.supportedIn(cr.version("101")).supported, true); | ||
| assert.equal(ranged.supportedIn(cr.version("124")).supported, true); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not the 125 assert here, so it's the same asserts for unranged and ranged? (You might remove 101 if you want to reduce the number of rows.)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with 4e0110b. |
||
| assert.equal(unranged.supportedIn(cr.version("125")).supported, false); | ||
| }); | ||
|
|
||
| it("returns unknown support when release is before ranged version_added", function () { | ||
| const cr = browser("chrome"); | ||
| const rangedOpen = new RealSupportStatement( | ||
| { version_added: "≤100" }, | ||
| cr, | ||
| ); | ||
| const rangedClosed = new RealSupportStatement( | ||
| { version_added: "≤100", version_removed: "125" }, | ||
| cr, | ||
| ); | ||
|
|
||
| assert.equal(rangedOpen.supportedIn(cr.version("99")).supported, null); | ||
| assert.equal( | ||
| rangedClosed.supportedIn(cr.version("99")).supported, | ||
| null, | ||
| ); | ||
| }); | ||
|
|
||
| it("returns unknown support when release is after version_added and before ranged version_removed", function () { | ||
| const cr = browser("chrome"); | ||
| const rangedEnd = new RealSupportStatement( | ||
| { version_added: "100", version_removed: "≤125" }, | ||
| cr, | ||
| ); | ||
|
|
||
| assert.equal(rangedEnd.supportedIn(cr.version("100")).supported, true); | ||
| assert.equal(rangedEnd.supportedIn(cr.version("101")).supported, null); | ||
| assert.equal(rangedEnd.supportedIn(cr.version("124")).supported, null); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also test 101 here to make it clear that there's just a single release we're sure about?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with 4e0110b. |
||
| assert.equal(rangedEnd.supportedIn(cr.version("125")).supported, false); | ||
| }); | ||
|
|
||
| it("returns unsupported when statement is version_added false", function () { | ||
| const cr = browser("chrome"); | ||
| const statement = new RealSupportStatement( | ||
| { version_added: false }, | ||
| cr, | ||
| ); | ||
|
|
||
| for (const release of cr.releases) { | ||
| assert.equal(statement.supportedIn(release).supported, false); | ||
| } | ||
| }); | ||
|
|
||
| it("returns unsupported when release is before fixed version_added", function () { | ||
| const cr = browser("chrome"); | ||
| const unranged = new RealSupportStatement({ version_added: "100" }, cr); | ||
| assert.equal(unranged.supportedIn(cr.version("99")).supported, false); | ||
| }); | ||
|
|
||
| it("returns unsupported when release is on or after version_removed", function () { | ||
| const cr = browser("chrome"); | ||
|
|
||
| const unranged = new RealSupportStatement( | ||
| { version_added: "1", version_removed: "10" }, | ||
| cr, | ||
| ); | ||
| assert.equal(unranged.supportedIn(cr.version("10")).supported, false); | ||
| assert.equal(unranged.supportedIn(cr.version("11")).supported, false); | ||
| assert.equal(unranged.supportedIn(cr.current()).supported, false); | ||
| assert.equal( | ||
| unranged.supportedIn(cr.releases.at(-1) as any).supported, | ||
| false, | ||
| ); | ||
|
|
||
| const ranged = new RealSupportStatement( | ||
| { version_added: "≤5", version_removed: "10" }, | ||
| cr, | ||
| ); | ||
| assert.equal(ranged.supportedIn(cr.version("10")).supported, false); | ||
| assert.equal(ranged.supportedIn(cr.version("11")).supported, false); | ||
| assert.equal(ranged.supportedIn(cr.current()).supported, false); | ||
| assert.equal( | ||
| ranged.supportedIn(cr.releases.at(-1) as any).supported, | ||
| false, | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.