Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add dir & path option
  • Loading branch information
c4spar committed Apr 5, 2023
commit a0ccec6aea2bf343c3b8abf7b0b0452889e7ba2a
34 changes: 26 additions & 8 deletions testing/assert_snapshot_call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,39 @@ export interface AssertSnapshotCallOptions extends AssertSnapshotCallStep {
name: string;
/** Import meta. Required to determine the import url of the test file. */
meta: ImportMeta;
/** Test function. */
fn(): Promise<unknown>;
/**
* Object of test steps. Key is the test name and the value is an array of
* input sequences/characters.
*/
steps?: Record<string, AssertSnapshotCallStep>;
/** Test function. */
fn(): Promise<unknown>;
/**
* Operating system snapshot suffix. This is useful when your test produces
* different output on different operating systems.
*/
osSuffix?: Array<typeof Deno.build.os>;
/**
* Arguments passed to the `deno test` command when executing the snapshot
* tests. `--allow-env=ASSERT_SNAPSHOT_CALL` is passed by default.
*/
denoArgs?: Array<string>;
/**
* Snapshot output directory. Snapshot files will be written to this directory.
* This can be relative to the test directory or an absolute path.
*
* If both `dir` and `path` are specified, the `dir` option will be ignored and
* the `path` option will be handled as normal.
*/
dir?: string;
/**
* Snapshot output path. The snapshot will be written to this file. This can be
* a path relative to the test directory or an absolute path.
*
* If both `dir` and `path` are specified, the `dir` option will be ignored and
* the `path` option will be handled as normal.
*/
path?: string;
/**
* Operating system snapshot suffix. This is useful when your test produces
* different output on different operating systems.
*/
osSuffix?: Array<typeof Deno.build.os>;
/** Enable/disable colors. Default is `false`. */
colors?: boolean;
/**
Expand Down Expand Up @@ -120,7 +136,9 @@ function registerTest(options: AssertSnapshotCallOptions) {
: "";

await assertSnapshot(ctx, output, {
path: `__snapshots__/${fileName}${suffix}.snap`,
dir: options.dir,
path: options.path ??
(options.dir ? undefined : `__snapshots__/${fileName}${suffix}.snap`),
});
}
}
Expand Down