-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
If Date Object input is specified as DateTime type gte, lte, lt,gt operator in include's where condition doesn't work #56
Comments
jest-prisma does not touch Date class. I think this is not jest-prisma issue but Jest issue. |
@Quramy I also found first inputed values are same in every cases.
Prisma using in Jest directely It may be related to jestjs/jest#7246. |
I found inserting async setup() {
const jestPrisma = await this.delegate.preSetup();
await super.setup();
this.global.jestPrisma = jestPrisma;
this.global.Date = Date
} |
@Quramy |
@tkow Thanks for your investigating and sending the PR. this.global.Date = Date I think this problem is caused by jestjs/jest#2549 ( It's famous jest issue, and tooooo long to read 😭 ) And 3rd party jest environments to tackle the issue are published: e.g. https://www.npmjs.com/package/jest-environment-node-single-context For now, I don't know whether jest-prisma should extend the "workaround" environment or not. But users can weave jest-prisma function to their own environment like this: import type { Circus } from "@jest/types";
import type { JestEnvironmentConfig, EnvironmentContext } from "@jest/environment";
import { PrismaEnvironmentDelegate } from "@quramy/jest-prisma-core";
import Environment from "jest-environment-node-single-context";
export default class PrismaEnvironment extends Environment {
private readonly delegate: PrismaEnvironmentDelegate;
constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {
super(config, context);
this.delegate = new PrismaEnvironmentDelegate(config, context);
}
async setup() {
const jestPrisma = await this.delegate.preSetup();
await super.setup();
this.global.jestPrisma = jestPrisma;
}
handleTestEvent(event: Circus.Event) {
return this.delegate.handleTestEvent(event);
}
async teardown() {
await Promise.all([super.teardown(), this.delegate.teardown()]);
}
}
|
@Quramy As I thought it, jest-prisma includes jest-environment-node-single-context relatively better than the others in the point of |
Thanks for reply and testing.
Hummm, I'm thinking about this. Please give me some time before I answer the question. |
Of course. I bypass this pitfall by extending environment now as you told me. Thank you. |
I'm sorry if it's already known, but I can't input Date JS object as DateTime type fields at where operators using
jestPrisma.client
in my environment though original prisma client passes tests.The photo shows running first test with prisma-jest, and second with original client.
Version Spec
(Addition)
It doesn't reproduce it only just to addI try to find how to reproduce it asap.created_at Datetime @default(now())
to example-prj' user model.I could reproduce it when condition has
include: { where: { [$dateFiledName]: { lt: new Date } } }
, so on. Both sqlite and postgresql are reproduced so it may have the problem in js layer .I confirmed that internal jest-prisma-core originalClient and jest-prisma jestPrisma.originalClient works by force creating and fetch data with overwriting in node_modules folder. In addition, I noticed that validate method in prisma calls with same data, but slightly different though I don't know why. It may be clues.
Original client
Proxy client(both jestPrisma.client and jestPrisma.originalClient)
I also found invalidChildren' value exists in node_modules/@prisma/client/runtime/index.js validate method with jest-prisma proxy though manually PrismaClient in jest test case doesn't.
The text was updated successfully, but these errors were encountered: