mirror of
https://github.com/zenstackhq/zenstack
synced 2026-05-24 10:08:55 +00:00
* fix: prisma plugin not respecting `zenstack.output` * chore: add test for #295 --------- Co-authored-by: = <=>
81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { createProject, runCli } from '../utils';
|
|
|
|
describe('Core plugins tests', () => {
|
|
it('can automatically generate a TypeScript schema with default output', () => {
|
|
const workDir = createProject(`
|
|
model User {
|
|
id String @id @default(cuid())
|
|
}
|
|
`);
|
|
runCli('generate', workDir);
|
|
expect(fs.existsSync(path.join(workDir, 'zenstack/schema.ts'))).toBe(true);
|
|
});
|
|
|
|
it('can automatically generate a TypeScript schema with custom output', () => {
|
|
const workDir = createProject(`
|
|
plugin typescript {
|
|
provider = '@core/typescript'
|
|
output = '../generated-schema'
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
}
|
|
`);
|
|
runCli('generate', workDir);
|
|
expect(fs.existsSync(path.join(workDir, 'generated-schema/schema.ts'))).toBe(true);
|
|
});
|
|
|
|
it('can generate a Prisma schema with default output', () => {
|
|
const workDir = createProject(`
|
|
plugin prisma {
|
|
provider = '@core/prisma'
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
}
|
|
`);
|
|
runCli('generate', workDir);
|
|
expect(fs.existsSync(path.join(workDir, 'zenstack/schema.prisma'))).toBe(true);
|
|
});
|
|
|
|
it('can generate a Prisma schema with custom output', () => {
|
|
const workDir = createProject(`
|
|
plugin prisma {
|
|
provider = '@core/prisma'
|
|
output = '../prisma/schema.prisma'
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
}
|
|
`);
|
|
runCli('generate', workDir);
|
|
expect(fs.existsSync(path.join(workDir, 'prisma/schema.prisma'))).toBe(true);
|
|
});
|
|
|
|
it('can generate a Prisma schema with custom output relative to zenstack.output', () => {
|
|
const workDir = createProject(`
|
|
plugin prisma {
|
|
provider = '@core/prisma'
|
|
output = './schema.prisma'
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
}
|
|
`);
|
|
|
|
const pkgJson = JSON.parse(fs.readFileSync(path.join(workDir, 'package.json'), 'utf8'));
|
|
pkgJson.zenstack = {
|
|
output: './relative',
|
|
};
|
|
fs.writeFileSync(path.join(workDir, 'package.json'), JSON.stringify(pkgJson, null, 2));
|
|
runCli('generate', workDir);
|
|
expect(fs.existsSync(path.join(workDir, 'relative/schema.prisma'))).toBe(true);
|
|
});
|
|
});
|