From c7a3a37cf1cbb6494233f9cb9b5f15cccadfea41 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 19 Aug 2022 13:11:57 +0200 Subject: [PATCH 1/3] chore: make prettierPath optional in `SnapshotState` --- packages/jest-snapshot/src/InlineSnapshots.ts | 2 +- packages/jest-snapshot/src/State.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/jest-snapshot/src/InlineSnapshots.ts b/packages/jest-snapshot/src/InlineSnapshots.ts index 4c2d064da3e1..1cf34797de00 100644 --- a/packages/jest-snapshot/src/InlineSnapshots.ts +++ b/packages/jest-snapshot/src/InlineSnapshots.ts @@ -46,7 +46,7 @@ export type InlineSnapshot = { export function saveInlineSnapshots( snapshots: Array, - prettierPath: string, + prettierPath: string | null, ): void { let prettier: Prettier | null = null; if (prettierPath) { diff --git a/packages/jest-snapshot/src/State.ts b/packages/jest-snapshot/src/State.ts index ef3aa5d72cfa..5520da70d7a2 100644 --- a/packages/jest-snapshot/src/State.ts +++ b/packages/jest-snapshot/src/State.ts @@ -24,7 +24,7 @@ import { export type SnapshotStateOptions = { updateSnapshot: Config.SnapshotUpdateState; - prettierPath: string; + prettierPath: string | null; expand?: boolean; snapshotFormat: PrettyFormatOptions; }; @@ -62,7 +62,7 @@ export default class SnapshotState { private _snapshotPath: string; private _inlineSnapshots: Array; private _uncheckedKeys: Set; - private _prettierPath: string; + private _prettierPath: string | null; private _snapshotFormat: PrettyFormatOptions; added: number; From b754892156e833a84e96d6fd7e4e33ecb963a26c Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 19 Aug 2022 13:15:18 +0200 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eaf6a8a436d..42521e9a13d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - `[jest-config]` Fix testing multiple projects with TypeScript config files ([#13099](https://github.com/facebook/jest/pull/13099)) - `[@jest/expect-utils]` Fix deep equality of ImmutableJS Record ([#13055](https://github.com/facebook/jest/pull/13055)) - `[jest-haste-map]` Increase the maximum possible file size that jest-haste-map can handle ([#13094](https://github.com/facebook/jest/pull/13094)) +- `[jest-snapshot]` Make `prettierPath` optional in `SnapshotState` ([#13149](https://github.com/facebook/jest/pull/13149)) - `[jest-worker]` When a process runs out of memory worker exits correctly and doesn't spin indefinitely ([#13054](https://github.com/facebook/jest/pull/13054)) ### Chore & Maintenance From bf25c392b65fd04a1d4288707994aaf23763673d Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 19 Aug 2022 13:27:52 +0200 Subject: [PATCH 3/3] actually optional --- packages/jest-snapshot/src/InlineSnapshots.ts | 2 +- packages/jest-snapshot/src/State.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/jest-snapshot/src/InlineSnapshots.ts b/packages/jest-snapshot/src/InlineSnapshots.ts index 1cf34797de00..2ee07954f6da 100644 --- a/packages/jest-snapshot/src/InlineSnapshots.ts +++ b/packages/jest-snapshot/src/InlineSnapshots.ts @@ -72,7 +72,7 @@ export function saveInlineSnapshots( const saveSnapshotsForFile = ( snapshots: Array, sourceFilePath: string, - prettier?: Prettier, + prettier: Prettier | undefined, ) => { const sourceFile = fs.readFileSync(sourceFilePath, 'utf8'); diff --git a/packages/jest-snapshot/src/State.ts b/packages/jest-snapshot/src/State.ts index 5520da70d7a2..a065294b8d9a 100644 --- a/packages/jest-snapshot/src/State.ts +++ b/packages/jest-snapshot/src/State.ts @@ -24,7 +24,7 @@ import { export type SnapshotStateOptions = { updateSnapshot: Config.SnapshotUpdateState; - prettierPath: string | null; + prettierPath?: string | null; expand?: boolean; snapshotFormat: PrettyFormatOptions; }; @@ -80,7 +80,7 @@ export default class SnapshotState { this._initialData = data; this._snapshotData = data; this._dirty = dirty; - this._prettierPath = options.prettierPath; + this._prettierPath = options.prettierPath ?? null; this._inlineSnapshots = []; this._uncheckedKeys = new Set(Object.keys(this._snapshotData)); this._counters = new Map();