Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): add console error log for caching on top of error (#18759)
- Loading branch information
Showing
3 changed files
with
70 additions
and
16 deletions.
There are no files selected for viewing
52 changes: 46 additions & 6 deletions
52
packages/client/src/runtime/core/init/checkPlatformCaching.test.ts
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 |
---|---|---|
@@ -1,31 +1,71 @@ | ||
import { PrismaClientInitializationError } from '@prisma/engine-core' | ||
|
||
import { checkPlatformCaching } from './checkPlatformCaching' | ||
|
||
const consoleMock = jest.spyOn(global.console, 'error').mockImplementation() | ||
|
||
beforeEach(() => { | ||
consoleMock.mockClear() | ||
}) | ||
|
||
test('generated via postinstall on vercel', () => { | ||
expect(() => checkPlatformCaching({ postinstall: true, ciName: 'Vercel', clientVersion: '0.0.0' })) | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
We have detected that you've built your project on Vercel, which caches dependencies. | ||
This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. | ||
To fix this, make sure to run the \`prisma generate\` command during your build process. | ||
Prisma has detected that this project was built on Vercel, which caches dependencies. This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. To fix this, make sure to run the \`prisma generate\` command during the build process. | ||
Learn how: https://pris.ly/d/vercel-build | ||
`) | ||
|
||
expect(consoleMock.mock.calls[0]).toMatchInlineSnapshot(` | ||
[ | ||
Prisma has detected that this project was built on Vercel, which caches dependencies. This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. To fix this, make sure to run the \`prisma generate\` command during the build process. | ||
Learn how: https://pris.ly/d/vercel-build, | ||
] | ||
`) | ||
}) | ||
|
||
test('generated on vercel', () => { | ||
expect(() => checkPlatformCaching({ postinstall: false, ciName: 'Vercel', clientVersion: '0.0.0' })).not.toThrow() | ||
|
||
expect(consoleMock.mock.calls[0]).toMatchInlineSnapshot(`undefined`) | ||
}) | ||
|
||
test('generated via postinstall on netlify', () => { | ||
expect(() => checkPlatformCaching({ postinstall: true, ciName: 'Netlify CI', clientVersion: '0.0.0' })) | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
We have detected that you've built your project on Netlify CI, which caches dependencies. | ||
This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. | ||
To fix this, make sure to run the \`prisma generate\` command during your build process. | ||
Prisma has detected that this project was built on Netlify CI, which caches dependencies. This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. To fix this, make sure to run the \`prisma generate\` command during the build process. | ||
Learn how: https://pris.ly/d/netlify-build | ||
`) | ||
|
||
expect(consoleMock.mock.calls[0]).toMatchInlineSnapshot(` | ||
[ | ||
Prisma has detected that this project was built on Netlify CI, which caches dependencies. This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. To fix this, make sure to run the \`prisma generate\` command during the build process. | ||
Learn how: https://pris.ly/d/netlify-build, | ||
] | ||
`) | ||
}) | ||
|
||
test('generated on netlify', () => { | ||
expect(() => checkPlatformCaching({ postinstall: false, ciName: 'Netlify CI', clientVersion: '0.0.0' })).not.toThrow() | ||
expect(consoleMock.mock.calls[0]).toMatchInlineSnapshot(`undefined`) | ||
}) | ||
|
||
test('error is a PrismaClientInitializationError', () => { | ||
try { | ||
checkPlatformCaching({ postinstall: true, ciName: 'Netlify CI', clientVersion: '0.0.0' }) | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(PrismaClientInitializationError) | ||
expect(consoleMock.mock.calls[0]).toMatchInlineSnapshot(` | ||
[ | ||
Prisma has detected that this project was built on Netlify CI, which caches dependencies. This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. To fix this, make sure to run the \`prisma generate\` command during the build process. | ||
Learn how: https://pris.ly/d/netlify-build, | ||
] | ||
`) | ||
} | ||
}) | ||
|
||
export {} |
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
19 changes: 16 additions & 3 deletions
19
packages/client/tests/e2e/platform-caching-error/tests/vercel-auto-generate.ts
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 |
---|---|---|
@@ -1,15 +1,28 @@ | ||
import { PrismaClient } from '@prisma/client' | ||
|
||
const consoleMock = jest.spyOn(global.console, 'error').mockImplementation() | ||
|
||
beforeEach(() => { | ||
consoleMock.mockClear() | ||
}) | ||
|
||
test('vercel env var + auto generate', () => { | ||
try { | ||
const prisma = new PrismaClient() | ||
prisma.$connect() | ||
} catch (e) { | ||
expect(e).toMatchInlineSnapshot(` | ||
[Error: We have detected that you've built your project on Vercel, which caches dependencies. | ||
This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. | ||
To fix this, make sure to run the \`prisma generate\` command during your build process. | ||
[Error: Prisma has detected that this project was built on Vercel, which caches dependencies. This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. To fix this, make sure to run the \`prisma generate\` command during the build process. | ||
Learn how: https://pris.ly/d/vercel-build] | ||
`) | ||
|
||
expect(consoleMock.mock.calls[0]).toMatchInlineSnapshot(` | ||
[ | ||
"Prisma has detected that this project was built on Vercel, which caches dependencies. This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. To fix this, make sure to run the \`prisma generate\` command during the build process. | ||
Learn how: https://pris.ly/d/vercel-build", | ||
] | ||
`) | ||
} | ||
}) |