import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, test } from "vitest";

const source = readFileSync(
	join(process.cwd(), "scripts/copy-resources.cjs"),
	"utf-8",
);

describe("copy-resources dev runtime contract", () => {
	test("copy_resources_when_run_from_other_cwd_uses_repo_root_paths", () => {
		assert.match(source, /const root = resolve\(__dirname, "\.\."\)/);
		assert.match(source, /rmSync\(distResources/);
		assert.match(source, /cwd: root/);
		assert.match(source, /copyNonTsFiles\(srcResources, distResources\)/);
	});

	test("copy_resources_when_source_js_exists_does_not_overwrite_compiled_output", () => {
		assert.match(source, /entry\.name\.endsWith\("\.js"\)/);
		assert.match(source, /entry\.name\.endsWith\("\.jsx"\)/);
	});
});
