Skip to content

test(parser): migrate to vitest & simplify structure #3248

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

Closed
wants to merge 7 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
"packages/idempotency",
"packages/jmespath",
"packages/logger",
"packages/parser",
]
fail-fast: false
steps:
Expand Down Expand Up @@ -91,14 +92,12 @@ jobs:
run: |
npm run lint -w -w packages/tracer \
-w packages/metrics \
-w packages/parameters \
-w packages/parser
-w packages/parameters
- name: Run unit tests
run: |
npm t -w packages/tracer \
-w packages/metrics \
-w packages/parameters \
-w packages/parser
-w packages/parameters
check-examples:
runs-on: ubuntu-latest
env:
Expand Down
30 changes: 0 additions & 30 deletions packages/parser/jest.config.cjs

This file was deleted.

12 changes: 8 additions & 4 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
"access": "public"
},
"scripts": {
"test": "npm run test:unit",
"test:unit": "jest --group=unit --detectOpenHandles --coverage --verbose",
"jest": "jest --detectOpenHandles --coverage --verbose",
"watch": "jest --watch",
"test": "vitest --run tests/unit",
"test:unit": "vitest --run tests/unit",
"test:unit:coverage": "vitest --run tests/unit --coverage.enabled --coverage.thresholds.100 --coverage.include='src/**'",
"test:unit:types": "echo 'Not Implemented'",
"test:unit:watch": "vitest tests/unit",
"test:e2e:nodejs18x": "echo 'Not implemented'",
"test:e2e:nodejs20x": "echo 'Not implemented'",
"test:e2e": "echo 'Not implemented'",
"build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
"build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
"build": "npm run build:esm & npm run build:cjs",
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/src/parserDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type { ParserOutput } from './types/parser.js';
*
* class Lambda implements LambdaInterface {
*
* @parser({ envelope: SqsEnvelope, schema: OrderSchema })
* @parser({ envelope: SqsEnvelope, schema: OrderSchema })
* public async handler(event: Order, _context: Context): Promise<unknown> {
* // sqs event is parsed and the payload is extracted and parsed
* // apply business logic to your Order event
Expand Down Expand Up @@ -54,7 +54,7 @@ import type { ParserOutput } from './types/parser.js';
*
* class Lambda implements LambdaInterface {
*
* @parser({ envelope: SqsEnvelope, schema: OrderSchema, safeParse: true })
* @parser({ envelope: SqsEnvelope, schema: OrderSchema, safeParse: true })
* public async handler(event: ParsedResult<Order>, _context: unknown): Promise<unknown> {
* if (event.success) {
* // event.data is the parsed event object of type Order
Expand Down
21 changes: 21 additions & 0 deletions packages/parser/src/schemas/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import z from 'zod';

/**
* A base schema for record objects with string keys and string values
*/
const RecordSchema = z.record(z.string());

/**
* A base schema for HTTP methods
*/
const HttpMethodSchema = z.enum([
'GET',
'POST',
'PUT',
'PATCH',
'DELETE',
'HEAD',
'OPTIONS',
]);

export { RecordSchema, HttpMethodSchema };
28 changes: 0 additions & 28 deletions packages/parser/tests/events/albEventPathTrailingSlash.json

This file was deleted.

72 changes: 0 additions & 72 deletions packages/parser/tests/events/apiGatewayAuthorizerRequestEvent.json

This file was deleted.

This file was deleted.

52 changes: 0 additions & 52 deletions packages/parser/tests/events/apiGatewayAuthorizerV2Event.json

This file was deleted.

71 changes: 0 additions & 71 deletions packages/parser/tests/events/apiGatewayProxyEvent.json

This file was deleted.

Loading
Loading