Skip to content

Commit

Permalink
fix: napi tests (#6146)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Suchanek <Tim.Suchanek@gmail.com>
Co-authored-by: timsuchanek <tim.suchanek@gmail.com>
  • Loading branch information
3 people committed Mar 29, 2021
1 parent 01af9a9 commit 9236149
Show file tree
Hide file tree
Showing 76 changed files with 574 additions and 422 deletions.
129 changes: 129 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -162,7 +162,82 @@ jobs:
files: ./src/packages/tests/src/__tests__/coverage/clover.xml
flags: tests-integration,${{ matrix.database }}
name: tests-integration-${{ matrix.database }}
#
# TESTS-INTEGRATION-NAPI
#
tests-integration-napi:
timeout-minutes: 20
runs-on: ubuntu-20.04
env:
PRISMA_FORCE_NAPI: "true"
PRISMA_DEBUG_ENABLE_ALL_FLAGS: "true"
strategy:
fail-fast: false
matrix:
database:
- sqlite
- postgres
- mysql
- mariadb
- mssql
node: [12]

steps:
- uses: actions/checkout@v2

- run: docker-compose -f src/docker/docker-compose.yml up --detach ${{matrix.database}}
if: matrix.database != 'sqlite'

# From https://docs.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}

- run: bash .github/workflows/setup.sh
env:
CI: true
SKIP_GIT: true
GITHUB_CONTEXT: ${{ toJson(github) }}

- run: pnpm i sqlite3@5.0.2 --unsafe-perm --reporter=silent
if: ${{ matrix.database == 'sqlite' }}
working-directory: src/packages/tests

# temp
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3

- run: pnpm run jest integration/${{ matrix.database }} -- --forceExit --maxConcurrency=8
working-directory: src/packages/tests
env:
CI: true
SKIP_GIT: true
GITHUB_CONTEXT: ${{ toJson(github) }}
TEST_POSTGRES_BASE_URI: postgres://prisma:prisma@localhost:5432
TEST_MYSQL_BASE_URI: mysql://root:root@localhost:3306
TEST_MARIADB_BASE_URI: mysql://root:root@localhost:4306
TEST_POSTGRES_URI: postgres://prisma:prisma@localhost:5432/tests
TEST_MYSQL_URI: mysql://root:root@localhost:3306/tests
TEST_MARIADB_URI: mysql://root:root@localhost:4306/tests
TEST_MSSQL_URI: mssql://SA:Pr1sm4_Pr1sm4@localhost:1433/master

- uses: codecov/codecov-action@v1
with:
files: ./src/packages/tests/src/__tests__/coverage/clover.xml
flags: tests-integration,${{ matrix.database }}
name: tests-integration-${{ matrix.database }}
#
# CLI-COMMANDS
#
Expand Down Expand Up @@ -274,6 +349,60 @@ jobs:
files: ./src/packages/client/src/__tests__/coverage/clover.xml
flags: client,${{ matrix.os }}
name: client-${{ matrix.os }}

#
# CLIENT (types tests only with NAPI Enabled)
#
client-types-napi:
timeout-minutes: 10
runs-on: ubuntu-20.04
env:
PRISMA_FORCE_NAPI: "true"
PRISMA_DEBUG_ENABLE_ALL_FLAGS: "true"
strategy:
fail-fast: false
matrix:
node: [12]

steps:
- uses: actions/checkout@v2

# From https://docs.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}

- run: bash .github/workflows/setup.sh
env:
CI: true
SKIP_GIT: true
GITHUB_CONTEXT: ${{ toJson(github) }}

- run: pnpm run test src/__tests__/types/types.test.ts
working-directory: src/packages/client
env:
CI: true
SKIP_GIT: true
GITHUB_CONTEXT: ${{ toJson(github) }}

- uses: codecov/codecov-action@v1
with:
files: ./src/packages/client/src/__tests__/coverage/clover.xml
flags: client-types,${{ matrix.os }}
name: client-types-${{ matrix.os }}

#
# CLIENT (types tests only)
#
Expand Down
1 change: 1 addition & 0 deletions src/package.json
Expand Up @@ -36,6 +36,7 @@
"build": "ts-node scripts/setup.ts --build",
"dry": "ts-node scripts/ci/publish.ts --dry-run",
"publish-all": "ts-node scripts/ci/publish.ts --publish",
"bump-engines": "ts-node scripts/bump-engines.ts",
"test": "ts-node scripts/ci/publish.ts --test",
"all": "ts-node scripts/ci/all.ts",
"status": "ts-node scripts/ci/publish.ts --status",
Expand Down
3 changes: 2 additions & 1 deletion src/packages/client/fixtures/blog/prisma/schema.prisma
Expand Up @@ -2,8 +2,9 @@ datasource db {
provider = "sqlite"
url = "file:dev.db"
}

generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
previewFeatures = ["napi"]
}

