From 9ba62ea2eb80864b292c770ec74a5d700711bf94 Mon Sep 17 00:00:00 2001 From: Josh Calder Date: Mon, 14 Aug 2023 18:12:32 +1000 Subject: [PATCH] Fix Prisma test using `--frozen` (#8767) --- tests/cli-tests/artifacts.test.ts | 48 ++++++++++++++++++++---------- tests/cli-tests/migrations.test.ts | 3 +- tests/cli-tests/prisma.test.ts | 12 ++++---- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/tests/cli-tests/artifacts.test.ts b/tests/cli-tests/artifacts.test.ts index aae89e431f4..abceb042754 100644 --- a/tests/cli-tests/artifacts.test.ts +++ b/tests/cli-tests/artifacts.test.ts @@ -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'] @@ -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"`) }) @@ -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"`) }) @@ -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"`) }) diff --git a/tests/cli-tests/migrations.test.ts b/tests/cli-tests/migrations.test.ts index 9e7bdff40b9..56c1624ebfd 100644 --- a/tests/cli-tests/migrations.test.ts +++ b/tests/cli-tests/migrations.test.ts @@ -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 diff --git a/tests/cli-tests/prisma.test.ts b/tests/cli-tests/prisma.test.ts index 5bb0a092dd7..884d3515525 100644 --- a/tests/cli-tests/prisma.test.ts +++ b/tests/cli-tests/prisma.test.ts @@ -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) @@ -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 @@ -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 @@ -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" `)