Skip to content

Commit 49dfb8c

Browse files
committed
test: Create temp directory in place
1 parent dd76fc7 commit 49dfb8c

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/test/test-generate.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { exec } from 'child_process';
55
import crypto from 'crypto';
66
import fs from 'graceful-fs';
77
import { castArray, uniq } from 'lodash';
8-
import cachePath from 'temp-dir';
98
import { ImportSpecifierStructure, Project } from 'ts-morph';
109

1110
import { generate } from '../generate';
@@ -107,6 +106,20 @@ export async function testGenerate(args: {
107106
return { project, sourceFiles };
108107
}
109108

109+
async function prepareCachePath(): Promise<string> {
110+
const base = process.env.CI
111+
? process.cwd()
112+
: await import('temp-dir').then(x => x.default);
113+
114+
const result = `${base}/~prisma-test`;
115+
116+
if (!fs.existsSync(result)) {
117+
fs.mkdirSync(result, { recursive: true });
118+
}
119+
120+
return result;
121+
}
122+
110123
/**
111124
* Get generator options after run prisma generate.
112125
*/
@@ -127,10 +140,7 @@ async function createGeneratorOptions(
127140
`;
128141
// eslint-disable-next-line prefer-rest-params
129142
const hash = createHash(generatorVersion, schemaHeader, arguments);
130-
const prismaTestPath = `${cachePath}/prisma-test`;
131-
if (!fs.existsSync(prismaTestPath)) {
132-
fs.mkdirSync(prismaTestPath);
133-
}
143+
const prismaTestPath = await prepareCachePath();
134144
const cacheFile = `${prismaTestPath}/options-${hash}.js`;
135145
if (!fs.existsSync(cacheFile)) {
136146
const schemaFile = `${prismaTestPath}/schema-${hash}.prisma`;
@@ -154,7 +164,7 @@ async function createGeneratorOptions(
154164
throw new Error('Generate error');
155165
}
156166
proc.stdout?.pipe(process.stdout);
157-
proc.stderr?.pipe(process.stderr);
167+
proc.stderr.pipe(process.stdout);
158168
proc.on('error', reject);
159169
proc.on('exit', code => {
160170
code === 0 ? resolve(0) : reject(code);

0 commit comments

Comments
 (0)