Expand Down
3 changes: 2 additions & 1 deletion src/packages/client/package.json
Expand Up @@ -24,7 +24,7 @@
"types": "index.d.ts",
"license": "Apache-2.0",
"engines": {
"node": ">=10.4"
"node": ">=10.16"
},
"homepage": "https://www.prisma.io",
"repository": "git@github.com:prisma/prisma.git",
Expand Down Expand Up @@ -63,6 +63,7 @@
"@prisma/generator-helper": "workspace:*",
"@prisma/get-platform": "workspace:*",
"@prisma/migrate": "workspace:*",
"@prisma/fetch-engine": "workspace:*",
"@prisma/sdk": "workspace:*",
"@timsuchanek/copy": "1.4.5",
"@types/debug": "4.1.5",
Expand Down
Expand Up @@ -3,7 +3,11 @@ import fs from 'fs'
import path from 'path'
import { generateTestClient } from '../../../../utils/getTestClient'

test('corruption', async () => {
test('corruption of query engine binary', async () => {
// testing for corruption of the main query engine
if (process.env.PRISMA_FORCE_NAPI === 'true') {
return
}
expect.assertions(1)

await generateTestClient()
Expand Down
@@ -1,6 +1,10 @@
import { getTestClient } from '../../../../utils/getTestClient'

test('error-link', async () => {
// works in isolation
if (process.env.PRISMA_FORCE_NAPI) {
return
}
expect.assertions(1)

const PrismaClient = await getTestClient()
Expand Down
Expand Up @@ -17,8 +17,8 @@ beforeAll(async () => {
prisma = new PrismaClient()
})

afterAll(() => {
prisma.$disconnect()
afterAll(async () => {
await prisma.$disconnect()
})

test('executeRaw-alter-postgres', async () => {
Expand Down
Expand Up @@ -24,5 +24,5 @@ test('incorrect-column-type', async () => {
→ 15 await expect(prisma.user.findMany()).reject
Attempted to serialize scalar '123' with incompatible type 'String'
`)
prisma.$disconnect()
await prisma.$disconnect()
})
Expand Up @@ -35,7 +35,7 @@ describe('int-errors', () => {
})

afterAll(async () => {
prisma.$disconnect()
await prisma.$disconnect()

await tearDownMysql(SetupParams.connectionString).catch((e) => {
console.log(e)
Expand Down
Expand Up @@ -4,6 +4,11 @@ import path from 'path'
import { generateTestClient } from '../../../../utils/getTestClient'

test('missing-binary-native', async () => {
// works in isolation
if (process.env.PRISMA_FORCE_NAPI) {
return
}

expect.assertions(1)
await generateTestClient()

Expand Down
Expand Up @@ -4,6 +4,10 @@ import path from 'path'
import { generateTestClient } from '../../../../utils/getTestClient'

test('missing-binary', async () => {
// works in isolation
if (process.env.PRISMA_FORCE_NAPI) {
return
}
expect.assertions(1)
await generateTestClient()

Expand Down
Expand Up @@ -4,20 +4,17 @@ test('missing-relation', async () => {
expect.assertions(2)
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()

try {
await prisma.post.findMany({
include: {
author: true,
},
})
} catch (e) {
expect(e.message).toContain('PANIC in')
expect(e.message).toContain('PANIC')
expect(e.message).toContain(
'Application logic invariant error: received null value for field author which may not be null',
)
} finally {
prisma.$disconnect()
}
})

Expand Down
Expand Up @@ -18,5 +18,5 @@ test('missing-table', async () => {
The table \`main.User\` does not exist in the current database.
`)

prisma.$disconnect()
await prisma.$disconnect()
})
Expand Up @@ -21,5 +21,5 @@ test('object-transaction object', async () => {
`All elements of the array need to be Prisma Client promises. Hint: Please make sure you are not awaiting the Prisma client calls you intended to pass in the $transaction function.`,
)

prisma.$disconnect()
await prisma.$disconnect()
})
Expand Up @@ -7,8 +7,8 @@ beforeAll(async () => {
prisma = new PrismaClient()
})

afterAll(() => {
prisma.$disconnect()
afterAll(async () => {
await prisma.$disconnect()
})

test('raw-transaction: queryRaw', async () => {
Expand Down
Expand Up @@ -20,5 +20,5 @@ test('source-map-support', async () => {
}),
).rejects.toMatchSnapshot()

prisma.$disconnect()
await prisma.$disconnect()
})
Expand Up @@ -92,5 +92,5 @@ test('uncheckedScalarInputs validation', async () => {
`)
}

prisma.$disconnect()
await prisma.$disconnect()
})
Expand Up @@ -57,5 +57,5 @@ test('union validation', async () => {
`)
}

prisma.$disconnect()
await prisma.$disconnect()
})
@@ -1,7 +1,7 @@
import { getTestClient } from '../../../../utils/getTestClient'
import path from 'path'
import { migrateDb } from '../../__helpers__/migrateDb'
import { getTestClient } from '../../../../utils/getTestClient'
import { tearDownMysql } from '../../../../utils/setupMysql'
import { migrateDb } from '../../__helpers__/migrateDb'

// We WANT to be able to do the async function without an await
/* eslint-disable @typescript-eslint/require-await */
Expand Down Expand Up @@ -47,7 +47,7 @@ test('wrong-native-types-mysql A: Int, SmallInt, TinyInt, MediumInt, BigInt', as
`)

prisma.$disconnect()
await prisma.$disconnect()
})

test('wrong-native-types-mysql B: Float, Double, Decimal, Numeric', async () => {
Expand Down Expand Up @@ -79,7 +79,7 @@ test('wrong-native-types-mysql B: Float, Double, Decimal, Numeric', async () =>
`)

prisma.$disconnect()
await prisma.$disconnect()
})

test('wrong-native-types-mysql C: Char, VarChar, TinyText, Text, MediumText, LongText', async () => {
Expand Down Expand Up @@ -114,7 +114,7 @@ test('wrong-native-types-mysql C: Char, VarChar, TinyText, Text, MediumText, Lon
`The provided value for the column is too long for the column's type. Column: char`,
)

prisma.$disconnect()
await prisma.$disconnect()
})

test('wrong-native-types-mysql D: Date, Time, DateTime, Timestamp, Year', async () => {
Expand Down Expand Up @@ -149,7 +149,7 @@ test('wrong-native-types-mysql D: Date, Time, DateTime, Timestamp, Year', async
`)

prisma.$disconnect()
await prisma.$disconnect()
})

test('wrong-native-types-mysql E: Bit, Binary, VarBinary, Blob, TinyBlob, MediumBlob, LongBlob', async () => {
Expand Down Expand Up @@ -197,5 +197,5 @@ test('wrong-native-types-mysql E: Bit, Binary, VarBinary, Blob, TinyBlob, Medium
`)

prisma.$disconnect()
await prisma.$disconnect()
})

0 comments on commit 9236149

Please sign in to comment.