Skip to content

Commit

Permalink
test: extract hardcoded package.json declarations to fixtures (#309)
Browse files Browse the repository at this point in the history
* test: extract hardcoded package into fixture file

* ci: allow renovate to process package.json files also in tests

* chore: allign prisma and @prisma/client version

* style: fix formating issues

* chore: pin nexus version in dev dependencies

* test: pin version for all prisma specific dependencies to 4.0 for test-past-prisma
  • Loading branch information
rostislav-simonik authored Nov 20, 2022
1 parent 68884c5 commit 8cebf8a
Show file tree
Hide file tree
Showing 10 changed files with 1,218 additions and 1,779 deletions.
3 changes: 2 additions & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"extends": ["config:base", ":semanticCommits", ":automergeMinor"],
"rangeStrategy": "bump",
"assignees": ["rostislav-simonik"],
"reviewers": ["rostislav-simonik"]
"reviewers": ["rostislav-simonik"],
"ignorePaths": []
}
10 changes: 6 additions & 4 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
matrix:
os: ['ubuntu-latest']
node-version: [16]
prisma-client-version: ['4.0']
prisma-base-version: ['4.0']

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -95,13 +95,15 @@ jobs:
run: yarn --frozen-lockfile

- name: Set E2E DB Schema
run: yarn -s ts-node scripts/get-e2e-db-schema --os ${{ matrix.os }} --node-version ${{ matrix.node-version }} --prisma-client-version ${{ matrix.prisma-client-version }} --github-env $GITHUB_ENV
run: yarn -s ts-node scripts/get-e2e-db-schema --os ${{ matrix.os }} --node-version ${{ matrix.node-version }} --prisma-client-version ${{ matrix.prisma-base-version }} --github-env $GITHUB_ENV

- name: Build
run: yarn -s build

- name: Install Prisma Client version
run: yarn -s add @prisma/client@${{ matrix.prisma-client-version }}
- name: Install prisma dev packages
run: yarn -s add prisma@${{ matrix.prisma-base-version }} @prisma/client@${{ matrix.prisma-base-version }} @prisma/internals@${{ matrix.prisma-base-version }} --dev

- name: Install prisma packages
run: yarn -s add @prisma/generator-helper@${{ matrix.prisma-base-version }}
- name: Test
run: yarn -s test:ci
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
"devDependencies": {
"@homer0/prettier-plugin-jsdoc": "^4.0.6",
"@prisma-labs/prettier-config": "0.1.0",
"@prisma/client": "^4.1.0",
"@prisma/internals": "^4.1.0",
"@prisma/client": "^4.0.0",
"@prisma/internals": "^4.0.0",
"@types/debug": "^4.1.7",
"@types/expand-tilde": "^2.0.0",
"@types/jest": "27.5.2",
Expand Down Expand Up @@ -107,11 +107,11 @@
"jest-watch-typeahead": "2.2.0",
"konn": "^0.7.0",
"markdown-toc": "^1.2.0",
"nexus": "^1.1.0",
"nexus": "1.1.0",
"nodemon": "^2.0.20",
"object-hash": "^3.0.0",
"prettier": "2.7.1",
"prisma": "4.1.0",
"prisma": "^4.0.0",
"read-pkg-up": "7",
"slug": "^5.3.0",
"strip-ansi": "6",
Expand All @@ -124,7 +124,7 @@
},
"prettier": "@prisma-labs/prettier-config",
"peerDependencies": {
"@prisma/client": "^4",
"@prisma/client": "^4.0",
"graphql": "^15.0.0 || ^16.0.0",
"nexus": "^1.0.0",
"ts-node": "^10.9.1"
Expand All @@ -135,7 +135,7 @@
}
},
"dependencies": {
"@prisma/generator-helper": "^4.1.0",
"@prisma/generator-helper": "^4.0.0",
"debug": "^4.3.4",
"decimal.js": "^10.3.1",
"dindist": "^1.0.2",
Expand Down
27 changes: 27 additions & 0 deletions tests/e2e/fixtures/kitchen-sink/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "kitchen-sink",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"reflect": "yarn -s reflect:prisma && yarn -s reflect:nexus",
"reflect:prisma": "cross-env DEBUG='*' prisma generate",
"reflect:nexus": "cross-env REFLECT=true ts-node --transpile-only src/schema",
"build": "tsc",
"start": "node build/server",
"dev:server": "yarn ts-node-dev --transpile-only server",
"db:migrate": "prisma db push --force-reset --accept-data-loss && ts-node prisma/seed"
},
"dependencies": {
"@prisma/client": "__dynamic__",
"@types/node": "^18.11.9",
"apollo-server": "^3.11.1",
"cross-env": "^7.0.3",
"dotenv": "^9.0.0",
"graphql": "^15.8.0",
"nexus": "1.1.0",
"prisma": "__dynamic__",
"ts-node": "^10.9.1",
"ts-node-dev": "^1.1.6",
"typescript": "4.5.2"
}
}
14 changes: 14 additions & 0 deletions tests/e2e/fixtures/ts-node-import-error/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "ts-node-import-error",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"build": "prisma generate"
},
"dependencies": {
"@prisma/client": "__dynamic__",
"graphql": "^15.8.0",
"nexus": "1.1.0",
"prisma": "__dynamic__"
}
}
14 changes: 14 additions & 0 deletions tests/e2e/fixtures/ts-node-unused/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "ts-node-unused",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"build": "prisma generate"
},
"dependencies": {
"@prisma/client": "__dynamic__",
"graphql": "^15.8.0",
"nexus": "1.1.0",
"prisma": "__dynamic__"
}
}
28 changes: 1 addition & 27 deletions tests/e2e/kitchen-sink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,7 @@ const ctx = konn()
.done()

