我正在将 BunJS 和 Prisma 用于我的个人项目,并通过 cucumberjs 和 keploy 进行测试。以下是我的版本:-
姓名 | 版本 |
---|---|
节点 | v21.6.0 |
操作系统 | linux-arm64-openssl-3.0.x |
Prisma 客户端 | 5.12.1 |
查询引擎 | 473ed3124229e22d881cb7addf559799debae1ab |
数据库 | postgresql |
这是我的棱镜模式:-
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
password String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
posts Post[]
comments Comment[]
...
}
当我在没有集成任何测试部分的情况下运行应用程序时,它工作正常。但是在测试时,仅在 Post 调用中,我收到错误
Invalid `prisma.user.create()` invocation:Could not figure out an ID in create. This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.
这是我的仓库:- https://github.com/darkin424/Blog-Website .
要重现,请按照以下步骤操作:-
1. start the database docker instance
2. install `keploy` with :- https://keploy.io/docs/server/installation/
3. keploy record -c "bun --watch index.ts"
4. make few post api call for creation like `signup`, `create-post`
5. stop the docker instance
6. keploy test -c "bun --watch index.ts"
这样您就可以复制问题
我尝试查看其他人面临的类似问题并尝试运行:-
bunx prisma format
bunx prisma validate
bunx prisma migrate dev
bunx prisma generate
如果我将后调用视为噪音,我的测试工作正常,但我也想测试这些后调用。
所以我将 prisma 版本更新到最新版本,现在能够更好地看到错误。在测试模式下,我得到了日志之间的回溯:-
thread 'tokio-runtime-worker' panicked at query-engine/connectors/sql-query-connector/src/database/operations/write.rs:194:22:
Could not figure out an ID in create
stack backtrace:
0: 0xffff62e79450 - <unknown>
1: 0xffff627db750 - <unknown>
2: 0xffff62e5afb4 - <unknown>
3: 0xffff62e7cfc4 - <unknown>
4: 0xffff62e7c968 - <unknown>
我尝试了上述步骤来复制。这个问题与 Prisma 无关,而是 keploy 如何处理 postgres 的模拟创建,基本上在 keploy 中,
preparedQueryStatement
是用 S
初始化的,因为在大多数数据库中,序列是“S1,S2,S3,.. .”,但如果使用 prisma,则查询是使用“s_1、s_2、s_3、...”创建的,因此模拟与测试不正确匹配,导致失败。
这个问题在 keploy 的 alpha-17 版本中得到了解决,我得到了以下结果:
🐰 Keploy: 2024-07-01T13:28:42+05:30 INFO result {"testcase id": "test-1", "testset id": "test-set-0", "passed": "true"}
🐰 Keploy: 2024-07-01T13:28:42+05:30 INFO starting test for of {"test case": "test-2", "test set": "test-set-0"}
Testrun failed for testcase with id: "test-2"
--------------------------------------------------------------------
+-------------------------------------------------------------------------------------------------------------+
| DIFFS TEST-2 |
+-------------------------------------------------------------------------------------------------------------+
| EXPECT HEADER | ACTUAL HEADER |
| -----------------------------------------------------+----------------------------------------------------- |
| | |
| |
| EXPECT BODY | ACTUAL BODY |
| -----------------------------------------------------+----------------------------------------------------- |
| { | { |
| "message": "User logged in successfully", | "message": "User logged in successfully", |
| - "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. | + "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. |
| eyJpZCI6MSwiZW1haWwiOiJpc3NzYWxjdXBuYW1kZUBhYmMuY2 | eyJpZCI6MSwiZW1haWwiOiJpc3NzYWxjdXBuYW1kZUBhYmMuY2 |
| 9tIiwiaWF0IjoxNzE5ODIwNDE2LCJleHAiOjE3MTk5MDY4MTZ9 | 9tIiwiaWF0IjoxNzE5ODIwNzIyLCJleHAiOjE3MTk5MDcxMjJ9 |
| .vPfugYdsBOlI-0LCdmLKADEEjRXz6FViBRWTJCKQTq8" | ._q0QLMJ-6_Y588JLq3fzc3qtBwYEKzdnAQe9z-4PeeQ" |
| } | } |
| | |
| |
+-------------------------------------------------------------------------------------------------------------+
🐰 Keploy: 2024-07-01T13:28:42+05:30 INFO result {"testcase id": "test-2", "testset id": "test-set-0", "passed": "false"}
🐰 Keploy: 2024-07-01T13:28:42+05:30 INFO starting test for of {"test case": "test-3", "test set": "test-set-0"}
Testrun passed for testcase with id: "test-3"
--------------------------------------------------------------------
🐰 Keploy: 2024-07-01T13:28:42+05:30 INFO result {"testcase id": "test-3", "testset id": "test-set-0", "passed": "true"}
🐰 Keploy: 2024-07-01T13:28:42+05:30 INFO starting test for of {"test case": "test-4", "test set": "test-set-0"}
Testrun passed for testcase with id: "test-4"
--------------------------------------------------------------------
🐰 Keploy: 2024-07-01T13:28:42+05:30 INFO result {"testcase id": "test-4", "testset id": "test-set-0", "passed": "true"}
<=========================================>
TESTRUN SUMMARY. For test-set: "test-set-0"
Total tests: 4
Total test passed: 3
Total test failed: 1
<=========================================>
唯一失败的是由于令牌过期,我通过使用
--freeze-time
标志来传递。