-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Josh Calder
committed
Feb 28, 2023
1 parent
0d73d57
commit 5a657b7
Showing
2 changed files
with
26 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,31 +61,20 @@ export function generateDataArray(map: (key: number) => any, range: number) { | |
|
||
export async function deleteAllData(projectDir: string) { | ||
const resolvedProjectDir = path.resolve(projectRoot, projectDir); | ||
/** | ||
* As of @prisma/[email protected] it appears that the prisma client runtime tries to resolve the path to the prisma schema | ||
* from process.cwd(). This is not always the project directory we want to run keystone from. | ||
* Here we mutate the process.cwd global with a fn that returns the project directory we expect, such that prisma | ||
* can retrieve the correct schema file. | ||
*/ | ||
const prevCwd = process.cwd; | ||
try { | ||
process.cwd = () => resolvedProjectDir; | ||
const { PrismaClient } = require(path.join( | ||
resolvedProjectDir, | ||
'node_modules/.testprisma/client' | ||
)); | ||
const prisma = new PrismaClient(); | ||
|
||
await prisma.$transaction( | ||
Object.values(prisma) | ||
.filter((x: any) => x?.deleteMany) | ||
.map((x: any) => x?.deleteMany?.({})) | ||
); | ||
|
||
await prisma.$disconnect(); | ||
} finally { | ||
process.cwd = prevCwd; | ||
} | ||
|
||
const { PrismaClient } = require(path.join( | ||
resolvedProjectDir, | ||
'node_modules/.testprisma/client' | ||
)); | ||
const prisma = new PrismaClient(); | ||
|
||
await prisma.$transaction( | ||
Object.values(prisma) | ||
.filter((x: any) => x?.deleteMany) | ||
.map((x: any) => x?.deleteMany?.({})) | ||
); | ||
|
||
await prisma.$disconnect(); | ||
} | ||
|
||
export const adminUITests = ( | ||
|
@@ -99,7 +88,7 @@ export const adminUITests = ( | |
let cleanupKeystoneProcess = () => {}; | ||
|
||
afterAll(async () => { | ||
await cleanupKeystoneProcess(); | ||
cleanupKeystoneProcess(); | ||
}); | ||
|
||
async function startKeystone(command: 'start' | 'dev') { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,28 +18,16 @@ export async function loadIndex(page: playwright.Page) { | |
} | ||
|
||
async function deleteAllData(projectDir: string) { | ||
/** | ||
* As of @prisma/[email protected] it appears that the prisma client runtime tries to resolve the path to the prisma schema | ||
* from process.cwd(). This is not always the project directory we want to run keystone from. | ||
* Here we mutate the process.cwd global with a fn that returns the project directory we expect, such that prisma | ||
* can retrieve the correct schema file. | ||
*/ | ||
const prevCwd = process.cwd; | ||
try { | ||
process.cwd = () => projectDir; | ||
const { PrismaClient } = require(path.join(projectDir, 'node_modules/.myprisma/client')); | ||
const prisma = new PrismaClient(); | ||
|
||
await prisma.$transaction( | ||
Object.values(prisma) | ||
.filter((x: any) => x?.deleteMany) | ||
.map((x: any) => x?.deleteMany?.({})) | ||
); | ||
|
||
await prisma.$disconnect(); | ||
} finally { | ||
process.cwd = prevCwd; | ||
} | ||
const { PrismaClient } = require(path.join(projectDir, 'node_modules/.myprisma/client')); | ||
const prisma = new PrismaClient(); | ||
|
||
await prisma.$transaction( | ||
Object.values(prisma) | ||
.filter((x: any) => x?.deleteMany) | ||
.map((x: any) => x?.deleteMany?.({})) | ||
); | ||
|
||
await prisma.$disconnect(); | ||
} | ||
|
||
const treeKill = promisify(_treeKill); | ||
|
@@ -79,7 +67,7 @@ export const exampleProjectTests = ( | |
let cleanupKeystoneProcess = () => {}; | ||
|
||
afterAll(async () => { | ||
await cleanupKeystoneProcess(); | ||
cleanupKeystoneProcess(); | ||
}); | ||
|
||
async function startKeystone(command: 'start' | 'dev') { | ||
|