MCPcopy Index your code
hub / github.com/prisma/prisma-examples / testSqliteExample

Function testSqliteExample

tests/fixtures.ts:71–127  ·  view source on GitHub ↗
(
  examplePath: string,
  options?: { generateSql?: boolean; env?: NodeJS.ProcessEnv; runBuild?: boolean }
)

Source from the content-addressed store, hash-verified

69
70// For SQLite examples that don't need @prisma/dev server
71export function testSqliteExample(
72 examplePath: string,
73 options?: { generateSql?: boolean; env?: NodeJS.ProcessEnv; runBuild?: boolean }
74) {
75 describe(examplePath, () => {
76 test('prisma setup', async () => {
77 const cwd = path.join(process.cwd(), examplePath)
78 const env = { ...process.env, ...options?.env }
79 const packageJsonPath = path.join(cwd, 'package.json')
80 const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
81 const scripts = packageJson.scripts ?? {}
82
83 // Remove existing SQLite databases to ensure clean state
84 const dbPaths = [path.join(cwd, 'dev.db'), path.join(cwd, 'prisma', 'dev.db')]
85 for (const dbPath of dbPaths) {
86 if (fs.existsSync(dbPath)) {
87 fs.unlinkSync(dbPath)
88 }
89 }
90
91 console.log(`\n[${examplePath}] Installing dependencies...`)
92 await execa('npm', ['install'], { cwd, env, stdio: 'inherit' })
93
94 console.log(`\n[${examplePath}] Running prisma generate...`)
95 await execa('npx', ['prisma', 'generate'], { cwd, env, stdio: 'inherit' })
96
97 console.log(`\n[${examplePath}] Running prisma db push...`)
98 await execa('npx', ['prisma', 'db', 'push', '--accept-data-loss'], {
99 cwd,
100 env,
101 stdio: 'inherit',
102 })
103
104 if (options?.generateSql) {
105 console.log(`\n[${examplePath}] Running prisma generate --sql...`)
106 await execa('npx', ['prisma', 'generate', '--sql'], { cwd, env, stdio: 'inherit' })
107 }
108
109 // Check for seed in prisma.config.ts (Prisma v7+)
110 const configPath = path.join(cwd, 'prisma.config.ts')
111 if (fs.existsSync(configPath)) {
112 const content = fs.readFileSync(configPath, 'utf-8')
113 if (content.includes('seed:')) {
114 console.log(`\n[${examplePath}] Running prisma db seed...`)
115 await execa('npx', ['prisma', 'db', 'seed'], { cwd, env, stdio: 'inherit' })
116 }
117 }
118
119 if (options?.runBuild && scripts.build) {
120 console.log(`\n[${examplePath}] Running build...`)
121 await execa('npm', ['run', 'build'], { cwd, env, stdio: 'inherit' })
122 }
123
124 console.log(`\n[${examplePath}] Completed successfully!`)
125 })
126 })
127}

Callers 3

databases.test.tsFile · 0.85
orm.test.tsFile · 0.85

Calls 1

logMethod · 0.65

Tested by

no test coverage detected