Skip to content

Commit

Permalink
Merge pull request #48 from iliubinskii/feature/fix-jest-playwright-c…
Browse files Browse the repository at this point in the history
…onflict

Feature/fix jest playwright conflict
  • Loading branch information
iliubinskii authored Jun 23, 2024
2 parents 6fe97e6 + 8f08179 commit 75b9272
Show file tree
Hide file tree
Showing 34 changed files with 289 additions and 151 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
.DS_Store
.env
.env.e2e
.next
.vercel
blob-report
certificates
coverage
dist
docker
node_modules
playwright/.cache
playwright-report
test-results
5 changes: 5 additions & 0 deletions .env.e2e.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CI=false
BASE_URL=https://preview-api.zero-company.app
JWT_ADMIN_EMAIL=...
JWT_EMAIL=...
JWT_SECRET=...
7 changes: 3 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
* @type {import("eslint").Linter.Config }
*/
const config = {
env: {
es2020: true,
jest: true
},
env: { es2020: true },
extends: ["./.eslintrc.base.cjs"],
globals: { Express: true },
ignorePatterns: ["!.*", "coverage/**", "dist/**", "node_modules/**"],
Expand Down Expand Up @@ -104,6 +101,7 @@ const config = {
"lcfirst",
"localhost",
"logform",
"matchers",
"mjs",
"mongodb",
"multer",
Expand Down Expand Up @@ -140,6 +138,7 @@ const config = {
"ttl",
"txt",
"ucfirst",
"undef",
"unlink",
"uploader",
"upsert",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
branches: [ develop ]
pull_request:
branches: [ main, master ]
workflow_dispatch:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
.DS_Store
.env
.env.e2e
.next
.vercel
blob-report
certificates
coverage
docker
dist
docker
node_modules
playwright/.cache
playwright-report
Expand Down
8 changes: 6 additions & 2 deletions .vercelignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
.DS_Store
.env
.env.e2e
.next
.vercel
blob-report
certificates
coverage
docker
dist
docker
node_modules
.DS_Store
playwright/.cache
playwright-report
test-results
*.test.js
*.test.jsx
*.test.ts
Expand Down
3 changes: 3 additions & 0 deletions api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
lang,
logServerInfo,
logger,
modelsExist,
mongodbConnectionExists,
redisClientExists
} from "../src";
Expand All @@ -30,6 +31,8 @@ export default async function handler(
: lang.MongodbConnectionCacheMiss
);

logger.info(modelsExist() ? lang.ModelsCacheHit : lang.ModelsCacheMiss);

if (SESSION_STORE_PROVIDER === "redis")
logger.info(
redisClientExists() ? lang.RedisClientCacheHit : lang.RedisClientCacheMiss
Expand Down
3 changes: 2 additions & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const config = {
globalTeardown: "./jest.global-teardown.ts",
preset: "ts-jest",
setupFilesAfterEnv: ["jest-extended/all", "./jest.setup-after-env.ts"],
testEnvironment: "node"
testEnvironment: "node",
testPathIgnorePatterns: ["/dist/", "/node_modules/", "/tests/"]
};

export default config;
5 changes: 2 additions & 3 deletions jest.setup-after-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
/* eslint-disable import/no-namespace -- Ok */

import * as config from "./src/config";

jest.mock("./src/config");
import { getMongodbMemoryServerUri } from "./utils";

// @ts-expect-error
config.MONGODB_URI = `mongodb://127.0.0.1:${config.TEST_MONGODB_PORT}/`;
config.MONGODB_URI = getMongodbMemoryServerUri();
2 changes: 2 additions & 0 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "0.1.0",
"private": true,
"description": "Zero Company API",
"keywords": [
"crowdworking"
],
"keywords": [],
"repository": {
"type": "git",
"url": "https://github.com/iliubinskii/zero-company-api"
Expand Down Expand Up @@ -51,6 +49,7 @@
"prepare": "husky",
"start": "node dist/index.js",
"test": "jest --coverage",
"test-e2e": "playwright test",
"type-check": "tsc --incremental false --noEmit"
},
"lint-staged": {
Expand Down Expand Up @@ -102,6 +101,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@next/eslint-plugin-next": "^14.2.3",
"@playwright/test": "^1.44.1",
"@types/eslint": "^8.56.10",
Expand Down
12 changes: 2 additions & 10 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
/* eslint-disable node/no-unpublished-import -- Ok */

import { bool, cleanEnv } from "envalid";
import { BASE_URL, CI } from "./tests";
import { defineConfig, devices } from "@playwright/test";
import { config } from "dotenv";

config();

// eslint-disable-next-line no-process-env -- Ok
const { CI } = cleanEnv(process.env, {
CI: bool({ default: false })
});

export default defineConfig({
forbidOnly: CI,
Expand All @@ -24,7 +16,7 @@ export default defineConfig({
retries: CI ? 2 : 0,
testDir: "./tests",
use: {
baseURL: "https://preview-api.zero-company.app/",
baseURL: BASE_URL,
trace: "on-first-retry"
},
workers: CI ? 1 : 2
Expand Down
2 changes: 0 additions & 2 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const env = cleanEnv(process.env, {
AUTH0_CLIENT_SECRET: str(),
AUTH0_DOMAIN: str(),
AUTH0_RETURN_URL: str(),
CI: bool({ default: false }),
CLOUDINARY_API_KEY: str(),
CLOUDINARY_API_SECRET: str(),
CLOUDINARY_BASE_FOLDER: str(),
Expand Down Expand Up @@ -61,7 +60,6 @@ export const {
AUTH0_CLIENT_SECRET,
AUTH0_DOMAIN,
AUTH0_RETURN_URL,
CI,
CLOUDINARY_API_KEY,
CLOUDINARY_API_SECRET,
CLOUDINARY_BASE_FOLDER,
Expand Down
16 changes: 11 additions & 5 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
import type { CSSProperties, DetailedHTMLProps, HTMLAttributes } from "react";
import type { Jwt } from "./schema";

export type IntrinsicElement = DetailedHTMLProps<
HTMLAttributes<HTMLElement>,
HTMLElement
> & { name: string; role: string; style?: CSSProperties };

declare global {
namespace JSX {
interface IntrinsicElements {
Expand All @@ -18,6 +13,12 @@ declare global {
}
}

declare module "@jest/expect" {
export interface Matchers<R>
// eslint-disable-next-line no-undef -- Ok
extends CustomMatchers<R> {}
}

declare module "express-serve-static-core" {
interface Request {
idParam?: string | undefined;
Expand All @@ -43,3 +44,8 @@ declare module "express-session" {
successReturnUrl?: string | undefined;
}
}

export type IntrinsicElement = DetailedHTMLProps<
HTMLAttributes<HTMLElement>,
HTMLElement
> & { name: string; role: string; style?: CSSProperties };
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from "./middleware";
export * from "./providers";
export * from "./routes";
export * from "./schema";
export * from "./schema-mongodb";
export * from "./services";
export * from "./types";
export * from "./utils";
2 changes: 2 additions & 0 deletions src/langs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const lang = {
JwtVerificationFailed: "JWT verification failed",
LogLevel: "Log level",
MethodNotAllowed: "Method not allowed. Https is required",
ModelsCacheHit: "Models cache hit",
ModelsCacheMiss: "Models cache miss",
MongodbAll: "MongoDB all",
MongodbClose: "MongoDB close",
MongodbConnected: "MongoDB connected",
Expand Down
2 changes: 1 addition & 1 deletion src/providers/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createClient } from "redis";
import { lang } from "../langs";
import { logger } from "../services";

// Cache the connection in serverless environments
// Cache the client in serverless environments
let cachedClient: ReturnType<typeof createClient> | undefined;

/**
Expand Down
12 changes: 6 additions & 6 deletions src/routes/categories/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
} from "../../schema";
import {
assertDefined,
assertValidForJsonStringify,
buildErrorResponse,
dangerouslyAssumeJsonTransform,
sendResponse,
wrapAsyncHandler
} from "../../utils";
Expand All @@ -40,7 +40,7 @@ export function createCategoryControllers(
sendResponse<Routes["/categories"]["post"]>(
res,
StatusCodes.CREATED,
assertValidForJsonStringify(category)
dangerouslyAssumeJsonTransform(category)
);
} else
sendResponse<Routes["/categories"]["post"]>(
Expand All @@ -67,7 +67,7 @@ export function createCategoryControllers(
sendResponse<Routes["/categories"]["get"]>(
res,
StatusCodes.OK,
assertValidForJsonStringify(categories)
dangerouslyAssumeJsonTransform(categories)
);
} else
sendResponse<Routes["/categories"]["get"]>(
Expand All @@ -85,7 +85,7 @@ export function createCategoryControllers(
sendResponse<Routes["/categories/{id}"]["get"]>(
res,
StatusCodes.OK,
assertValidForJsonStringify(category)
dangerouslyAssumeJsonTransform(category)
);
else
sendResponse<Routes["/categories/{id}"]["get"]>(
Expand All @@ -108,7 +108,7 @@ export function createCategoryControllers(
sendResponse<Routes["/categories/{id}/companies"]["get"]>(
res,
StatusCodes.OK,
assertValidForJsonStringify(companies)
dangerouslyAssumeJsonTransform(companies)
);
} else
sendResponse<Routes["/categories/{id}/companies"]["get"]>(
Expand All @@ -129,7 +129,7 @@ export function createCategoryControllers(
sendResponse<Routes["/categories/{id}"]["put"]>(
res,
StatusCodes.OK,
assertValidForJsonStringify(category)
dangerouslyAssumeJsonTransform(category)
);
else
sendResponse<Routes["/categories/{id}"]["put"]>(
Expand Down
12 changes: 6 additions & 6 deletions src/routes/companies/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
} from "../../schema";
import {
assertDefined,
assertValidForJsonStringify,
buildErrorResponse,
dangerouslyAssumeJsonTransform,
sendResponse,
wrapAsyncHandler
} from "../../utils";
Expand Down Expand Up @@ -42,7 +42,7 @@ export function createCompanyControllers(
sendResponse<Routes["/companies"]["post"]>(
res,
StatusCodes.CREATED,
assertValidForJsonStringify(company)
dangerouslyAssumeJsonTransform(company)
);
} else
sendResponse<Routes["/companies"]["post"]>(
Expand Down Expand Up @@ -76,7 +76,7 @@ export function createCompanyControllers(
sendResponse<Routes["/companies/{id}/found"]["post"]>(
res,
StatusCodes.OK,
assertValidForJsonStringify(company)
dangerouslyAssumeJsonTransform(company)
);
else
sendResponse<Routes["/companies/{id}/found"]["post"]>(
Expand All @@ -94,7 +94,7 @@ export function createCompanyControllers(
sendResponse<Routes["/companies"]["get"]>(
res,
StatusCodes.OK,
assertValidForJsonStringify(companies)
dangerouslyAssumeJsonTransform(companies)
);
} else
sendResponse<Routes["/companies"]["get"]>(
Expand All @@ -112,7 +112,7 @@ export function createCompanyControllers(
sendResponse<Routes["/companies/{id}"]["get"]>(
res,
StatusCodes.OK,
assertValidForJsonStringify(company)
dangerouslyAssumeJsonTransform(company)
);
else
sendResponse<Routes["/companies/{id}"]["get"]>(
Expand All @@ -133,7 +133,7 @@ export function createCompanyControllers(
sendResponse<Routes["/companies/{id}"]["put"]>(
res,
StatusCodes.OK,
assertValidForJsonStringify(company)
dangerouslyAssumeJsonTransform(company)
);
else
sendResponse<Routes["/companies/{id}"]["put"]>(
Expand Down
Loading

0 comments on commit 75b9272

Please sign in to comment.