test(engine): guard against React/DOM imports in engine
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
import { readdir, readFile } from 'node:fs/promises';
|
||||||
|
import { join } from 'node:path';
|
||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
const ENGINE_DIR = join(import.meta.dirname, '..');
|
||||||
|
const FORBIDDEN = [/from\s+['"]react/, /from\s+['"]react-dom/, /from\s+['"]zustand/];
|
||||||
|
|
||||||
|
async function engineSourceFiles(): Promise<string[]> {
|
||||||
|
const entries = await readdir(ENGINE_DIR, { withFileTypes: true });
|
||||||
|
return entries
|
||||||
|
.filter((e) => e.isFile() && e.name.endsWith('.ts') && !e.name.endsWith('.test.ts'))
|
||||||
|
.map((e) => join(ENGINE_DIR, e.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('engine purity', () => {
|
||||||
|
it('does not import React, react-dom, or Zustand', async () => {
|
||||||
|
const files = await engineSourceFiles();
|
||||||
|
expect(files.length).toBeGreaterThan(0);
|
||||||
|
for (const file of files) {
|
||||||
|
const source = await readFile(file, 'utf8');
|
||||||
|
for (const pattern of FORBIDDEN) {
|
||||||
|
expect(source, `${file} must stay free of ${pattern}`).not.toMatch(pattern);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user