Skip to content

Commit

Permalink
fix(testing): call createAssertSnapshot in each test module
Browse files Browse the repository at this point in the history
This is required for transferring the CLI to another repository
  • Loading branch information
hasundue committed Apr 16, 2024
1 parent 0bd4540 commit bb7cea6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
15 changes: 10 additions & 5 deletions lib/file_test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { basename, dirname } from "./std/path.ts";
import { formatEOL, LF } from "./std/fs.ts";
import { assert, assertInstanceOf } from "./std/assert.ts";
import { fromFileUrl } from "./std/path.ts";
import { createAssertSnapshot } from "./std/testing.ts";
import { collect, CollectResult } from "./update.ts";
import { associateByFile, type FileUpdate, writeFileUpdate } from "./file.ts";
import {
FileSystemFake,
LatestVersionStub,
ReadTextFileStub,
WriteTextFileStub,
} from "./testing.ts";
import { assert, assertInstanceOf } from "./std/assert.ts";
import { assertSnapshot } from "./testing.ts";
import { collect, CollectResult } from "./update.ts";
import { associateByFile, type FileUpdate, writeFileUpdate } from "./file.ts";
import { LatestVersionStub } from "./testing.ts";

function toName(path: string) {
const base = basename(path);
Expand All @@ -18,6 +19,10 @@ function toName(path: string) {
: base;
}

const assertSnapshot = createAssertSnapshot({
dir: fromFileUrl(new URL("../test/snapshots/", import.meta.url)),
});

async function assertFileUpdateSnapshot(
t: Deno.TestContext,
results: FileUpdate[],
Expand Down
8 changes: 2 additions & 6 deletions lib/testing.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { createAssertSnapshot, spy, Stub, stub } from "./std/testing.ts";
import { spy, Stub, stub } from "./std/testing.ts";
import { formatEOL, LF } from "./std/fs.ts";
import { dirname, fromFileUrl } from "./std/path.ts";

export const assertSnapshot = createAssertSnapshot({
dir: fromFileUrl(new URL("../test/snapshots/", import.meta.url)),
});
import { dirname } from "./std/path.ts";

export const CommandStub = {
create(pattern = "") {
Expand Down
8 changes: 6 additions & 2 deletions lib/update_test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { dirname } from "./std/path.ts";
import { assertEquals, assertInstanceOf } from "./std/assert.ts";
import { filterKeys } from "./std/collections.ts";
import { basename } from "./std/path.ts";
import { assertSnapshot } from "./testing.ts";
import { basename, fromFileUrl } from "./std/path.ts";
import { createAssertSnapshot } from "./std/testing.ts";
import { LatestVersionStub } from "./testing.ts";
import { collect, DependencyUpdate } from "./update.ts";

const assertSnapshot = createAssertSnapshot({
dir: fromFileUrl(new URL("../test/snapshots/", import.meta.url)),
});

function test(
path: string,
name = basename(path),
Expand Down
8 changes: 6 additions & 2 deletions test/integration/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertEquals } from "../../lib/std/assert.ts";
import { stripAnsiCode } from "../../lib/std/fmt.ts";
import { join } from "../../lib/std/path.ts";
import { assertSnapshot } from "../../lib/testing.ts";
import { fromFileUrl, join } from "../../lib/std/path.ts";
import { createAssertSnapshot } from "../../lib/std/testing.ts";

// basic commands
molt("", { code: 2 });
Expand Down Expand Up @@ -115,3 +115,7 @@ function stringify(data: Uint8Array) {
}
return stripAnsiCode(text);
}

const assertSnapshot = createAssertSnapshot({
dir: fromFileUrl(new URL("../snapshots/", import.meta.url)),
});
7 changes: 6 additions & 1 deletion test/integration/registries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assertSnapshot } from "../../lib/testing.ts";
import { fromFileUrl } from "../../lib/std/path.ts";
import { createAssertSnapshot } from "../../lib/std/testing.ts";
import { parse, resolveLatestVersion } from "../../lib/dependency.ts";

type RegistryTestSpec = [
Expand Down Expand Up @@ -80,3 +81,7 @@ for (const spec of SPECS) {
await assert(updated);
});
}

const assertSnapshot = createAssertSnapshot({
dir: fromFileUrl(new URL("../snapshots/", import.meta.url)),
});

0 comments on commit bb7cea6

Please sign in to comment.