34 lines
1003 B
TypeScript
34 lines
1003 B
TypeScript
import { readdirSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
function collectReservedRouteTestFiles(directory: string): string[] {
|
|
const entries = readdirSync(directory, { withFileTypes: true });
|
|
const reservedTestFiles: string[] = [];
|
|
|
|
for (const entry of entries) {
|
|
const entryPath = join(directory, entry.name);
|
|
|
|
if (entry.isDirectory()) {
|
|
reservedTestFiles.push(...collectReservedRouteTestFiles(entryPath));
|
|
continue;
|
|
}
|
|
|
|
if (!entry.name.startsWith('+')) continue;
|
|
if (!entry.name.includes('.test.') && !entry.name.includes('.spec.')) continue;
|
|
|
|
reservedTestFiles.push(entryPath);
|
|
}
|
|
|
|
return reservedTestFiles;
|
|
}
|
|
|
|
describe('SvelteKit route file conventions', () => {
|
|
it('does not place test files in reserved +prefixed route filenames', () => {
|
|
const routeDirectory = import.meta.dirname;
|
|
const reservedTestFiles = collectReservedRouteTestFiles(routeDirectory);
|
|
|
|
expect(reservedTestFiles).toEqual([]);
|
|
});
|
|
});
|