test(codec-browsers): use fixed date inside tests
MODIFY
internal/codec-browsers/index.test.ts
internal/codec-browsers/index.test.ts
@@ -40,9 +40,9 @@ const promise = createFixtureTests(async (fixture, t) => {
includeSourceTextInDiagnostics: true,
});
- const result = Array.from(resolveTargets(parsed)).map((browser) =>
- `${browser.getId()}:${browser.getVersion()}`
- );
+ const result = Array.from(
+ resolveTargets(parsed, {fixedDate: new Date(1_616_056_455_400)}),
+ ).map((browser) => `${browser.getId()}:${browser.getVersion()}`);
t.namedSnapshot("targets", parsed, undefined, {filename: outputFile});

MODIFY
internal/codec-browsers/index.ts
internal/codec-browsers/index.ts
import {Browser} from "@internal/browser-features/Browser";
-import {resolveTargets} from "@internal/codec-browsers/resolve";
+import {ResolveOptions, resolveTargets} from "@internal/codec-browsers/resolve";
import {parseBrowserQuery} from "@internal/codec-browsers/parse";
import {ParserOptions} from "@internal/parser-core";
export function resolveBrowsers(
queries: string | string[] | ParserOptions,
+ resolveOptions?: ResolveOptions,
): Browser[] {
let opt: ParserOptions;
@@ -16,5 +17,5 @@ export function resolveBrowsers(
opt = queries;
}
- return Array.from(resolveTargets(parseBrowserQuery(opt)));
+ return Array.from(resolveTargets(parseBrowserQuery(opt), resolveOptions));
}

MODIFY
internal/codec-browsers/resolve.ts
internal/codec-browsers/resolve.ts
@@ -99,8 +99,13 @@ export interface TargetBrowserInversion {
>;
}
+export interface ResolveOptions {
+ fixedDate?: Date;
+}
+
export function resolveTargets(
targets: AnyTargetBrowser | AnyTargetBrowser[],
+ resolveOptions?: ResolveOptions,
): Set<Browser> {
const browsers: Set<Browser> = new Set([]);
const toRemove: Set<Browser> = new Set([]);
@@ -219,6 +224,7 @@ export function resolveTargets(
parseBrowserQuery({
input: modern,
}),
+ resolveOptions,
).forEach((b) => browsers.add(b));
break;
}
@@ -227,6 +233,7 @@ export function resolveTargets(
parseBrowserQuery({
input: dead,
}),
+ resolveOptions,
).forEach((b) => browsers.add(b));
break;
}
@@ -314,7 +321,7 @@ export function resolveTargets(
case "months":
case "days": {
const releaseDate = getBrowser({name}).getRawReleaseDate();
- const date = new Date();
+ const date = resolveOptions?.fixedDate ?? new Date();
switch (target.unit) {
case "years": {

MODIFY
internal/codec-browsers/test-fixtures/individual/last-days/input.test.md
internal/codec-browsers/test-fixtures/individual/last-days/input.test.md
"safari:14"
"opera:73"
"ios_saf:14"
+ "op_mini:1"
"android:81"
+ "bb:10"
"op_mob:59"
"and_chr:88"
"and_ff:85"
+ "and_uc:12.12"
"samsung:13"
"and_qq:10.4"
+ "baidu:7.12"
+ "kaios:2.5"
]
```

MODIFY
internal/codec-browsers/test-fixtures/individual/last-months/input.test.md
internal/codec-browsers/test-fixtures/individual/last-months/input.test.md
### `result`
```javascript
-["edge:88", "firefox:85", "chrome:88", "opera:73", "and_chr:88", "and_ff:85"]
+[
+ "edge:88"
+ "firefox:85"
+ "chrome:88"
+ "safari:14"
+ "opera:73"
+ "ios_saf:14"
+ "android:81"
+ "op_mob:59"
+ "and_chr:88"
+ "and_ff:85"
+ "samsung:13"
+ "and_qq:10.4"
+ "baidu:7.12"
+ "kaios:2.5"
+]
```
### `targets`

MODIFY
internal/codec-browsers/test-fixtures/individual/last-years/input.test.md
internal/codec-browsers/test-fixtures/individual/last-years/input.test.md
"safari:14"
"opera:73"
"ios_saf:14"
+ "op_mini:1"
"android:81"
+ "bb:10"
"op_mob:59"
"and_chr:88"
"and_ff:85"
+ "and_uc:12.12"
"samsung:13"
"and_qq:10.4"
"baidu:7.12"

test(codec-browsers): use fixed date inside tests (#1408)