From 695097bc4d73cae1f303607d116c59a50e3f78da Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 15 Jan 2025 08:59:10 +0100 Subject: [PATCH] chore: update typebox (#15450) --- CHANGELOG.md | 2 +- packages/jest-schemas/package.json | 2 +- packages/jest-schemas/src/index.ts | 16 +++---- packages/jest-schemas/src/raw-types.ts | 64 +++++++++++++------------- yarn.lock | 10 ++-- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 947668cd2cbe..f31431fe56fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ - `[jest-runtime]` Support `import.meta.resolve` ([#14930](https://github.com/jestjs/jest/pull/14930)) - `[jest-runtime]` [**BREAKING**] Make it mandatory to pass `globalConfig` to the `Runtime` constructor ([#15044](https://github.com/jestjs/jest/pull/15044)) - `[jest-runtime]` Add `unstable_unmockModule` ([#15080](https://github.com/jestjs/jest/pull/15080)) -- `[@jest/schemas]` Upgrade `@sinclair/typebox` to v0.31 ([#14072](https://github.com/jestjs/jest/pull/14072)) +- `[@jest/schemas]` Upgrade `@sinclair/typebox` to v0.34 ([#15450](https://github.com/jestjs/jest/pull/15450)) - `[@jest/types]` `test.each()`: Accept a readonly (`as const`) table properly ([#14565](https://github.com/jestjs/jest/pull/14565)) - `[@jest/types]` Improve argument type inference passed to `test` and `describe` callback functions from `each` tables ([#14920](https://github.com/jestjs/jest/pull/14920)) - `[jest-snapshot]` [**BREAKING**] Add support for [Error causes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) in snapshots ([#13965](https://github.com/facebook/jest/pull/13965)) diff --git a/packages/jest-schemas/package.json b/packages/jest-schemas/package.json index 7df7926143ab..3a1bfc2535ae 100644 --- a/packages/jest-schemas/package.json +++ b/packages/jest-schemas/package.json @@ -19,7 +19,7 @@ "./package.json": "./package.json" }, "dependencies": { - "@sinclair/typebox": "^0.33.0" + "@sinclair/typebox": "^0.34.0" }, "engines": { "node": "^16.10.0 || ^18.12.0 || >=20.0.0" diff --git a/packages/jest-schemas/src/index.ts b/packages/jest-schemas/src/index.ts index 973c64edf105..9b9d0b57311d 100644 --- a/packages/jest-schemas/src/index.ts +++ b/packages/jest-schemas/src/index.ts @@ -5,14 +5,14 @@ * LICENSE file in the root directory of this source tree. */ -import {type Static, Type} from '@sinclair/typebox'; -import {RawFakeTimers, RawInitialOptions, RawSnapshotFormat} from './raw-types'; +import type {Static} from '@sinclair/typebox'; +import * as types from './raw-types'; -export const SnapshotFormat = Type.Strict(RawSnapshotFormat); -export type SnapshotFormat = Static; +export const SnapshotFormat = types.SnapshotFormat; +export type SnapshotFormat = Static; -export const InitialOptions = Type.Strict(RawInitialOptions); -export type InitialOptions = Static; +export const InitialOptions = types.InitialOptions; +export type InitialOptions = Static; -export const FakeTimers = Type.Strict(RawFakeTimers); -export type FakeTimers = Static; +export const FakeTimers = types.FakeTimers; +export type FakeTimers = Static; diff --git a/packages/jest-schemas/src/raw-types.ts b/packages/jest-schemas/src/raw-types.ts index be58048ff0f8..8f001e762e1d 100644 --- a/packages/jest-schemas/src/raw-types.ts +++ b/packages/jest-schemas/src/raw-types.ts @@ -9,7 +9,7 @@ import {type Static, Type} from '@sinclair/typebox'; -export const RawSnapshotFormat = Type.Partial( +export const SnapshotFormat = Type.Partial( Type.Object({ callToJSON: Type.Boolean(), compareKeys: Type.Null(), @@ -34,12 +34,12 @@ export const RawSnapshotFormat = Type.Partial( }), ); -const RawCoverageProvider = Type.Union([ +const CoverageProvider = Type.Union([ Type.Literal('babel'), Type.Literal('v8'), ]); -const RawCoverageThresholdValue = Type.Partial( +const CoverageThresholdValue = Type.Partial( Type.Object({ branches: Type.Number({minimum: 0, maximum: 100}), functions: Type.Number({minimum: 0, maximum: 100}), @@ -48,15 +48,15 @@ const RawCoverageThresholdValue = Type.Partial( }), ); -const RawCoverageThresholdBase = Type.Object( - {global: RawCoverageThresholdValue}, - {additionalProperties: RawCoverageThresholdValue}, +const CoverageThresholdBase = Type.Object( + {global: CoverageThresholdValue}, + {additionalProperties: CoverageThresholdValue}, ); -const RawCoverageThreshold = Type.Unsafe<{ - global: Static; - [path: string]: Static; -}>(RawCoverageThresholdBase); +const CoverageThreshold = Type.Unsafe<{ + global: Static; + [path: string]: Static; +}>(CoverageThresholdBase); // TODO: add type test that these are all the colors available in chalk.ForegroundColor export const ChalkForegroundColors = Type.Union([ @@ -80,13 +80,13 @@ export const ChalkForegroundColors = Type.Union([ Type.Literal('whiteBright'), ]); -const RawDisplayName = Type.Object({ +const DisplayName = Type.Object({ name: Type.String(), color: ChalkForegroundColors, }); // TODO: verify these are the names of istanbulReport.ReportOptions -export const RawCoverageReporterNames = Type.Union([ +export const CoverageReporterNames = Type.Union([ Type.Literal('clover'), Type.Literal('cobertura'), Type.Literal('html-spa'), @@ -102,17 +102,17 @@ export const RawCoverageReporterNames = Type.Union([ Type.Literal('text-summary'), ]); -const RawCoverageReporters = Type.Array( +const CoverageReporters = Type.Array( Type.Union([ - RawCoverageReporterNames, + CoverageReporterNames, Type.Tuple([ - RawCoverageReporterNames, + CoverageReporterNames, Type.Record(Type.String(), Type.Unknown()), ]), ]), ); -const RawGlobalFakeTimersConfig = Type.Partial( +const GlobalFakeTimersConfig = Type.Partial( Type.Object({ enableGlobally: Type.Boolean({ description: @@ -122,7 +122,7 @@ const RawGlobalFakeTimersConfig = Type.Partial( }), ); -const RawFakeableAPI = Type.Union([ +const FakeableAPI = Type.Union([ Type.Literal('Date'), Type.Literal('hrtime'), Type.Literal('nextTick'), @@ -140,7 +140,7 @@ const RawFakeableAPI = Type.Union([ Type.Literal('clearTimeout'), ]); -const RawFakeTimersConfig = Type.Partial( +const FakeTimersConfig = Type.Partial( Type.Object({ advanceTimers: Type.Union([Type.Boolean(), Type.Number({minimum: 0})], { description: @@ -148,7 +148,7 @@ const RawFakeTimersConfig = Type.Partial( 'time delta may be provided by passing a number.', default: false, }), - doNotFake: Type.Array(RawFakeableAPI, { + doNotFake: Type.Array(FakeableAPI, { description: 'List of names of APIs (e.g. `Date`, `nextTick()`, `setImmediate()`, `setTimeout()`) that should not be faked.' + '\n\nThe default is `[]`, meaning all APIs are faked.', @@ -173,7 +173,7 @@ const RawFakeTimersConfig = Type.Partial( }), ); -const RawLegacyFakeTimersConfig = Type.Partial( +const LegacyFakeTimersConfig = Type.Partial( Type.Object({ legacyFakeTimers: Type.Literal(true, { description: @@ -183,12 +183,12 @@ const RawLegacyFakeTimersConfig = Type.Partial( }), ); -export const RawFakeTimers = Type.Intersect([ - RawGlobalFakeTimersConfig, - Type.Union([RawFakeTimersConfig, RawLegacyFakeTimersConfig]), +export const FakeTimers = Type.Intersect([ + GlobalFakeTimersConfig, + Type.Union([FakeTimersConfig, LegacyFakeTimersConfig]), ]); -const RawHasteConfig = Type.Partial( +const HasteConfig = Type.Partial( Type.Object({ computeSha1: Type.Boolean({ description: 'Whether to hash files using SHA-1.', @@ -225,7 +225,7 @@ const RawHasteConfig = Type.Partial( }), ); -export const RawInitialOptions = Type.Partial( +export const InitialOptions = Type.Partial( Type.Object({ automock: Type.Boolean(), bail: Type.Union([Type.Boolean(), Type.Number()]), @@ -239,16 +239,16 @@ export const RawInitialOptions = Type.Partial( collectCoverageFrom: Type.Array(Type.String()), coverageDirectory: Type.String(), coveragePathIgnorePatterns: Type.Array(Type.String()), - coverageProvider: RawCoverageProvider, - coverageReporters: RawCoverageReporters, - coverageThreshold: RawCoverageThreshold, + coverageProvider: CoverageProvider, + coverageReporters: CoverageReporters, + coverageThreshold: CoverageThreshold, dependencyExtractor: Type.String(), detectLeaks: Type.Boolean(), detectOpenHandles: Type.Boolean(), - displayName: Type.Union([Type.String(), RawDisplayName]), + displayName: Type.Union([Type.String(), DisplayName]), expand: Type.Boolean(), extensionsToTreatAsEsm: Type.Array(Type.String()), - fakeTimers: RawFakeTimers, + fakeTimers: FakeTimers, filter: Type.String(), findRelatedTests: Type.Boolean(), forceCoverageMatch: Type.Array(Type.String()), @@ -257,7 +257,7 @@ export const RawInitialOptions = Type.Partial( globals: Type.Record(Type.String(), Type.Unknown()), globalSetup: Type.Union([Type.String(), Type.Null()]), globalTeardown: Type.Union([Type.String(), Type.Null()]), - haste: RawHasteConfig, + haste: HasteConfig, id: Type.String(), injectGlobals: Type.Boolean(), reporters: Type.Array( @@ -317,7 +317,7 @@ export const RawInitialOptions = Type.Partial( slowTestThreshold: Type.Number(), snapshotResolver: Type.String(), snapshotSerializers: Type.Array(Type.String()), - snapshotFormat: RawSnapshotFormat, + snapshotFormat: SnapshotFormat, errorOnDeprecated: Type.Boolean(), testEnvironment: Type.String(), testEnvironmentOptions: Type.Record(Type.String(), Type.Unknown()), diff --git a/yarn.lock b/yarn.lock index f5a0f9e01115..da0a56032ef5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3413,7 +3413,7 @@ __metadata: version: 0.0.0-use.local resolution: "@jest/schemas@workspace:packages/jest-schemas" dependencies: - "@sinclair/typebox": ^0.33.0 + "@sinclair/typebox": ^0.34.0 languageName: unknown linkType: soft @@ -4916,10 +4916,10 @@ __metadata: languageName: node linkType: hard -"@sinclair/typebox@npm:^0.33.0": - version: 0.33.7 - resolution: "@sinclair/typebox@npm:0.33.7" - checksum: 96743096e8f15024148e2fcbaf236ada0cf4dd8d8f0c1b0d49a9de9003bda2b2a2b5084971d5587a2a0c64cd238a1f9dbbafe6c97af4154975f80dadf34ec0c0 +"@sinclair/typebox@npm:^0.34.0": + version: 0.34.13 + resolution: "@sinclair/typebox@npm:0.34.13" + checksum: abc841a407396e8f49afe9b42bf60133207029e9ac483861750b40bcc41a5de46b9b1b6026f5f34664de32a1941cad35e0de36e3a6f5f94c15c33a0d59260828 languageName: node linkType: hard