|
5 | 5 | isNodejsCompatDefaultOn, |
6 | 6 | NODEJS_COMPAT_DEFAULT_ON_DATE, |
7 | 7 | resolveNodejsCompat, |
| 8 | + stripRedundantNodejsCompatFlags, |
8 | 9 | } from "../src/compatibility-date"; |
9 | 10 |
|
10 | 11 | describe("getTodaysCompatDate()", () => { |
@@ -85,3 +86,60 @@ describe("resolveNodejsCompat", () => { |
85 | 86 | } |
86 | 87 | ); |
87 | 88 | }); |
| 89 | + |
| 90 | +describe("stripRedundantNodejsCompatFlags", () => { |
| 91 | + // [compatibilityDate, compatibilityFlags, expected] |
| 92 | + const cases: [string | undefined, string[], string[]][] = [ |
| 93 | + // Before the default-on date the flags are the only way to enable this |
| 94 | + ["2026-08-03", ["nodejs_compat"], ["nodejs_compat"]], |
| 95 | + ["2024-09-22", ["nodejs_compat_v2"], ["nodejs_compat_v2"]], |
| 96 | + [undefined, ["nodejs_compat"], ["nodejs_compat"]], |
| 97 | + // From the default-on date the date enables them, so they're redundant |
| 98 | + ["2026-08-04", ["nodejs_compat"], []], |
| 99 | + ["2026-08-04", ["nodejs_compat_v2"], []], |
| 100 | + ["2026-08-04", ["nodejs_compat", "nodejs_compat_v2"], []], |
| 101 | + ["2030-01-01", ["nodejs_compat"], []], |
| 102 | + // A flag that contradicts its opt-out is kept, since workerd reports that |
| 103 | + // and treats the flag as the winner - dropping it would flip the behaviour |
| 104 | + [ |
| 105 | + "2026-08-04", |
| 106 | + ["nodejs_compat", "no_nodejs_compat"], |
| 107 | + ["nodejs_compat", "no_nodejs_compat"], |
| 108 | + ], |
| 109 | + [ |
| 110 | + "2026-08-04", |
| 111 | + ["nodejs_compat_v2", "no_nodejs_compat_v2"], |
| 112 | + ["nodejs_compat_v2", "no_nodejs_compat_v2"], |
| 113 | + ], |
| 114 | + // Each flag is considered separately |
| 115 | + [ |
| 116 | + "2026-08-04", |
| 117 | + ["nodejs_compat", "no_nodejs_compat_v2"], |
| 118 | + ["no_nodejs_compat_v2"], |
| 119 | + ], |
| 120 | + // Opt-outs are never redundant, they matter for later dates |
| 121 | + ["2026-08-04", ["no_nodejs_compat"], ["no_nodejs_compat"]], |
| 122 | + // Other flags are left alone, in their original order |
| 123 | + [ |
| 124 | + "2026-08-04", |
| 125 | + ["nodejs_als", "nodejs_compat", "url_standard"], |
| 126 | + ["nodejs_als", "url_standard"], |
| 127 | + ], |
| 128 | + ["2026-08-04", [], []], |
| 129 | + // Only exact matches are stripped |
| 130 | + [ |
| 131 | + "2026-08-04", |
| 132 | + ["experimental:nodejs_compat_v2"], |
| 133 | + ["experimental:nodejs_compat_v2"], |
| 134 | + ], |
| 135 | + ]; |
| 136 | + |
| 137 | + test.for(cases)( |
| 138 | + "%s with %j", |
| 139 | + ([compatibilityDate, flags, expected], { expect }) => { |
| 140 | + expect(stripRedundantNodejsCompatFlags(compatibilityDate, flags)).toEqual( |
| 141 | + expected |
| 142 | + ); |
| 143 | + } |
| 144 | + ); |
| 145 | +}); |
0 commit comments