From 6091caf63c69f05e3e3397eb550469d6fd7fef7d Mon Sep 17 00:00:00 2001 From: Quang Phan Date: Tue, 17 Dec 2024 11:07:33 +0700 Subject: [PATCH] Refactor test and snapshots to colocate next to source file --- .../errors.test.ts => scripts/builder.test.ts | 7 +-- .../base}/__snapshots__/base.test.ts.snap | 28 +++++------ scripts/targets/base/base.test.ts | 6 +++ .../css}/__snapshots__/css.test.ts.snap | 0 scripts/targets/css/css.test.ts | 6 +++ .../__snapshots__/tailwind.test.ts.snap | 46 +++++++++---------- scripts/targets/tailwind/tailwind.test.ts | 6 +++ tests/base.test.ts | 7 --- tests/css.test.ts | 6 --- tests/tailwind.test.ts | 6 --- 10 files changed, 59 insertions(+), 59 deletions(-) rename tests/errors.test.ts => scripts/builder.test.ts (82%) rename {tests => scripts/targets/base}/__snapshots__/base.test.ts.snap (100%) create mode 100644 scripts/targets/base/base.test.ts rename {tests => scripts/targets/css}/__snapshots__/css.test.ts.snap (100%) create mode 100644 scripts/targets/css/css.test.ts rename {tests => scripts/targets/tailwind}/__snapshots__/tailwind.test.ts.snap (100%) create mode 100644 scripts/targets/tailwind/tailwind.test.ts delete mode 100644 tests/base.test.ts delete mode 100644 tests/css.test.ts delete mode 100644 tests/tailwind.test.ts diff --git a/tests/errors.test.ts b/scripts/builder.test.ts similarity index 82% rename from tests/errors.test.ts rename to scripts/builder.test.ts index 3afa1a4..455ce02 100644 --- a/tests/errors.test.ts +++ b/scripts/builder.test.ts @@ -1,9 +1,10 @@ import { stub } from "@std/testing/mock"; import { assert, assertRejects } from "@std/assert"; import { sandbox } from "@lambdalisue/sandbox"; -import { testPaletteSource } from "./utils.ts"; -import base from "../scripts/targets/base/base.config.ts"; -import { build } from "../scripts/builder.ts"; + +import { testPaletteSource } from "../tests/utils.ts"; +import base from "./targets/base/base.config.ts"; +import { build } from "./builder.ts"; Deno.test("should abort and clean up if Deno.remove throws unexpect error", async () => { const errorMessage = "some Deno.remove error"; diff --git a/tests/__snapshots__/base.test.ts.snap b/scripts/targets/base/__snapshots__/base.test.ts.snap similarity index 100% rename from tests/__snapshots__/base.test.ts.snap rename to scripts/targets/base/__snapshots__/base.test.ts.snap index 8ae17ee..761eec7 100644 --- a/tests/__snapshots__/base.test.ts.snap +++ b/scripts/targets/base/__snapshots__/base.test.ts.snap @@ -13,6 +13,20 @@ snapshot[`index.js 1`] = ` ' `; +snapshot[`index.d.ts 1`] = ` +"declare namespace _default { + let red: { + 50: string; + 500: string; + }; + let orange: { + 100: string; + }; +} +export default _default; +" +`; + snapshot[`index.cjs 1`] = ` '"use strict"; module.exports = { @@ -27,17 +41,3 @@ module.exports = { Object.defineProperty(exports, "__esModule", { value: true }); ' `; - -snapshot[`index.d.ts 1`] = ` -"declare namespace _default { - let red: { - 50: string; - 500: string; - }; - let orange: { - 100: string; - }; -} -export default _default; -" -`; diff --git a/scripts/targets/base/base.test.ts b/scripts/targets/base/base.test.ts new file mode 100644 index 0000000..a90ecb1 --- /dev/null +++ b/scripts/targets/base/base.test.ts @@ -0,0 +1,6 @@ +import { expectBuildToMatchSnapshot } from "../../../tests/utils.ts"; +import base from "./base.config.ts"; + +Deno.test("build base target", async (t) => { + await expectBuildToMatchSnapshot(t, base); +}); diff --git a/tests/__snapshots__/css.test.ts.snap b/scripts/targets/css/__snapshots__/css.test.ts.snap similarity index 100% rename from tests/__snapshots__/css.test.ts.snap rename to scripts/targets/css/__snapshots__/css.test.ts.snap diff --git a/scripts/targets/css/css.test.ts b/scripts/targets/css/css.test.ts new file mode 100644 index 0000000..ccd0e45 --- /dev/null +++ b/scripts/targets/css/css.test.ts @@ -0,0 +1,6 @@ +import { expectBuildToMatchSnapshot } from "../../../tests/utils.ts"; +import css from "./css.config.ts"; + +Deno.test("build css target", async (t) => { + await expectBuildToMatchSnapshot(t, css); +}); diff --git a/tests/__snapshots__/tailwind.test.ts.snap b/scripts/targets/tailwind/__snapshots__/tailwind.test.ts.snap similarity index 100% rename from tests/__snapshots__/tailwind.test.ts.snap rename to scripts/targets/tailwind/__snapshots__/tailwind.test.ts.snap index f7cbabd..30ba67d 100644 --- a/tests/__snapshots__/tailwind.test.ts.snap +++ b/scripts/targets/tailwind/__snapshots__/tailwind.test.ts.snap @@ -16,6 +16,29 @@ snapshot[`index.css 1`] = ` " `; +snapshot[`index.cjs 1`] = ` +'"use strict"; + +module.exports = { + inherit: "inherit", + current: "currentColor", + transparent: "transparent", + black: "#000", + white: "#fff", + + red: { + 50: "oklch(0.988281 0.0046875 20 / )", + 500: "oklch(0.742188 0.151562 20 / )", + }, + orange: { + 100: "oklch(0.966797 0.0171875 43.3333 / )", + }, +}; + +Object.defineProperty(exports, "__esModule", { value: true }); +' +`; + snapshot[`index.d.ts 1`] = ` "declare namespace _default { let inherit: string; @@ -54,26 +77,3 @@ snapshot[`index.js 1`] = ` }; ' `; - -snapshot[`index.cjs 1`] = ` -'"use strict"; - -module.exports = { - inherit: "inherit", - current: "currentColor", - transparent: "transparent", - black: "#000", - white: "#fff", - - red: { - 50: "oklch(0.988281 0.0046875 20 / )", - 500: "oklch(0.742188 0.151562 20 / )", - }, - orange: { - 100: "oklch(0.966797 0.0171875 43.3333 / )", - }, -}; - -Object.defineProperty(exports, "__esModule", { value: true }); -' -`; diff --git a/scripts/targets/tailwind/tailwind.test.ts b/scripts/targets/tailwind/tailwind.test.ts new file mode 100644 index 0000000..a32c137 --- /dev/null +++ b/scripts/targets/tailwind/tailwind.test.ts @@ -0,0 +1,6 @@ +import { expectBuildToMatchSnapshot } from "../../../tests/utils.ts"; +import tailwind from "./tailwind.config.ts"; + +Deno.test("build tailwind target", async (t) => { + await expectBuildToMatchSnapshot(t, tailwind); +}); diff --git a/tests/base.test.ts b/tests/base.test.ts deleted file mode 100644 index a3e5d8c..0000000 --- a/tests/base.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { expectBuildToMatchSnapshot } from "./utils.ts"; -import base from "../scripts/targets/base/base.config.ts"; - -Deno.test("build base target", async (t) => { - await expectBuildToMatchSnapshot(t, base); -}); - diff --git a/tests/css.test.ts b/tests/css.test.ts deleted file mode 100644 index 5f4630a..0000000 --- a/tests/css.test.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectBuildToMatchSnapshot } from "./utils.ts"; -import css from "../scripts/targets/css/css.config.ts"; - -Deno.test("build css target", async (t) => { - await expectBuildToMatchSnapshot(t, css); -}); diff --git a/tests/tailwind.test.ts b/tests/tailwind.test.ts deleted file mode 100644 index 4b5eab6..0000000 --- a/tests/tailwind.test.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectBuildToMatchSnapshot } from "./utils.ts"; -import tailwind from "../scripts/targets/tailwind/tailwind.config.ts"; - -Deno.test("build tailwind target", async (t) => { - await expectBuildToMatchSnapshot(t, tailwind); -});