beforeEach(() => {
ctx.packageJson.merge({
license: 'MIT',
scripts: {
reflect: 'yarn -s reflect:prisma && yarn -s reflect:nexus',
'reflect:prisma': "cross-env DEBUG='*' prisma generate",
// peer dependency check will fail since we're using yalc, e.g.:
// " ... nexus-prisma@0.0.0-dripip+c2653557 does not officially support @prisma/client@2.22.1 ... "
'reflect:nexus': 'cross-env REFLECT=true ts-node --transpile-only src/schema',
build: 'tsc',
start: 'node build/server',
'dev:server': 'yarn ts-node-dev --transpile-only server',
'db:migrate': 'prisma db push --force-reset --accept-data-loss && ts-node prisma/seed',
},
dependencies: {
dotenv: '^9.0.0',
'apollo-server': '^3.11.1',
'cross-env': '^7.0.1',
'@prisma/client': '^4.0.0',
'@types/node': '^14.14.32',
graphql: '^15.5.0',
nexus: '1.1.0',
prisma: '^4.0.0',
'ts-node': '^10.8.1',
'ts-node-dev': '^1.1.6',
typescript: '^4.2.3',
},
})
ctx.fixture.use(Path.join(__dirname, 'fixtures/kitchen-sink'))
ctx.runOrThrow(`${Path.join(process.cwd(), `node_modules/.bin/yalc`)} add ${ctx.thisPackageName}`)
ctx.runOrThrow(`npm install --legacy-peer-deps`, { env: { PEER_DEPENDENCY_CHECK: 'false' } })
})
Expand Down
15 changes: 3 additions & 12 deletions tests/e2e/ts-node-import-error.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dindist from 'dindist'
import { konn, providers } from 'konn'
import 'ts-replace-all'
import * as Path from 'path'
import { createPrismaSchema } from '../__helpers__/helpers'
import { project } from '../__providers__/project'

Expand All @@ -11,18 +12,7 @@ const ctx = konn()
.done()

it('when project does not have ts-node installed nexus-prisma generator still generates if there are no TS generator config files present', async () => {
ctx.packageJson.merge({
scripts: {
build: 'prisma generate',
},
dependencies: {
'@prisma/client': '4.0.0',
graphql: '15.5.1',
nexus: '1.1.0',
prisma: '4.0.0',
},
})

ctx.fixture.use(Path.join(__dirname, 'fixtures/ts-node-import-error'))
ctx.fs.write(
`prisma/schema.prisma`,
createPrismaSchema({
Expand Down Expand Up @@ -55,6 +45,7 @@ const normalizeGeneratorOutput = (output: string) =>
.replaceAll(/(\d+|\d+(\.\d+))(ms|s)/g, '<SOME TIME><unit>')
.replaceAll(/ to .* in /g, ' to <SOME PATH> in ')
.replaceAll(/loaded from.*/g, 'loaded from <SOME PATH>')
.replaceAll(/Error: Cannot find module/g, 'Cannot find module')
.replaceAll(/Generated Prisma Client \(.*\)/g, 'Generated Prisma Client (<SOME VERSION>)')
// https://regex101.com/r/r2wR1Y/2
.replaceAll(/Require stack:(?:(?:\n\s*- .*)(?:\n +at .* \(.*\))*)+/g, 'Require stack:\n- <SOME STACK>')
Expand Down
12 changes: 1 addition & 11 deletions tests/e2e/ts-node-unused.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@ const ctx = konn()
.useBeforeAll(providers.run())
.useBeforeAll(project())
.beforeAll((ctx) => {
ctx.packageJson.merge({
scripts: {
build: 'prisma generate',
},
dependencies: {
'@prisma/client': '4.0.0',
graphql: '15.5.1',
nexus: '1.1.0',
prisma: '4.0.0',
},
})
ctx.fixture.use(Path.join(__dirname, 'fixtures/ts-node-unused'))
ctx.fs.write(
`prisma/schema.prisma`,
createPrismaSchema({
Expand Down
Loading

0 comments on commit 8cebf8a

Please sign in to comment.