-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(snapshot): introduce
toMatchFileSnapshot
and auto queuing expe…
…ct promise (#3116)
- Loading branch information
Showing
28 changed files
with
325 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export function recordAsyncExpect(test: any, promise: Promise<any>) { | ||
// record promise for test, that resolves before test ends | ||
if (test) { | ||
// if promise is explicitly awaited, remove it from the list | ||
promise = promise.finally(() => { | ||
const index = test.promises.indexOf(promise) | ||
if (index !== -1) | ||
test.promises.splice(index, 1) | ||
}) | ||
|
||
// record promise | ||
if (!test.promises) | ||
test.promises = [] | ||
test.promises.push(promise) | ||
} | ||
|
||
return promise | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { SnapshotEnvironment } from '../types' | ||
|
||
export interface RawSnapshotInfo { | ||
file: string | ||
readonly?: boolean | ||
content?: string | ||
} | ||
|
||
export interface RawSnapshot extends RawSnapshotInfo { | ||
snapshot: string | ||
file: string | ||
} | ||
|
||
export async function saveRawSnapshots( | ||
environment: SnapshotEnvironment, | ||
snapshots: Array<RawSnapshot>, | ||
) { | ||
await Promise.all(snapshots.map(async (snap) => { | ||
if (!snap.readonly) | ||
await environment.saveSnapshotFile(snap.file, snap.snapshot) | ||
})) | ||
} |
Oops, something went wrong.