MCPcopy Index your code
hub / github.com/zenstackhq/zenstack / createTestProject

Function createTestProject

packages/testtools/src/project.ts:5–72  ·  view source on GitHub ↗
(zmodelContent?: string)

Source from the content-addressed store, hash-verified

3import tmp from 'tmp';
4
5export function createTestProject(zmodelContent?: string) {
6 const { name: workDir } = tmp.dirSync({ unsafeCleanup: true });
7
8 fs.mkdirSync(path.join(workDir, 'node_modules'));
9
10 // symlink all entries from "node_modules"
11 const nodeModules = fs.readdirSync(path.join(__dirname, '../node_modules'));
12 for (const entry of nodeModules) {
13 if (entry.startsWith('@zenstackhq')) {
14 continue;
15 }
16 fs.symlinkSync(
17 path.join(__dirname, '../node_modules', entry),
18 path.join(workDir, 'node_modules', entry),
19 'dir',
20 );
21 }
22
23 // in addition, symlink zenstack packages
24 const zenstackPackages = ['language', 'sdk', 'schema', 'orm', 'cli'];
25 fs.mkdirSync(path.join(workDir, 'node_modules/@zenstackhq'));
26 for (const pkg of zenstackPackages) {
27 fs.symlinkSync(
28 path.join(__dirname, `../../${pkg}`),
29 path.join(workDir, `node_modules/@zenstackhq/${pkg}`),
30 'dir',
31 );
32 }
33
34 fs.writeFileSync(
35 path.join(workDir, 'package.json'),
36 JSON.stringify(
37 {
38 name: 'test',
39 version: '1.0.0',
40 type: 'module',
41 },
42 null,
43 4,
44 ),
45 );
46
47 fs.writeFileSync(
48 path.join(workDir, 'tsconfig.json'),
49 JSON.stringify(
50 {
51 compilerOptions: {
52 module: 'ESNext',
53 target: 'ESNext',
54 moduleResolution: 'Bundler',
55 esModuleInterop: true,
56 skipLibCheck: true,
57 strict: true,
58 types: ['node'],
59 },
60 include: ['**/*.ts'],
61 },
62 null,

Callers 6

createProjectFunction · 0.90
createTestClientFunction · 0.90
generateTsSchemaFunction · 0.90
regression.test.tsFile · 0.90
import.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected