diff --git a/.github/workflows/reusable-run-linting-check-and-unit-tests.yml b/.github/workflows/reusable-run-linting-check-and-unit-tests.yml index f98a91353e..b6e8a36e95 100644 --- a/.github/workflows/reusable-run-linting-check-and-unit-tests.yml +++ b/.github/workflows/reusable-run-linting-check-and-unit-tests.yml @@ -44,7 +44,8 @@ jobs: "packages/batch", "packages/commons", "packages/jmespath", - "packages/idempotency" + "packages/idempotency", + "packages/event-handler" ] fail-fast: false steps: @@ -91,16 +92,14 @@ jobs: -w packages/tracer \ -w packages/metrics \ -w packages/parameters \ - -w packages/parser \ - -w packages/event-handler + -w packages/parser - name: Run unit tests run: | npm t -w packages/logger \ -w packages/tracer \ -w packages/metrics \ -w packages/parameters \ - -w packages/parser \ - -w packages/event-handler + -w packages/parser check-examples: runs-on: ubuntu-latest env: diff --git a/.husky/pre-push b/.husky/pre-push index a6182662c5..29e324aa7b 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -3,7 +3,6 @@ npm t \ -w packages/metrics \ -w packages/tracer \ -w packages/parameters \ - -w packages/parser \ - -w packages/event-handler + -w packages/parser npx vitest --run --coverage --changed="$(git merge-base HEAD main)" \ No newline at end of file diff --git a/packages/event-handler/jest.config.cjs b/packages/event-handler/jest.config.cjs deleted file mode 100644 index d5dec2b8f0..0000000000 --- a/packages/event-handler/jest.config.cjs +++ /dev/null @@ -1,29 +0,0 @@ -module.exports = { - displayName: { - name: 'Powertools for AWS Lambda (TypeScript) utility: EVENT HANDLER', - color: 'blue', - }, - runner: 'groups', - moduleNameMapper: { - '^(\\.{1,2}/.*)\\.js$': '$1', - }, - transform: { - '^.+\\.ts?$': 'ts-jest', - }, - moduleFileExtensions: ['js', 'ts'], - collectCoverageFrom: ['**/src/**/*.ts', '!**/node_modules/**'], - testMatch: ['**/?(*.)+(spec|test).ts'], - roots: ['/src', '/tests'], - testPathIgnorePatterns: ['/node_modules/'], - testEnvironment: 'node', - coveragePathIgnorePatterns: ['/node_modules/', 'src/types/index.ts'], - coverageThreshold: { - global: { - statements: 100, - branches: 100, - functions: 100, - lines: 100, - }, - }, - coverageReporters: ['json-summary', 'text', 'lcov'] -}; diff --git a/packages/event-handler/package.json b/packages/event-handler/package.json index 3031eb6e3f..3696fcac2a 100644 --- a/packages/event-handler/package.json +++ b/packages/event-handler/package.json @@ -8,8 +8,10 @@ }, "private": true, "scripts": { - "test": "npm run test:unit", - "test:unit": "jest --group=unit --detectOpenHandles --coverage --verbose", + "test": "vitest --run", + "test:unit": "vitest --run", + "test:unit:coverage": "vitest --run tests/unit --coverage.enabled --coverage.thresholds.100 --coverage.include='src/**'", + "test:unit:types": "echo 'Not Implemented'", "test:e2e:nodejs18x": "echo \"Not implemented\"", "test:e2e:nodejs20x": "echo \"Not implemented\"", "test:e2e": "echo \"Not implemented\"", diff --git a/packages/event-handler/tests/tsconfig.json b/packages/event-handler/tests/tsconfig.json index 45ba862a85..39f442212e 100644 --- a/packages/event-handler/tests/tsconfig.json +++ b/packages/event-handler/tests/tsconfig.json @@ -1,8 +1,8 @@ { "extends": "../tsconfig.json", "compilerOptions": { - "rootDir": "../", + "rootDir": "../../", "noEmit": true }, - "include": ["../src/**/*", "./**/*"] + "include": ["../../testing/src/setupEnv.ts", "../src/**/*", "./**/*"] } diff --git a/packages/event-handler/tests/unit/index.test.ts b/packages/event-handler/tests/unit/index.test.ts index c53ef9e1ce..cc067e7c70 100644 --- a/packages/event-handler/tests/unit/index.test.ts +++ b/packages/event-handler/tests/unit/index.test.ts @@ -1,16 +1,12 @@ -/** - * Test Event Handler - * - * @group unit/event-handler - */ +import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { foo } from '../../src/index.js'; describe('Event Handler', () => { const ENVIRONMENT_VARIABLES = process.env; beforeEach(() => { - jest.clearAllMocks(); - jest.resetModules(); + vi.clearAllMocks(); + vi.resetModules(); process.env = { ...ENVIRONMENT_VARIABLES }; }); diff --git a/packages/event-handler/vitest.config.ts b/packages/event-handler/vitest.config.ts new file mode 100644 index 0000000000..9f1196ef1f --- /dev/null +++ b/packages/event-handler/vitest.config.ts @@ -0,0 +1,8 @@ +import { defineProject } from 'vitest/config'; + +export default defineProject({ + test: { + environment: 'node', + setupFiles: ['../testing/src/setupEnv.ts'], + }, +}); diff --git a/vitest.config.ts b/vitest.config.ts index 989b2c970a..81203c1290 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -15,7 +15,7 @@ export default defineConfig({ ...coverageConfigDefaults.exclude, 'packages/batch/src/types.ts', 'packages/commons/src/types/**', - 'packages/event-handler/**', + 'packages/event-handler/src/types/**', 'packages/idempotency/src/types/**', 'packages/jmespath/src/types.ts', 'packages/logger/**',