diff --git a/packages/app/api-common/package.json b/packages/app/api-common/package.json index 7a6b9a70..8cc8c783 100644 --- a/packages/app/api-common/package.json +++ b/packages/app/api-common/package.json @@ -39,12 +39,12 @@ "@lokalise/eslint-config": "latest", "@lokalise/prettier-config": "latest", "@lokalise/package-vite-config": "latest", - "@vitest/coverage-v8": "^1.6.0", + "@vitest/coverage-v8": "^2.0.4", "prettier": "3.3.3", "rimraf": "^5.0.5", "typescript": "5.5.4", "vite": "5.3.4", - "vitest": "^1.6.0" + "vitest": "^2.0.4" }, "prettier": "@lokalise/prettier-config" } diff --git a/packages/app/backend-http-client/package.json b/packages/app/backend-http-client/package.json index a0863e15..284b663c 100644 --- a/packages/app/backend-http-client/package.json +++ b/packages/app/backend-http-client/package.json @@ -40,9 +40,8 @@ "@biomejs/biome": "^1.8.3", "@lokalise/biome-config": "^1.0.0", "@types/node": "^22.0.0", - "@vitest/coverage-v8": "^2.0.1", - "auto-changelog": "^2.4.0", + "@vitest/coverage-v8": "^2.0.4", "typescript": "^5.5.4", - "vitest": "^2.0.1" + "vitest": "^2.0.4" } } diff --git a/packages/app/context-fastify-plugins/package.json b/packages/app/context-fastify-plugins/package.json index d0c06605..a1640786 100644 --- a/packages/app/context-fastify-plugins/package.json +++ b/packages/app/context-fastify-plugins/package.json @@ -56,7 +56,7 @@ "@types/node": "^22.0.0", "@typescript-eslint/eslint-plugin": "^7.12.0", "@typescript-eslint/parser": "^7.12.0", - "@vitest/coverage-v8": "1.6.0", + "@vitest/coverage-v8": "^2.0.4", "eslint": "^8.57.0", "eslint-plugin-import": "^2.29.1", "eslint-plugin-vitest": "0.4.1", @@ -66,7 +66,7 @@ "prettier": "^3.3.3", "rimraf": "^5.0.1", "typescript": "^5.5.4", - "vitest": "1.6.0" + "vitest": "^2.0.4" }, "prettier": "@lokalise/prettier-config" } diff --git a/packages/app/context-fastify-plugins/src/plugins/unhandledExceptionPlugin.spec.ts b/packages/app/context-fastify-plugins/src/plugins/unhandledExceptionPlugin.spec.ts index f088d091..821ef5ff 100644 --- a/packages/app/context-fastify-plugins/src/plugins/unhandledExceptionPlugin.spec.ts +++ b/packages/app/context-fastify-plugins/src/plugins/unhandledExceptionPlugin.spec.ts @@ -1,7 +1,7 @@ import type { ErrorReport } from '@lokalise/error-utils' +import { isInternalError } from '@lokalise/node-core' import fastify from 'fastify' import type { RouteHandlerMethod } from 'fastify/types/route' -import { beforeEach } from 'vitest' import { getRequestIdFastifyAppConfig, @@ -9,14 +9,12 @@ import { } from './requestContextProviderPlugin' import { unhandledExceptionPlugin } from './unhandledExceptionPlugin' -const errors: ErrorReport[] = [] - process.on('unhandledRejection', (error) => { console.error('Unhandled Rejection:', error) // Optionally throw an error here to fail the test }) -async function initApp(routeHandler: RouteHandlerMethod) { +async function initApp(routeHandler: RouteHandlerMethod, errors: ErrorReport[]) { const app = fastify({ ...getRequestIdFastifyAppConfig(), }) @@ -37,26 +35,49 @@ async function initApp(routeHandler: RouteHandlerMethod) { handler: routeHandler, }) await app.ready() + return app } -// This needs to be skipped in CI, because vitest fails the run if there are any unhandled errors. See https://github.com/vitest-dev/vitest/issues/5796 -describe.skip('unhandledExceptionPlugin', () => { - beforeEach(() => { - errors.splice(0, errors.length) +describe('unhandledExceptionPlugin', () => { + it('handled unhandled rejection with Error type', async () => { + const errors: ErrorReport[] = [] + const app = await initApp((_req, res) => { + void new Promise(() => { + throw new Error('new test unhandled error') + }) + return res.status(204).send() + }, errors) + const response = await app.inject().get('/').end() + expect(response.statusCode).toBe(204) + + await vitest.waitUntil( + () => { + return errors.length > 0 + }, + { + interval: 50, + timeout: 2000, + }, + ) + + expect(errors).toHaveLength(1) + const error = errors[0] + expect(error.error.message).toBe('new test unhandled error') }) - it('handled unhandled rejection', async () => { - const app = await initApp((req, res) => { + it('handled unhandled rejection with not error type', async () => { + const errors: ErrorReport[] = [] + const app = await initApp((_req, res) => { void new Promise(() => { - throw new Error('new unhandled error') + throw 'this is my test unhandled error' }) return res.status(204).send() - }) + }, errors) const response = await app.inject().get('/').end() expect(response.statusCode).toBe(204) - const errorsReported = await vitest.waitUntil( + await vitest.waitUntil( () => { return errors.length > 0 }, @@ -66,6 +87,13 @@ describe.skip('unhandledExceptionPlugin', () => { }, ) - expect(errorsReported).toBe(true) + expect(errors).toHaveLength(1) + const error = errors[0] + expect(isInternalError(error.error)).toBe(true) + expect(error.error).toMatchObject({ + errorCode: 'UNHANDLED_REJECTION', + message: 'Unhandled rejection', + details: { errorObject: '"this is my test unhandled error"' }, + }) }) }) diff --git a/packages/app/error-utils/package.json b/packages/app/error-utils/package.json index 5163af6d..082bc47d 100644 --- a/packages/app/error-utils/package.json +++ b/packages/app/error-utils/package.json @@ -32,12 +32,12 @@ "@lokalise/node-core": "^11.2.0", "@lokalise/prettier-config": "latest", "@lokalise/package-vite-config": "latest", - "@vitest/coverage-v8": "^1.6.0", + "@vitest/coverage-v8": "^2.0.4", "prettier": "^3.3.3", "rimraf": "^5.0.7", "typescript": "5.5.4", "vite": "5.3.4", - "vitest": "^1.6.0" + "vitest": "^2.0.4" }, "prettier": "@lokalise/prettier-config" } diff --git a/packages/app/events-common/package.json b/packages/app/events-common/package.json index 6aa102e4..ec20ccc5 100644 --- a/packages/app/events-common/package.json +++ b/packages/app/events-common/package.json @@ -39,12 +39,12 @@ "@lokalise/prettier-config": "latest", "@lokalise/package-vite-config": "latest", "@message-queue-toolkit/sns": "^17.0.0", - "@vitest/coverage-v8": "^1.6.0", + "@vitest/coverage-v8": "^2.0.4", "prettier": "3.3.3", "rimraf": "^5.0.7", "typescript": "5.5.4", "vite": "5.3.4", - "vitest": "1.6.0" + "vitest": "^2.0.4" }, "prettier": "@lokalise/prettier-config" } diff --git a/packages/app/events-common/vite.config.ts b/packages/app/events-common/vite.config.ts index 490254dc..1b996157 100644 --- a/packages/app/events-common/vite.config.ts +++ b/packages/app/events-common/vite.config.ts @@ -6,17 +6,17 @@ import packageJson from './package.json' /* eslint-disable import/no-default-export */ export default defineConfig({ - entry: resolve(__dirname, 'src/index.ts'), - dependencies: Object.keys(packageJson.peerDependencies), - test: { - coverage: { - exclude: ['src/**/*.spec.ts', 'src/**/*.test.ts', 'src/**/*Types.ts', 'src/**/*types.ts'], - thresholds: { - lines: 96, - functions: 0, // not applicable - branches: 0, // not applicable - statements: 96, - }, - }, - }, + entry: resolve(__dirname, 'src/index.ts'), + dependencies: Object.keys(packageJson.peerDependencies), + test: { + coverage: { + exclude: ['src/**/index.ts', 'src/**/*.spec.ts', 'src/**/*.test.ts', 'src/**/*types.ts'], + thresholds: { + lines: 96, + functions: 0, // not applicable + branches: 0, // not applicable + statements: 96, + }, + }, + }, }) diff --git a/packages/app/id-utils/package.json b/packages/app/id-utils/package.json index 8a8877cb..d9cc850c 100644 --- a/packages/app/id-utils/package.json +++ b/packages/app/id-utils/package.json @@ -42,12 +42,12 @@ "@lokalise/eslint-config": "latest", "@lokalise/package-vite-config": "latest", "@lokalise/prettier-config": "latest", - "@vitest/coverage-v8": "^1.6.0", + "@vitest/coverage-v8": "^2.0.4", "prettier": "^3.3.3", "rimraf": "^5.0.7", "typescript": "5.5.4", "vite": "5.3.4", - "vitest": "^1.6.0" + "vitest": "^2.0.4" }, "prettier": "@lokalise/prettier-config" } diff --git a/packages/app/non-translatable-markup/package.json b/packages/app/non-translatable-markup/package.json index 51da7228..2a89a3c9 100644 --- a/packages/app/non-translatable-markup/package.json +++ b/packages/app/non-translatable-markup/package.json @@ -41,12 +41,12 @@ "@lokalise/eslint-config": "latest", "@lokalise/prettier-config": "latest", "@lokalise/package-vite-config": "latest", - "@vitest/coverage-v8": "^1.6.0", + "@vitest/coverage-v8": "^2.0.4", "prettier": "3.3.3", "rimraf": "^5.0.7", "typescript": "5.5.4", "vite": "5.3.4", - "vitest": "^1.6.0" + "vitest": "^2.0.4" }, "prettier": "@lokalise/prettier-config" } diff --git a/packages/app/prisma-utils/package.json b/packages/app/prisma-utils/package.json index 60da5ee3..f73d629f 100644 --- a/packages/app/prisma-utils/package.json +++ b/packages/app/prisma-utils/package.json @@ -49,13 +49,13 @@ "@lokalise/biome-config": "*", "@lokalise/package-vite-config": "*", "@prisma/client": "^5.14.0", - "@vitest/coverage-v8": "^1.6.0", + "@vitest/coverage-v8": "^2.0.4", "cross-env": "^7.0.3", "dotenv-cli": "^7.4.1", "prisma": "^5.14.0", "rimraf": "^5.0.7", "typescript": "5.5.4", "vite": "5.3.4", - "vitest": "^1.6.0" + "vitest": "^2.0.4" } } diff --git a/packages/app/prisma-utils/src/prismaTransaction.spec.ts b/packages/app/prisma-utils/src/prismaTransaction.spec.ts index 602cba0b..2ce2427f 100644 --- a/packages/app/prisma-utils/src/prismaTransaction.spec.ts +++ b/packages/app/prisma-utils/src/prismaTransaction.spec.ts @@ -64,7 +64,7 @@ describe('prismaTransaction', () => { }) // Then - expect(result.result?.value).toMatchObject(TEST_ITEM_1.value) + expect(result.result?.value).toBe(TEST_ITEM_1.value) expect(result.result?.id).toBeDefined() }) diff --git a/packages/app/prisma-utils/vitest.config.mts b/packages/app/prisma-utils/vitest.config.mts index 088e3dba..b5f7163a 100644 --- a/packages/app/prisma-utils/vitest.config.mts +++ b/packages/app/prisma-utils/vitest.config.mts @@ -16,8 +16,9 @@ export default defineConfig({ coverage: { include: ['src/**/*.ts'], exclude: [ - 'src/index.ts', - 'src/types.ts' + 'src/**/index.ts', + 'src/**/types.ts', + 'src/**/*.spec.ts' ], reporter: ['text'], all: true, diff --git a/packages/app/script-utils/package.json b/packages/app/script-utils/package.json index 4aa1b036..4b5a0f03 100644 --- a/packages/app/script-utils/package.json +++ b/packages/app/script-utils/package.json @@ -40,12 +40,12 @@ "@lokalise/eslint-config": "latest", "@lokalise/package-vite-config": "latest", "@lokalise/prettier-config": "latest", - "@vitest/coverage-v8": "^1.6.0", + "@vitest/coverage-v8": "^2.0.4", "prettier": "^3.3.3", "rimraf": "^5.0.7", "typescript": "5.5.4", "vite": "5.3.4", - "vitest": "^1.6.0" + "vitest": "^2.0.4" }, "prettier": "@lokalise/prettier-config" } diff --git a/packages/app/supported-languages/package.json b/packages/app/supported-languages/package.json index 0298c675..9635812d 100644 --- a/packages/app/supported-languages/package.json +++ b/packages/app/supported-languages/package.json @@ -42,12 +42,12 @@ "@lokalise/prettier-config": "latest", "@lokalise/node-core": "^11.2.0", "@rollup/plugin-typescript": "^11.1.3", - "@vitest/coverage-v8": "^1.6.0", + "@vitest/coverage-v8": "^2.0.4", "prettier": "^3.3.3", "rimraf": "^5.0.7", "rollup": "^4.4.1", "typescript": "5.5.4", - "vitest": "^1.6.0" + "vitest": "^2.0.4" }, "prettier": "@lokalise/prettier-config" } diff --git a/packages/app/universal-ts-utils/package.json b/packages/app/universal-ts-utils/package.json index fe701a80..b6c9bdee 100644 --- a/packages/app/universal-ts-utils/package.json +++ b/packages/app/universal-ts-utils/package.json @@ -33,9 +33,9 @@ "@biomejs/biome": "^1.8.3", "@lokalise/biome-config": "^1.0.0", "@types/node": "^22.0.0", - "@vitest/coverage-v8": "^2.0.1", + "@vitest/coverage-v8": "^2.0.4", "auto-changelog": "^2.4.0", "typescript": "^5.5.4", - "vitest": "^2.0.1" + "vitest": "^2.0.4" } } diff --git a/packages/app/websockets-common/package.json b/packages/app/websockets-common/package.json index 32e6c0ec..77765742 100644 --- a/packages/app/websockets-common/package.json +++ b/packages/app/websockets-common/package.json @@ -40,7 +40,7 @@ "rimraf": "^5.0.7", "typescript": "~5.5.4", "vite": "5.3.4", - "vitest": "1.6.0" + "vitest": "^2.0.4" }, "dependencies": { "socket.io": "^4.7.5",