Skip to content

Commit

Permalink
improved messaging on startup (#6617)
Browse files Browse the repository at this point in the history
* improved messaging on startup

* Update based on Tim's feedback

* fixing tests

* fix tests

* tests passing

Co-authored-by: Noviny <[email protected]>
  • Loading branch information
Noviny and Noviny authored Sep 27, 2021
1 parent e81947d commit 11fb46c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-vans-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': patch
---

Improved messaging around keystone startup a little
8 changes: 7 additions & 1 deletion packages/keystone/src/scripts/run/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,14 @@ export const dev = async (cwd: string, shouldDropDatabase: boolean) => {
});
const server = app.listen(port, (err?: any) => {
if (err) throw err;
console.log(`⭐️ Dev Server Ready on http://localhost:${port}`);
// We start initialising Keystone after the dev server is ready,
console.log(`⭐️ Dev Server Starting on http://localhost:${port}`);
console.log(
`⭐️ GraphQL API Starting on http://localhost:${port}${
config.graphql?.path || '/api/graphql'
}`
);
// Don't start initialising Keystone until the dev server is ready,
// otherwise it slows down the first response significantly
initKeystone()
.then(() => {
Expand Down
76 changes: 45 additions & 31 deletions packages/keystone/src/scripts/tests/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ model Todo {
`);

expect(recording()).toEqual(`✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
✨ sqlite database "app.db" created at file:./app.db
✨ Your database is now in sync with your schema. Done in 0ms
Expand All @@ -111,14 +112,15 @@ describe('useMigrations: false', () => {
await setupAndStopDevServerForMigrations(tmp);

expect(recording()).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
✨ Generating GraphQL and Prisma schemas
✨ The database is already in sync with the Prisma schema.
✨ Connecting to the database
✨ Creating server
✅ GraphQL API ready"
`);
"✨ Starting Keystone
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
✨ The database is already in sync with the Prisma schema.
✨ Connecting to the database
✨ Creating server
✅ GraphQL API ready"
`);
});
test('warns when dropping field that has data in it', async () => {
const prevCwd = await setupInitialProjectWithoutMigrations();
Expand Down Expand Up @@ -151,19 +153,20 @@ describe('useMigrations: false', () => {
"
`);
expect(recording()).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
✨ Generating GraphQL and Prisma schemas
"✨ Starting Keystone
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
⚠️ Warnings:
⚠️ Warnings:
• You are about to drop the column \`title\` on the \`Todo\` table, which still contains 1 non-null values.
Prompt: Do you want to continue? Some data will be lost. true
✨ Your database is now in sync with your schema. Done in 0ms
✨ Connecting to the database
✨ Creating server
✅ GraphQL API ready"
`);
• You are about to drop the column \`title\` on the \`Todo\` table, which still contains 1 non-null values.
Prompt: Do you want to continue? Some data will be lost. true
✨ Your database is now in sync with your schema. Done in 0ms
✨ Connecting to the database
✨ Creating server
✅ GraphQL API ready"
`);
});
test('exits when refusing data loss prompt', async () => {
const prevCwd = await setupInitialProjectWithoutMigrations();
Expand Down Expand Up @@ -198,7 +201,8 @@ describe('useMigrations: false', () => {
`);
expect(recording()).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
⚠️ Warnings:
Expand All @@ -225,7 +229,8 @@ describe('useMigrations: false', () => {

expect(recording()).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
✨ Your database has been reset
✨ Your database is now in sync with your schema. Done in 0ms
Expand Down Expand Up @@ -268,7 +273,8 @@ CREATE TABLE "Todo" (
`);

expect(recording().replace(migrationName, 'migration_name')).toEqual(`✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
✨ sqlite database "app.db" created at file:./app.db
✨ There has been a change to your Keystone schema that requires a migration
Expand Down Expand Up @@ -345,7 +351,8 @@ describe('useMigrations: true', () => {

expect(recording().replace(migrationName, 'migration_name')).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
✨ There has been a change to your Keystone schema that requires a migration
Expand Down Expand Up @@ -418,7 +425,8 @@ describe('useMigrations: true', () => {

expect(recording().replace(migrationName, 'migration_name')).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
✨ There has been a change to your Keystone schema that requires a migration
Expand Down Expand Up @@ -480,7 +488,8 @@ describe('useMigrations: true', () => {
.replace(oldMigrationName, 'old_migration_name')
).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
- Drift detected: Your database schema is not in sync with your migration history.
Expand Down Expand Up @@ -527,7 +536,8 @@ describe('useMigrations: true', () => {

expect(recording().replace(oldMigrationName, 'old_migration_name')).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
- Drift detected: Your database schema is not in sync with your migration history.
Expand Down Expand Up @@ -605,7 +615,8 @@ describe('useMigrations: true', () => {

expect(recording().replace(migrationName!, 'migration_name')).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
✨ There has been a change to your Keystone schema that requires a migration
Expand Down Expand Up @@ -643,7 +654,8 @@ describe('useMigrations: true', () => {

expect(recording().replace(migrationName, 'migration_name')).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
✨ sqlite database \\"app.db\\" created at file:./app.db
✨ The following migration(s) have been applied:
Expand Down Expand Up @@ -676,7 +688,8 @@ describe('useMigrations: true', () => {

expect(recording().replace(migrationName, 'migration_name')).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
✨ Your database has been reset
✨ The following migration(s) have been applied:
Expand All @@ -697,7 +710,8 @@ describe('useMigrations: true', () => {

expect(recording()).toMatchInlineSnapshot(`
"✨ Starting Keystone
⭐️ Dev Server Ready on http://localhost:3000
⭐️ Dev Server Starting on http://localhost:3000
⭐️ GraphQL API Starting on http://localhost:3000/api/graphql
✨ Generating GraphQL and Prisma schemas
✨ Your database is up to date, no migrations need to be created or applied
✨ Connecting to the database
Expand Down

0 comments on commit 11fb46c

Please sign in to comment.