Skip to content

Commit 12d7fd8

Browse files
committed
Add 1.x gates
1 parent bb1e686 commit 12d7fd8

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

testing/_assert_inline_snapshot.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import {
1717
serialize,
1818
} from "./_snapshot_utils.ts";
1919

20+
// TODO (WWRS): Remove this when we drop support for Deno 1.x
21+
export const LINT_SUPPORTED = !Deno.version.deno.startsWith("1.");
22+
2023
/** The options for {@linkcode assertInlineSnapshot}. */
2124

2225
export interface InlineSnapshotOptions<T = unknown>
@@ -136,6 +139,12 @@ class AssertInlineSnapshotContext {
136139
const snapshotsUpdated = Object.keys(this.#lineColumnToSnapshot).length;
137140
if (snapshotsUpdated === 0) return;
138141

142+
if (!LINT_SUPPORTED) {
143+
throw new Error(
144+
"Deno versions before 2.2.0 do not support Deno.lint, which is required to update inline snapshots",
145+
);
146+
}
147+
139148
const testFilePath = fromFileUrl(this.#testFileUrl);
140149
ensureFileSync(testFilePath);
141150
const file = Deno.readTextFileSync(testFilePath);
@@ -237,8 +246,8 @@ class AssertInlineSnapshotContext {
237246
* ```ts
238247
* import { assertInlineSnapshot } from "@std/testing/snapshot";
239248
*
240-
* Deno.test("snapshot", async (t) => {
241-
* await assertInlineSnapshot<number>(t, 2, `2`);
249+
* Deno.test("snapshot", (t) => {
250+
* assertInlineSnapshot<number>(t, 2, `2`);
242251
* });
243252
* ```
244253
* @typeParam T The type of the snapshot
@@ -263,8 +272,8 @@ export function assertInlineSnapshot<T>(
263272
* ```ts
264273
* import { assertInlineSnapshot } from "@std/testing/snapshot";
265274
*
266-
* Deno.test("snapshot", async (t) => {
267-
* await assertInlineSnapshot<number>(t, 2, `2`);
275+
* Deno.test("snapshot", (t) => {
276+
* assertInlineSnapshot<number>(t, 2, `2`);
268277
* });
269278
* ```
270279
* @typeParam T The type of the snapshot
@@ -354,8 +363,8 @@ export function assertInlineSnapshot(
354363
* format: false
355364
* });
356365
*
357-
* Deno.test("a snapshot test case", async (t) => {
358-
* await assertInlineSnapshot(
366+
* Deno.test("a snapshot test case", (t) => {
367+
* assertInlineSnapshot(
359368
* t,
360369
* { foo: "Hello", bar: "World" },
361370
* `CREATE`

testing/_assert_inline_snapshot_test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { assertEquals } from "@std/assert";
55
import {
66
assertInlineSnapshot,
77
createAssertInlineSnapshot,
8+
LINT_SUPPORTED,
89
} from "./_assert_inline_snapshot.ts";
910

1011
const SNAPSHOT_MODULE_URL = toFileUrl(join(
@@ -85,6 +86,8 @@ Deno.test("assertInlineSnapshot()", (t) => {
8586
});
8687

8788
Deno.test("assertInlineSnapshot() formats", async () => {
89+
if (!LINT_SUPPORTED) return;
90+
8891
const tempDir = await Deno.makeTempDir();
8992
const formatTestFile = join(tempDir, "format_test.ts");
9093
const noFormatTestFile = join(tempDir, "no_format_test.ts");
@@ -138,6 +141,8 @@ Deno.test("no format", async (t) => {
138141
});
139142

140143
Deno.test("assertInlineSnapshot() counts lines and columns like V8", async () => {
144+
if (!LINT_SUPPORTED) return;
145+
141146
const tempDir = await Deno.makeTempDir();
142147
const countTestFile = join(tempDir, "count_test.ts");
143148
try {

testing/snapshot.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
* // example_test.ts
3939
* import { assertInlineSnapshot } from "@std/testing/snapshot";
4040
*
41-
* Deno.test("isInlineSnapshotMatch", async function (t): Promise<void> {
41+
* Deno.test("isInlineSnapshotMatch", function (t): void {
4242
* const a = {
4343
* hello: "world!",
4444
* example: 123,
4545
* };
46-
* await assertInlineSnapshot(
46+
* assertInlineSnapshot(
4747
* t,
4848
* a,
4949
* `{
@@ -179,13 +179,15 @@ import {
179179
type SnapshotMode,
180180
type SnapshotOptions,
181181
} from "./_assert_snapshot.ts";
182+
import { serialize } from "./_snapshot_utils.ts";
182183

183184
export {
184185
assertInlineSnapshot,
185186
assertSnapshot,
186187
createAssertInlineSnapshot,
187188
createAssertSnapshot,
188189
type InlineSnapshotOptions,
190+
serialize,
189191
type SnapshotMode,
190192
type SnapshotOptions,
191193
};

0 commit comments

Comments
 (0)