Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/resolve tests #207

Merged
merged 4 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
matrix:
os: ['ubuntu-latest']
node-version: [16.x]
prisma-client-version: ['3.5']
prisma-client-version: ['3.10', '3.11', '3.12', '3.13']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our test now does not support more than one past version test.
Because we have a DB from Heroku to test with and we use schema name for every test by os name and node version here you will use the same schema name so every test will reset the schema for the other one.
we need to update the create schema function to add the prisma version on it.
Please take a look here https://github.com/prisma/nexus-prisma/blob/main/scripts/get-e2e-db-schema.ts

Copy link
Contributor

@jasonkuhrt jasonkuhrt Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case it helps we've implemented e2e tests in @prisma/templates that allow parallel testing on one database server: https://github.com/prisma/templates-node/blob/main/tests/e2e/__testers__.ts

One of the key bits is the clean up operation which is handy for supporting local TDD (doesn't matter much for one-off runs in CI): https://github.com/prisma/templates-node/blob/main/tests/e2e/__testers__.ts#L38

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
"exports": {
".": {
"require": "./dist-cjs/entrypoints/main.js",
"import": "./dist-esm/entrypoints/main.mjs"
"import": "./dist-esm/entrypoints/main.js"
},
"./scalars": {
"require": "./dist-cjs/entrypoints/scalars.js",
"import": "./dist-esm/entrypoints/scalars.mjs"
"import": "./dist-esm/entrypoints/scalars.js"
},
"./generator": {
"require": "./dist-cjs/entrypoints/generator.js",
"import": "./dist-esm/entrypoints/generator.mjs"
"import": "./dist-esm/entrypoints/generator.js"
},
"./*": {
"default": "./*.js"
Expand Down Expand Up @@ -59,7 +59,7 @@
"dev": "yarn -s clean && tsc --build --watch tsconfig.cjs.json tsconfig.esm.json",
"dev:ts": "yarn dev",
"dev:yalc": "nodemon --delay 1.5 --exec 'yalc push --no-scripts' --watch 'dist-*/**/*'",
"build": "yarn clean && tsc --build tsconfig.cjs.json tsconfig.esm.json && tsc-esm -p tsconfig.esm.json",
"build": "yarn clean && tsc --build tsconfig.cjs.json tsconfig.esm.json",
"test": "cross-env NO_COLOR=true DEBUG='konn*,e2e' jest",
"test:e2e": "cross-env NO_COLOR=true DEBUG=e2e jest --selectProjects e2e",
"test:unit": "cross-env NO_COLOR=true jest --selectProjects unit",
Expand All @@ -75,8 +75,8 @@
"devDependencies": {
"@homer0/prettier-plugin-jsdoc": "^4.0.6",
"@prisma-labs/prettier-config": "0.1.0",
"@prisma/client": "^3.6.0",
"@prisma/sdk": "^3.6.0",
"@prisma/client": "^3.12.0",
"@prisma/sdk": "^3.12.0",
"@types/debug": "^4.1.7",
"@types/expand-tilde": "^2.0.0",
"@types/jest": "27.0.3",
Expand Down Expand Up @@ -108,21 +108,20 @@
"nodemon": "^2.0.15",
"object-hash": "^2.2.0",
"prettier": "2.5.0",
"prisma": "3.6.0",
"prisma": "3.12.0",
"read-pkg-up": "7",
"slug": "^5.2.0",
"strip-ansi": "6",
"ts-jest": "27.0.7",
"ts-node": "^10.4.0",
"type-fest": "^2.8.0",
"typescript": "4.5.2",
"typescript-esm": "^2.0.0",
"yalc": "^1.0.0-pre.53",
"zod": "^3.11.6"
},
"prettier": "@prisma-labs/prettier-config",
"peerDependencies": {
"@prisma/client": "^3.5",
"@prisma/client": "^3.10",
"graphql": "^15 | ^16",
"nexus": "^1.0.0",
"ts-node": "^10.0.0"
Expand All @@ -133,7 +132,7 @@
}
},
"dependencies": {
"@prisma/generator-helper": "^3.6.0",
"@prisma/generator-helper": "^3.12.0",
"debug": "^4.3.3",
"decimal.js": "^10.3.1",
"dindist": "^1.0.2",
Expand Down
5 changes: 2 additions & 3 deletions tests/checks/PrismaClientOnContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const base = testIntegrationPartial({
database: `
model User {
id String @id
profile Profile? @relation(fields: [profileId], references: [id])
profile Profile @relation(fields: [profileId], references: [id])
profileId String
}
model Profile {
id String @id
user User @relation
user User? @relation
}
`,
api({ User, Profile }) {
Expand Down Expand Up @@ -45,7 +45,6 @@ const base = testIntegrationPartial({
await prisma.user.create({
data: {
id: '1',
profileId: '100',
profile: {
create: {
id: '100',
Expand Down
48 changes: 12 additions & 36 deletions tests/checks/__snapshots__/PrismaClientOnContext.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Query {

type User {
id: ID!
profile: Profile
profile: Profile!
}

type Profile {
Expand Down Expand Up @@ -55,7 +55,7 @@ type Query {

type User {
id: ID!
profile: Profile
profile: Profile!
}

type Profile {
Expand All @@ -68,13 +68,7 @@ exports[`duckType strategy: passes if client looks like a valid prisma client in

exports[`instanceOf strategy: If prisma client import fails then the check cannot perform its instanceof strategy and thus throws an error: graphqlOperationExecutionResult 1`] = `
Object {
"data": Object {
"users": Array [
Object {
"profile": null,
},
],
},
"data": null,
"errors": Array [
[GraphQLError: Could not perform "PrismaClientOnContext" check because there was an error while trying to import Prisma Client:

Expand All @@ -91,7 +85,7 @@ type Query {

type User {
id: ID!
profile: Profile
profile: Profile!
}

type Profile {
Expand All @@ -104,13 +98,7 @@ exports[`instanceOf strategy: If prisma client import fails then the check canno

exports[`instanceOf strategy: If prisma client import succeeds but what is imported is not a valid prisma client then the check cannot perform its instanceof strategy and thus throws an error: graphqlOperationExecutionResult 1`] = `
Object {
"data": Object {
"users": Array [
Object {
"profile": null,
},
],
},
"data": null,
"errors": Array [
[GraphQLError: Could not perform "PrismaClientOnContext" check because could not get a reference to a valid Prisma Client class. Found:

Expand All @@ -127,7 +115,7 @@ type Query {

type User {
id: ID!
profile: Profile
profile: Profile!
}

type Profile {
Expand Down Expand Up @@ -160,7 +148,7 @@ type Query {

type User {
id: ID!
profile: Profile
profile: Profile!
}

type Profile {
Expand All @@ -173,13 +161,7 @@ exports[`instanceOf strategy: passes if client is a real instance of prisma clie

exports[`instanceOf strategy: throws an error if client is NOT a real instance of prisma client: graphqlOperationExecutionResult 1`] = `
Object {
"data": Object {
"users": Array [
Object {
"profile": null,
},
],
},
"data": null,
"errors": Array [
[GraphQLError: Check "PrismaClientOnContext" failed using "instanceOf" strategy. The GraphQL context.prisma value is not an instance of the Prisma Client.],
],
Expand All @@ -194,7 +176,7 @@ type Query {

type User {
id: ID!
profile: Profile
profile: Profile!
}

type Profile {
Expand All @@ -207,13 +189,7 @@ exports[`instanceOf strategy: throws an error if client is NOT a real instance o

exports[`instanceOf_duckType_fallback strategy: error thrown when both instanceof check and duck typing fails: graphqlOperationExecutionResult 1`] = `
Object {
"data": Object {
"users": Array [
Object {
"profile": null,
},
],
},
"data": null,
"errors": Array [
[GraphQLError: Check "PrismaClientOnContext" failed using "instanceOf_duckType_fallback" strategy. The GraphQL context.prisma value is not an instance of the Prisma Client.],
],
Expand All @@ -228,7 +204,7 @@ type Query {

type User {
id: ID!
profile: Profile
profile: Profile!
}

type Profile {
Expand Down Expand Up @@ -261,7 +237,7 @@ type Query {

type User {
id: ID!
profile: Profile
profile: Profile!
}

type Profile {
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/kitchen-sink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ beforeEach(() => {
dotenv: '^9.0.0',
'apollo-server': '^2.24.0',
'cross-env': '^7.0.1',
'@prisma/client': '^2.18.0',
'@prisma/client': '^3.5.0',
'@types/node': '^14.14.32',
graphql: '^15.5.0',
nexus: '^1.0.0',
prisma: '^2.18.0',
nexus: '1.1.0',
prisma: '^3.5.0',
'ts-node': '^9.1.1',
'ts-node-dev': '^1.1.6',
typescript: '^4.2.3',
Expand Down Expand Up @@ -151,7 +151,7 @@ it('A full-featured project type checks, generates expected GraphQL schema, and
async function main() {
const prisma = new PrismaClient()

await prisma.$executeRaw('TRUNCATE "Foo", "Bar", "Qux"')
await prisma.$executeRaw\`TRUNCATE "Foo", "Bar", "Qux"\`
await prisma.foo.create({
data: {
id: 'foo1',
Expand Down
Loading