35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
|
|
import { describe, it, expect } from "vitest";
|
||
|
|
import * as fs from "node:fs";
|
||
|
|
import * as path from "node:path";
|
||
|
|
|
||
|
|
describe("store file extensions", () => {
|
||
|
|
it("test_store_files_use_svelte_ts_extension", () => {
|
||
|
|
const storesDir = path.resolve(__dirname);
|
||
|
|
const files = fs.readdirSync(storesDir);
|
||
|
|
|
||
|
|
// Find .ts files that are NOT .svelte.ts and NOT test files
|
||
|
|
const plainTsFiles = files.filter(
|
||
|
|
(f) =>
|
||
|
|
f.endsWith(".ts") &&
|
||
|
|
!f.endsWith(".svelte.ts") &&
|
||
|
|
!f.endsWith(".test.ts")
|
||
|
|
);
|
||
|
|
|
||
|
|
for (const file of plainTsFiles) {
|
||
|
|
const content = fs.readFileSync(path.join(storesDir, file), "utf-8");
|
||
|
|
expect(content).not.toMatch(
|
||
|
|
/\$state\s*[<(]/,
|
||
|
|
`${file} uses $state() but does not have .svelte.ts extension`
|
||
|
|
);
|
||
|
|
expect(content).not.toMatch(
|
||
|
|
/\$derived\s*[<(]/,
|
||
|
|
`${file} uses $derived() but does not have .svelte.ts extension`
|
||
|
|
);
|
||
|
|
expect(content).not.toMatch(
|
||
|
|
/\$effect\s*[<(]/,
|
||
|
|
`${file} uses $effect() but does not have .svelte.ts extension`
|
||
|
|
);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|