diff --git a/Justfile b/Justfile index 9f62128..6b05875 100644 --- a/Justfile +++ b/Justfile @@ -17,7 +17,8 @@ preview: bunx --bun concurrently --kill-others "rye run sanic server --port 8070 --host 0.0.0.0" "bunx --bun vite preview --port 8071 --host 0.0.0.0" test: - bun test #TODO: proper test setup + bun test + rye test lint: bunx --bun prettier --check . diff --git a/bun-svelte.ts b/bun-svelte.ts new file mode 100644 index 0000000..4977a8d --- /dev/null +++ b/bun-svelte.ts @@ -0,0 +1,24 @@ +import { plugin } from "bun" + +await plugin({ + name: "svelte loader", + async setup(build) { + const { compile } = await import("svelte/compiler") + + // when a .svelte file is imported... + build.onLoad({ filter: /\.svelte$/ }, async ({ path }) => { + // read and compile it with the Svelte compiler + const file = await Bun.file(path).text() + const contents = compile(file, { + filename: path, + generate: "client", + }).js.code + + // and return the compiled source code as "js" + return { + contents, + loader: "js", + } + }) + }, +}) diff --git a/bun.lockb b/bun.lockb index b745217..0c30887 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/bun_setup.ts b/bun_setup.ts new file mode 100644 index 0000000..dcdf8db --- /dev/null +++ b/bun_setup.ts @@ -0,0 +1,40 @@ +import { GlobalRegistrator } from "@happy-dom/global-registrator" +import { vitePreprocess } from "@sveltejs/vite-plugin-svelte" +import { plugin } from "bun" +import { afterEach, expect } from "bun:test" +import { cleanup } from "@testing-library/svelte" +import * as matchers from "@testing-library/jest-dom/matchers" + +expect.extend(matchers) + +afterEach(() => { + cleanup() +}) + +const oldConsole = console +GlobalRegistrator.register() +window.console = oldConsole + +await plugin({ + name: "svelte loader", + async setup(builder) { + const { compile, preprocess } = await import("svelte/compiler") + const { readFileSync } = await import("fs") + + builder.onLoad({ filter: /\.svelte$/ }, async ({ path }) => { + return { + // Use the preprocessor of your choice. + contents: compile( + await preprocess(readFileSync(path, "utf8"), vitePreprocess()).then( + (processed) => processed.code, + ), + { + filename: path, + generate: "client", + }, + ).js.code, + loader: "js", + } + }) + }, +}) diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 0000000..3ff377f --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,2 @@ +[test] +preload = ["./bun_setup.ts"] \ No newline at end of file diff --git a/happydom.ts b/happydom.ts new file mode 100644 index 0000000..ce01084 --- /dev/null +++ b/happydom.ts @@ -0,0 +1,3 @@ +import { GlobalRegistrator } from "@happy-dom/global-registrator" + +GlobalRegistrator.register() diff --git a/matchers.d.ts b/matchers.d.ts new file mode 100644 index 0000000..0f19f03 --- /dev/null +++ b/matchers.d.ts @@ -0,0 +1,7 @@ +import { AsymmetricMatchers, Matchers } from "bun:test" +import type { TestingLibraryMatchers } from "@testing-library/jest-dom/matchers" + +declare module "bun:test" { + interface Matchers extends TestingLibraryMatchers {} + interface AsymmetricMatchers extends TestingLibraryMatchers {} +} diff --git a/package.json b/package.json index 05e4fcf..d69720a 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,17 @@ "private": true, "license": "ISC", "devDependencies": { + "@happy-dom/global-registrator": "^15.7.4", "@sveltejs/adapter-auto": "^3.2.5", "@sveltejs/kit": "^2.7.1", "@sveltejs/vite-plugin-svelte": "^4.0.0-next.6", + "@testing-library/dom": "^10.4.0", + "@testing-library/jest-dom": "^6.6.2", + "@testing-library/svelte": "^5.2.4", + "@types/bun": "^1.1.11", "@types/eslint": "^9.6.1", "concurrently": "^9.0.1", - "eslint": "^9.12.0", + "eslint": "^9.13.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.45.1", "globals": "^15.11.0", @@ -19,9 +24,8 @@ "svelte-check": "^4.0.5", "tslib": "^2.8.0", "typescript": "^5.6.3", - "typescript-eslint": "^8.9.0", - "vite": "^5.4.9", - "vitest": "^2.1.3" + "typescript-eslint": "^8.10.0", + "vite": "^5.4.9" }, "type": "module" } diff --git a/pyproject.toml b/pyproject.toml index 825a000..ade0db2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,11 +18,20 @@ build-backend = "hatchling.build" [tool.rye] managed = true -dev-dependencies = [] +dev-dependencies = [ + "pytest>=8.3.3", +] [tool.ruff] format.indent-style = "tab" +[tool.pytest.ini_options] +minversion = "6.0" +addopts = "-ra -q" +testpaths = [ + "src", +] + [tool.hatch.metadata] allow-direct-references = true diff --git a/requirements-dev.lock b/requirements-dev.lock index 3007e31..25a9afc 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -17,12 +17,19 @@ html5tagger==1.3.0 # via tracerite httptools==0.6.2 # via sanic +iniconfig==2.0.0 + # via pytest multidict==6.1.0 # via sanic mypy==1.12.0 # via aigis mypy-extensions==1.0.0 # via mypy +packaging==24.1 + # via pytest +pluggy==1.5.0 + # via pytest +pytest==8.3.3 sanic==24.6.0 # via aigis sanic-routing==23.12.0 diff --git a/src/aigis/test_1plus2.py b/src/aigis/test_1plus2.py new file mode 100644 index 0000000..e5207d7 --- /dev/null +++ b/src/aigis/test_1plus2.py @@ -0,0 +1,5 @@ +import pytest + + +def test_1plus2(): + assert 1 + 2 == 3 diff --git a/src/index.test.ts b/src/index.test.ts index 316e4cd..824c58c 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,7 +1,17 @@ -import { describe, it, expect } from "vitest" +import { describe, it, expect } from "bun:test" +import page from "./routes/+page.svelte" +import { screen, render } from "@testing-library/svelte" describe("sum test", () => { it("adds 1 + 2 to equal 3", () => { expect(1 + 2).toBe(3) }) }) + +describe("root page test", () => { + it("has the correct header", async () => { + render(page) + const header = await screen.findByRole("heading") + expect(header).toBeDefined() + }) +}) diff --git a/testing-library.ts b/testing-library.ts new file mode 100644 index 0000000..9fffb23 --- /dev/null +++ b/testing-library.ts @@ -0,0 +1,9 @@ +import { afterEach, expect } from "bun:test" +import { cleanup } from "@testing-library/svelte" +import * as matchers from "@testing-library/jest-dom/matchers" + +expect.extend(matchers) + +afterEach(() => { + cleanup() +}) diff --git a/vite.config.ts b/vite.config.ts index 04fd695..7b72a3c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,11 +1,8 @@ import { sveltekit } from "@sveltejs/kit/vite" -import { defineConfig } from "vitest/config" +import { defineConfig } from "vite" export default defineConfig({ plugins: [sveltekit()], - test: { - include: ["src/**/*.{test,spec}.{js,ts}"], - }, server: { watch: { ignored: ["**/__pycache__/**", "**/.*_cache/**", "**/.venv/**", "**/.direnv/**"],