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

Workaround test #1

Closed
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/example-prj/jest-prisma-ex-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Circus } from "@jest/types";
import type { JestEnvironmentConfig, EnvironmentContext } from "@jest/environment";
import Environment from "jest-environment-node-single-context";
export default class PrismaEnvironment extends Environment {
private readonly delegate;
constructor(config: JestEnvironmentConfig, context: EnvironmentContext);
setup(): Promise<void>;
handleTestEvent(event: Circus.Event): Promise<void> | undefined;
teardown(): Promise<void>;
}
27 changes: 27 additions & 0 deletions examples/example-prj/jest-prisma-ex-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jest_prisma_core_1 = require("@quramy/jest-prisma-core");
const jest_environment_node_single_context_1 = __importDefault(require("jest-environment-node-single-context"));
class PrismaEnvironment extends jest_environment_node_single_context_1.default {
constructor(config, context) {
super(config, context);
this.delegate = new jest_prisma_core_1.PrismaEnvironmentDelegate(config, context);
}
async setup() {
const jestPrisma = await this.delegate.preSetup();
await super.setup();
this.global.jestPrisma = jestPrisma;
}
handleTestEvent(event) {
return this.delegate.handleTestEvent(event);
}
async teardown() {
await Promise.all([super.teardown(), this.delegate.teardown()]);
}
}
exports.default = PrismaEnvironment;
28 changes: 28 additions & 0 deletions examples/example-prj/jest-prisma-ex-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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()]);
}
}
2 changes: 1 addition & 1 deletion examples/example-prj/jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export default {
transform: {
"^.+\\.tsx?$": ["ts-jest", { diagnostics: false }],
},
testEnvironment: "@quramy/jest-prisma/environment",
testEnvironment: "./jest-prisma-ex-env.js",
};
5 changes: 3 additions & 2 deletions examples/example-prj/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"test:ci": "DATABASE_URL=\"file:./test.db\" jest"
},
"devDependencies": {
"@quramy/jest-prisma": "*",
"@prisma/client": "*",
"@quramy/jest-prisma": "*",
"@types/jest": "29.2.1",
"prisma": "*",
"jest": "29.2.2",
"jest-environment-node-single-context": "^29.0.0",
"prisma": "*",
"ts-jest": "29.0.3"
},
"dependencies": {
Expand Down
16 changes: 8 additions & 8 deletions examples/example-prj/src/service/includeWhere.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ describe("Should include date type work arround", () => {
const user = await prisma.user.findFirst({
where: {
createdAt: {
lt: new jestPrisma.Date(),
gte: new jestPrisma.Date(new jestPrisma.Date().getTime() - 1000 * 60 * 60 * 24),
lt: new Date(),
gte: new Date(new Date().getTime() - 1000 * 60 * 60 * 24),
},
},
include: {
posts: {
where: {
createdAt: {
lt: new jestPrisma.Date(),
gte: new jestPrisma.Date(new jestPrisma.Date().getTime() - 1000 * 60 * 60 * 24),
lt: new Date(),
gte: new Date(new Date().getTime() - 1000 * 60 * 60 * 24),
},
},
},
Expand All @@ -47,8 +47,8 @@ describe("Should include date type work arround", () => {
where: {
author: {
createdAt: {
lt: new jestPrisma.Date(),
gte: new jestPrisma.Date(new jestPrisma.Date().getTime() - 1000 * 60 * 60 * 24),
lt: new Date(),
gte: new Date(new Date().getTime() - 1000 * 60 * 60 * 24),
},
},
},
Expand All @@ -58,8 +58,8 @@ describe("Should include date type work arround", () => {
posts: {
where: {
createdAt: {
lt: new jestPrisma.Date(),
gte: new jestPrisma.Date(new jestPrisma.Date().getTime() - 1000 * 60 * 60 * 24),
lt: new Date(),
gte: new Date(new Date().getTime() - 1000 * 60 * 60 * 24),
},
},
},
Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.