Skip to content

Commit

Permalink
Fix Prisma test using --frozen (#8767)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Calder authored and dcousens committed Mar 28, 2024
1 parent b065c83 commit d9a2505
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
48 changes: 33 additions & 15 deletions tests/cli-tests/artifacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,34 @@ import {
testdir,
} from './utils'

describe.each(['postinstall', ['build', '--frozen'], ['prisma', 'migrate', 'status']])(
'%s',
command => {
test('logs an error and exits with 1 when the schemas do not exist', async () => {
const tmp = await testdir({
...symlinkKeystoneDeps,
'keystone.js': basicKeystoneConfig,
})
const recording = recordConsole()
await expect(runCommand(tmp, command)).rejects.toEqual(new ExitError(1))
expect(recording()).toMatchInlineSnapshot(
`"Your Prisma and GraphQL schemas are not up to date"`
)
describe.each(['postinstall', ['build', '--frozen']])('%s', command => {
test('logs an error and exits with 1 when the schemas do not exist', async () => {
const tmp = await testdir({
...symlinkKeystoneDeps,
'keystone.js': basicKeystoneConfig,
})

const recording = recordConsole()
await expect(runCommand(tmp, command)).rejects.toEqual(new ExitError(1))

expect(recording()).toMatchInlineSnapshot(`"Your Prisma and GraphQL schemas are not up to date"`)
})
})

describe('prisma migrate status', () => {
test('logs an error and exits with 1 when the schemas do not exist', async () => {
const tmp = await testdir({
...symlinkKeystoneDeps,
'keystone.js': basicKeystoneConfig,
})
}
)
await expect(runCommand(tmp, ['build', '--no-ui', '--frozen'])).rejects.toEqual(new ExitError(1))

const recording = recordConsole()
await expect(runCommand(tmp, ['prisma', '--frozen', 'migrate', 'status'])).rejects.toEqual(new ExitError(1))

expect(recording()).toMatchInlineSnapshot(`"Your Prisma and GraphQL schemas are not up to date"`)
})
})

const schemasMatch = ['schema.prisma', 'schema.graphql']

Expand All @@ -37,9 +49,11 @@ describe('postinstall', () => {
...symlinkKeystoneDeps,
'keystone.js': basicKeystoneConfig,
})

const recording = recordConsole()
await runCommand(tmp, ['postinstall', '--fix'])
const files = await getFiles(tmp, schemasMatch)

expect(files).toEqual(await getFiles(`${__dirname}/fixtures/basic-project`, schemasMatch))
expect(recording()).toMatchInlineSnapshot(`"? Generated GraphQL and Prisma schemas"`)
})
Expand All @@ -50,9 +64,11 @@ describe('postinstall', () => {
...schemas,
'keystone.js': basicKeystoneConfig,
})

const recording = recordConsole()
await runCommand(tmp, 'postinstall')
const files = await getFiles(tmp, schemasMatch)

expect(files).toEqual(await getFiles(`${__dirname}/fixtures/basic-project`, schemasMatch))
expect(recording()).toMatchInlineSnapshot(`"? GraphQL and Prisma schemas are up to date"`)
})
Expand All @@ -63,8 +79,10 @@ describe('postinstall', () => {
...schemas,
'keystone.js': basicKeystoneConfig,
})

const recording = recordConsole()
await runCommand(tmp, 'postinstall')

expect(await getFiles(tmp, ['node_modules/.keystone/**/*'])).toMatchSnapshot()
expect(recording()).toMatchInlineSnapshot(`"? GraphQL and Prisma schemas are up to date"`)
})
Expand Down
3 changes: 2 additions & 1 deletion tests/cli-tests/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ describe('useMigrations: false', () => {
}

expect(recording()).toMatchInlineSnapshot(`
"? Starting Keystone
"? Generated GraphQL and Prisma schemas
? Starting Keystone
? Server listening on :3000 (http://localhost:3000/)
? GraphQL API available at /api/graphql
? Generating GraphQL and Prisma schemas
Expand Down
12 changes: 7 additions & 5 deletions tests/cli-tests/prisma.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ test('keystone prisma exits with the same code as the prisma child process exits
cwd: tmp,
})
expect(result.all!.replace(/[^ -~\n]/g, '?')).toMatchInlineSnapshot(`
"
"? Generated GraphQL and Prisma schemas
! Unknown command "bad-thing"
? Prisma is a modern DB toolkit to query, migrate and model your database (https://prisma.io)
Expand All @@ -33,7 +34,7 @@ test('keystone prisma exits with the same code as the prisma child process exits
studio Browse your data with Prisma Studio
validate Validate your Prisma schema
format Format your Prisma schema
Flags
--preview-feature Run Preview Prisma commands
Expand All @@ -51,7 +52,7 @@ test('keystone prisma exits with the same code as the prisma child process exits
Create migrations from your Prisma schema, apply them to the database, generate artifacts (e.g. Prisma Client)
$ prisma migrate dev
Pull the schema from an existing database, updating the Prisma schema
$ prisma db pull
Expand Down Expand Up @@ -79,8 +80,9 @@ test('keystone prisma uses the db url in the keystone config', async () => {
all: true,
cwd: tmp,
})
expect(result.all).toMatchInlineSnapshot(`
"Prisma schema loaded from schema.prisma
expect(result.all!.replace(/[^ -~\n]/g, '?')).toMatchInlineSnapshot(`
"? Generated GraphQL and Prisma schemas
Prisma schema loaded from schema.prisma
Datasource "sqlite": SQLite database "app.db" at "file:./app.db"
Error: P1003: Database app.db does not exist at ./app.db"
`)
Expand Down

0 comments on commit d9a2505

Please sign in to comment.