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

test(pulse): add a test for pulse extension for Node.js #4637

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions .github/workflows/scripts/detect-jobs-to-run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('detect-jobs-to-run', () => {
"driver-adapters",
"driver-adapters-wasm",
"accelerate",
"pulse",
"bundlers",
"libraries",
"databases",
Expand Down Expand Up @@ -115,6 +116,7 @@ describe('detect-jobs-to-run', () => {
"driver-adapters",
"driver-adapters-wasm",
"accelerate",
"pulse",
"bundlers",
"libraries",
"databases",
Expand Down Expand Up @@ -152,6 +154,7 @@ describe('detect-jobs-to-run', () => {
"driver-adapters",
"driver-adapters-wasm",
"accelerate",
"pulse",
"bundlers",
"libraries",
"databases",
Expand Down Expand Up @@ -189,6 +192,7 @@ describe('detect-jobs-to-run', () => {
"driver-adapters",
"driver-adapters-wasm",
"accelerate",
"pulse",
"bundlers",
"libraries",
"databases",
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ jobs:
- driver-adapters
- driver-adapters-wasm
- accelerate
- pulse
- bundlers
- libraries
- databases
Expand Down Expand Up @@ -132,6 +133,7 @@ jobs:
- driver-adapters
- driver-adapters-wasm
- accelerate
- pulse
- bundlers
- libraries
- databases
Expand Down Expand Up @@ -174,6 +176,7 @@ jobs:
- driver-adapters
- driver-adapters-wasm
- accelerate
- pulse
- bundlers
- libraries
- databases
Expand Down Expand Up @@ -1561,6 +1564,82 @@ jobs:
if: failure()
run: bash .github/slack/notify-failure.sh ${{ github.job }} ${{ matrix.platform }}

pulse:
needs: [detect_jobs_to_run]
if: contains(fromJSON(needs.detect_jobs_to_run.outputs.jobs), 'pulse')

timeout-minutes: 60 # can take longer if platforms are down, so better protect
strategy:
fail-fast: false
matrix:
platform:
- nodejs
# - deno
# - cloudflare-workers-service
# - cloudflare-workers-module
# - vercel-edge-functions
# - vercel-cli-serverless-functions
# - nodejs-postgresql-itx
# - nodejs-mysql-itx
# - nodejs-mongodb-itx
# - nodejs-cockroachdb-itx
# - nodejs-postgresql-logs
# - nodejs-mongodb-logs
# - nodejs-tracing
clientEngine: [library]
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}
concurrency: ${{ github.job }}-${{ matrix.platform }}-${{ matrix.clientEngine }}
env:
NODE_ENV: development
NODE_MODULES_CACHE: false
NODE_VERBOSE: true
# VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
# VERCEL_ORG_ID: ${{ vars.VERCEL_ORG_ID }}
# TODO change to vars below
# CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
# CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
# DATAPROXY_VERCEL_EDGE_FUNCTIONS_PROJECT_ID: ${{ vars.DATAPROXY_VERCEL_EDGE_FUNCTIONS_PROJECT_ID }}
# DATAPROXY_VERCEL_CLI_SERVERLESS_FUNCTIONS_PROJECT_ID: ${{ vars.DATAPROXY_VERCEL_CLI_SERVERLESS_FUNCTIONS_PROJECT_ID }}

steps:
- uses: actions/checkout@v4

- uses: pnpm/[email protected]
with:
version: 8

- uses: actions/setup-node@v4
with:
node-version: 16
cache: 'pnpm'
cache-dependency-path: ${{ github.job }}/${{ matrix.platform }}/pnpm-lock.yaml

# - name: use deno v1.x
# uses: denoland/setup-deno@v1
# with:
# deno-version: v1.x

- name: Define Client Engine Type to test
run: echo "PRISMA_CLIENT_ENGINE_TYPE=${{ matrix.clientEngine }}" >> $GITHUB_ENV

- name: Install Dependencies
run: pnpm install

- name: test Pulse with extension ${{ matrix.platform }}
uses: nick-invision/retry@v3
with:
timeout_minutes: 15
max_attempts: 3
retry_wait_seconds: 30
command: bash .github/scripts/test-project.sh ${{ github.job }} ${{ matrix.platform }}
env:
MY_POSTGRES_DB_URL: ${{ secrets.MY_POSTGRES_DB_URL }}

- name: notify-slack
if: failure()
run: bash .github/slack/notify-failure.sh ${{ github.job }} ${{ matrix.platform }}

bundlers:
needs: [detect_jobs_to_run]
if: contains(fromJSON(needs.detect_jobs_to_run.outputs.jobs), 'bundlers')
Expand Down
11 changes: 11 additions & 0 deletions pulse/nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Node.js

Tests Prisma Client with Pulse extension using Node.js.

## How to run this

Set the necessary env vars first.

```sh
source ./prepare.sh && ./run.sh && ./test.sh && ./finally.sh
```
40 changes: 40 additions & 0 deletions pulse/nodejs/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { main } from './src/index'

/// <reference types="@types/jest" />

describe('Pulse', () => {
test('create a subscription, send queries and listen to events', async () => {
const result = await main()
console.debug({ result })

expect(result.create).toMatchObject({
action: 'create',
created: {
email: expect.any(String),
name: null,
user_id: expect.any(Number),
},
id: expect.any(String),
modelName: 'User',
})
expect(result.update).toMatchObject({
action: 'update',
after: {
email: expect.any(String),
name: 'Alice',
user_id: expect.any(Number),
},
before: null,
id: expect.any(String),
modelName: 'User',
})
expect(result.delete).toMatchObject({
action: 'delete',
deleted: {
user_id: expect.any(Number),
},
id: expect.any(String),
modelName: 'User',
})
}, 30000)
})
5 changes: 5 additions & 0 deletions pulse/nodejs/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
20 changes: 20 additions & 0 deletions pulse/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "nodejs",
"license": "MIT",
"scripts": {
"test": "jest"
},
"dependencies": {
"@prisma/client": "5.11.0-dev.43",
"@prisma/extension-pulse": "0.2.3"
},
"devDependencies": {
"@types/jest": "28.1.8",
"@types/node": "16.18.86",
"jest": "29.7.0",
"prisma": "5.11.0-dev.43",
"ts-jest": "29.1.2",
"ts-node": "10.9.2",
"typescript": "5.3.3"
}
}
Loading
Loading