Initial Commit
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* dist-asserts — regression test that exercises the BUILT artifact
|
||||
* (`dist/index.js`), not the source.
|
||||
*
|
||||
* Guards against the data:URL globalSetup bug fixed by
|
||||
* `testing-integration-build-fix`: Vite library mode previously inlined
|
||||
* `new URL("../setup/global-setup.js", import.meta.url).pathname` as a
|
||||
* `data:video/mp2t;base64,…` URL, which Vitest could not load. Any future
|
||||
* refactor that re-introduces an asset-intercepted URL expression in the
|
||||
* build output will fail this test.
|
||||
*
|
||||
* Runs after `build` because turbo declares `test.dependsOn: ["build"]`.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
import { existsSync } from "node:fs";
|
||||
import { isAbsolute } from "node:path";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import type { ServiceFixture } from "../src/fixture/service-fixture.js";
|
||||
|
||||
interface StubConfig extends Record<string, unknown> {
|
||||
answer: number;
|
||||
}
|
||||
|
||||
const stubFixture: ServiceFixture<StubConfig> = {
|
||||
name: "stub",
|
||||
async start(): Promise<StubConfig> {
|
||||
return { answer: 42 };
|
||||
},
|
||||
async stop(): Promise<void> {},
|
||||
async healthCheck(): Promise<boolean> {
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
interface DistModule {
|
||||
createIntegrationSetup: (
|
||||
fixtures: Record<string, ServiceFixture<StubConfig>>
|
||||
) => { globalSetup: string; inject: unknown };
|
||||
}
|
||||
|
||||
async function loadDist(): Promise<DistModule> {
|
||||
return (await import("../dist/index.js")) as unknown as DistModule;
|
||||
}
|
||||
|
||||
describe("dist artifact: createIntegrationSetup.globalSetup", () => {
|
||||
it("returns an absolute filesystem path that exists on disk", async () => {
|
||||
const { createIntegrationSetup } = await loadDist();
|
||||
const result = createIntegrationSetup({ stub: stubFixture });
|
||||
|
||||
expect(typeof result.globalSetup).toBe("string");
|
||||
expect(result.globalSetup.length).toBeGreaterThan(0);
|
||||
expect(isAbsolute(result.globalSetup)).toBe(true);
|
||||
expect(existsSync(result.globalSetup)).toBe(true);
|
||||
});
|
||||
|
||||
it("MUST NOT return a data: / blob: / non-file URL scheme", async () => {
|
||||
const { createIntegrationSetup } = await loadDist();
|
||||
const result = createIntegrationSetup({ stub: stubFixture });
|
||||
|
||||
expect(result.globalSetup.startsWith("data:")).toBe(false);
|
||||
expect(result.globalSetup.startsWith("blob:")).toBe(false);
|
||||
expect(result.globalSetup.startsWith("http:")).toBe(false);
|
||||
expect(result.globalSetup.startsWith("https:")).toBe(false);
|
||||
});
|
||||
|
||||
it("globalSetup ends with the expected filename", async () => {
|
||||
const { createIntegrationSetup } = await loadDist();
|
||||
const result = createIntegrationSetup({ stub: stubFixture });
|
||||
|
||||
// Tolerant of POSIX (/) and Windows (\) path separators.
|
||||
expect(
|
||||
result.globalSetup.endsWith("setup/global-setup.js") ||
|
||||
result.globalSetup.endsWith("setup\\global-setup.js")
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user