Skip to content

Commit 3789076

Browse files
authored
test(parser): migrate to vitest (#3299)
1 parent 112b4bb commit 3789076

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+67
-239
lines changed

Diff for: .github/workflows/reusable-run-linting-check-and-unit-tests.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
"packages/jmespath",
4949
"packages/logger",
5050
"packages/tracer",
51+
"packages/parser",
5152
]
5253
fail-fast: false
5354
steps:
@@ -91,13 +92,11 @@ jobs:
9192
- name: Run linting
9293
run: |
9394
npm run lint -w packages/metrics \
94-
-w packages/parameters \
95-
-w packages/parser
95+
-w packages/parameters
9696
- name: Run unit tests
9797
run: |
9898
npm t -w packages/metrics \
99-
-w packages/parameters \
100-
-w packages/parser
99+
-w packages/parameters
101100
check-examples:
102101
runs-on: ubuntu-latest
103102
env:

Diff for: .husky/pre-push

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
npm t \
22
-w packages/metrics \
3-
-w packages/parameters \
4-
-w packages/parser
3+
-w packages/parameters
54

6-
npx vitest --run --coverage --changed="$(git merge-base HEAD main)" tests/unit
5+
npx vitest --run \
6+
--exclude tests/unit/layer-publisher.test.ts \
7+
--coverage --coverage.thresholds.100 \
8+
--changed="$(git merge-base HEAD main)" \
9+
tests/unit

Diff for: packages/parser/jest.config.cjs

-30
This file was deleted.

Diff for: packages/parser/package.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
"access": "public"
1111
},
1212
"scripts": {
13-
"test": "npm run test:unit",
14-
"test:unit": "jest --group=unit --detectOpenHandles --coverage --verbose",
15-
"jest": "jest --detectOpenHandles --coverage --verbose",
16-
"watch": "jest --watch",
13+
"test": "vitest --run tests/unit",
14+
"test:unit": "vitest --run tests/unit",
15+
"test:unit:coverage": "vitest --run tests/unit --coverage.enabled --coverage.thresholds.100 --coverage.include='src/**'",
16+
"test:unit:types": "vitest --run tests/types --typecheck",
17+
"test:unit:watch": "vitest tests/unit",
18+
"test:e2e:nodejs18x": "echo 'Not implemented'",
19+
"test:e2e:nodejs20x": "echo 'Not implemented'",
20+
"test:e2e": "echo 'Not implemented'",
1721
"build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
1822
"build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
1923
"build": "npm run build:esm & npm run build:cjs",

Diff for: packages/parser/tests/unit/types.test.ts renamed to packages/parser/tests/types/envelopes.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, it } from 'vitest';
12
import { z } from 'zod';
23
import {
34
ApiGatewayEnvelope,
@@ -30,7 +31,7 @@ describe('Types ', () => {
3031
{ envelope: LambdaFunctionUrlEnvelope, name: 'LambdaFunctionUrl' },
3132
{ envelope: VpcLatticeEnvelope, name: 'VpcLattice' },
3233
{ envelope: VpcLatticeV2Envelope, name: 'VpcLatticeV2' },
33-
])('should infer object for $name envelope', (testCase) => {
34+
])('infers object types for $name envelope', (testCase) => {
3435
type Result = ParserOutput<typeof userSchema, typeof testCase.envelope>;
3536
// Define the expected type
3637

@@ -57,7 +58,7 @@ describe('Types ', () => {
5758
{ envelope: SqsEnvelope, name: 'Sqs' },
5859
{ envelope: SnsEnvelope, name: 'Sns' },
5960
{ envelope: SnsSqsEnvelope, name: 'SnsSqs' },
60-
])('should infer array type with $name envelope', (testCase) => {
61+
])('infers array types with $name envelope', (testCase) => {
6162
// Define the expected type
6263
type Result = ParserOutput<typeof userSchema, typeof testCase.envelope>;
6364

Diff for: packages/parser/tests/unit/envelope.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
/**
2-
* Test decorator parser
3-
*
4-
* @group unit/parser
5-
*/
6-
1+
import { describe, expect, it } from 'vitest';
72
import { ZodError, z } from 'zod';
83
import { Envelope } from '../../src/envelopes/envelope.js';
94

Diff for: packages/parser/tests/unit/envelopes/apigw.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
/**
2-
* Test built-in API Gateway REST envelope
3-
*
4-
* @group unit/parser/envelopes/apigw
5-
*/
6-
1+
import { describe, expect, it } from 'vitest';
72
import { ZodError } from 'zod';
83
import { ApiGatewayEnvelope } from '../../../src/envelopes/index.js';
94
import { ParseError } from '../../../src/errors.js';

Diff for: packages/parser/tests/unit/envelopes/apigwv2.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
/**
2-
* Test built-in API Gateway HTTP API (v2) envelope
3-
*
4-
* @group unit/parser/envelopes/apigwv2
5-
*/
6-
1+
import { describe, expect, it } from 'vitest';
72
import { ZodError } from 'zod';
83
import { ApiGatewayV2Envelope } from '../../../src/envelopes/index.js';
94
import { ParseError } from '../../../src/errors.js';

Diff for: packages/parser/tests/unit/envelopes/cloudwatch.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
/**
2-
* Test built in schema envelopes for CloudWatch
3-
*
4-
* @group unit/parser/envelopes
5-
*/
6-
71
import { gzipSync } from 'node:zlib';
82
import { generateMock } from '@anatine/zod-mock';
3+
import { describe, expect, it } from 'vitest';
94
import { ZodError } from 'zod';
105
import { ParseError } from '../../../src';
116
import { CloudWatchEnvelope } from '../../../src/envelopes/index.js';

Diff for: packages/parser/tests/unit/envelopes/dynamodb.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
/**
2-
* Test built in schema envelopes for api gateway v2
3-
*
4-
* @group unit/parser/envelopes
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
82
import type { AttributeValue, DynamoDBStreamEvent } from 'aws-lambda';
3+
import { describe, expect, it } from 'vitest';
94
import { ZodError, z } from 'zod';
105
import { DynamoDBStreamEnvelope } from '../../../src/envelopes/index.js';
116
import { ParseError } from '../../../src/errors.js';

Diff for: packages/parser/tests/unit/envelopes/eventbridge.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
/**
2-
* Test built in schema envelopes for event bridge
3-
*
4-
* @group unit/parser/envelopes
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
82
import type { EventBridgeEvent } from 'aws-lambda';
3+
import { describe, expect, it } from 'vitest';
94
import { ZodError } from 'zod';
105
import { EventBridgeEnvelope } from '../../../src/envelopes/index.js';
116
import { ParseError } from '../../../src/errors.js';

Diff for: packages/parser/tests/unit/envelopes/kafka.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
/**
2-
* Test built in schema envelopes for api gateway v2
3-
*
4-
* @group unit/parser/envelopes
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
82
import type { MSKEvent, SelfManagedKafkaEvent } from 'aws-lambda';
3+
import { describe, expect, it } from 'vitest';
94
import { ParseError } from '../../../src';
105
import { KafkaEnvelope } from '../../../src/envelopes/index.js';
116
import { TestEvents, TestSchema } from '../schema/utils.js';

Diff for: packages/parser/tests/unit/envelopes/kinesis-firehose.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
/**
2-
* Test built in schema envelopes for Kinesis Firehose
3-
*
4-
* @group unit/parser/envelopes
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
2+
import { describe, expect, it } from 'vitest';
83
import { ZodError, type z } from 'zod';
94
import { ParseError } from '../../../src';
105
import { KinesisFirehoseEnvelope } from '../../../src/envelopes/index.js';

Diff for: packages/parser/tests/unit/envelopes/kinesis.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
/**
2-
* Test built in schema envelopes for Kinesis
3-
*
4-
* @group unit/parser/envelopes
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
82
import type { KinesisStreamEvent } from 'aws-lambda';
3+
import { describe, expect, it } from 'vitest';
94
import { KinesisEnvelope } from '../../../src/envelopes/index.js';
105
import { ParseError } from '../../../src/errors.js';
116
import { TestEvents, TestSchema } from '../schema/utils.js';

Diff for: packages/parser/tests/unit/envelopes/lambda.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
/**
2-
* Test built in schema envelopes for Lambda Functions URL
3-
*
4-
* @group unit/parser/envelopes
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
82
import type { APIGatewayProxyEventV2 } from 'aws-lambda';
3+
import { describe, expect, it } from 'vitest';
94
import { ZodError } from 'zod';
105
import { ParseError } from '../../../src';
116
import { LambdaFunctionUrlEnvelope } from '../../../src/envelopes/index.js';

Diff for: packages/parser/tests/unit/envelopes/sns.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
/**
2-
* Test built in schema envelopes for SNS
3-
*
4-
* @group unit/parser/envelopes
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
82
import type { SNSEvent, SQSEvent } from 'aws-lambda';
3+
import { describe, expect, it } from 'vitest';
94
import { ZodError, type z } from 'zod';
105
import { SnsEnvelope, SnsSqsEnvelope } from '../../../src/envelopes/index.js';
116
import { ParseError } from '../../../src/errors.js';

Diff for: packages/parser/tests/unit/envelopes/sqs.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
/**
2-
* Test built in schema envelopes for sqs
3-
*
4-
* @group unit/parser/envelopes
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
82
import type { SQSEvent } from 'aws-lambda';
3+
import { describe, expect, it } from 'vitest';
94
import { ZodError } from 'zod';
105
import { SqsEnvelope } from '../../../src/envelopes/sqs.js';
116
import { ParseError } from '../../../src/errors.js';

Diff for: packages/parser/tests/unit/envelopes/vpc-lattice.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
/**
2-
* Test built in schema envelopes for VPC Lattice
3-
*
4-
* @group unit/parser/envelopes
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
2+
import { describe, expect, it } from 'vitest';
83
import { ZodError } from 'zod';
94
import { ParseError } from '../../../src';
105
import { VpcLatticeEnvelope } from '../../../src/envelopes/index.js';

Diff for: packages/parser/tests/unit/envelopes/vpc-latticev2.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
/**
2-
* Test built in schema envelopes for VPC Lattice V2
3-
*
4-
* @group unit/parser/envelopes
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
2+
import { describe, expect, it } from 'vitest';
83
import { ZodError } from 'zod';
94
import { ParseError } from '../../../src';
105
import { VpcLatticeV2Envelope } from '../../../src/envelopes/index.js';

Diff for: packages/parser/tests/unit/helpers.test.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
/**
2-
* Test decorator parser
3-
*
4-
* @group unit/parser
5-
*/
1+
import { describe, expect, it } from 'vitest';
62
import { z } from 'zod';
73
import { JSONStringified } from '../../src/helpers.js';
84
import { AlbSchema } from '../../src/schemas/alb.js';

Diff for: packages/parser/tests/unit/parser.decorator.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
/**
2-
* Test decorator parser
3-
*
4-
* @group unit/parser
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
82
import type { LambdaInterface } from '@aws-lambda-powertools/commons/lib/esm/types';
93
import type { Context } from 'aws-lambda';
4+
import { describe, expect, it } from 'vitest';
105
import type { z } from 'zod';
116
import { EventBridgeEnvelope } from '../../src/envelopes/index.js';
127
import { ParseError } from '../../src/errors.js';

Diff for: packages/parser/tests/unit/parser.middy.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
/**
2-
* Test middleware parser
3-
*
4-
* @group unit/parser
5-
*/
6-
71
import { generateMock } from '@anatine/zod-mock';
82
import middy from '@middy/core';
93
import type { Context } from 'aws-lambda';
4+
import { describe, expect, it } from 'vitest';
105
import type { ZodSchema, z } from 'zod';
116
import { ParseError } from '../../src';
127
import { EventBridgeEnvelope, SqsEnvelope } from '../../src/envelopes';

Diff for: packages/parser/tests/unit/schema/alb.test.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
/**
2-
* Test built in schema
3-
*
4-
* @group unit/parser/schema/
5-
*/
1+
import { describe, expect, it } from 'vitest';
62
import { AlbMultiValueHeadersSchema, AlbSchema } from '../../../src/schemas/';
73
import { TestEvents } from './utils.js';
84

Diff for: packages/parser/tests/unit/schema/apigw.test.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
/**
2-
* Test built-in API Gateway REST schemas
3-
*
4-
* @group unit/parser/schema/apigw
5-
*/
1+
import { describe, expect, it } from 'vitest';
62
import {
73
APIGatewayProxyEventSchema,
84
APIGatewayRequestAuthorizerEventSchema,

Diff for: packages/parser/tests/unit/schema/apigwv2.test.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
/**
2-
* Test built-in API Gateway HTTP API (v2) schemas
3-
*
4-
* @group unit/parser/schema/apigwv2
5-
*/
1+
import { describe, expect, it } from 'vitest';
62
import {
73
APIGatewayProxyEventV2Schema,
84
APIGatewayRequestAuthorizerEventV2Schema,

Diff for: packages/parser/tests/unit/schema/cloudformation-custom-resource.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
/**
2-
* Test built in schema
3-
*
4-
* @group unit/parser/schema/
5-
*/
6-
1+
import { describe, expect, it } from 'vitest';
72
import {
83
CloudFormationCustomResourceCreateSchema,
94
CloudFormationCustomResourceDeleteSchema,

Diff for: packages/parser/tests/unit/schema/cloudwatch.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
/**
2-
* Test built in schema
3-
*
4-
* @group unit/parser/schema/
5-
*/
6-
1+
import { describe, expect, it } from 'vitest';
72
import { CloudWatchLogsSchema } from '../../../src/schemas/';
83
import { TestEvents } from './utils.js';
94

Diff for: packages/parser/tests/unit/schema/dynamodb.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
/**
2-
* Test built in schema
3-
*
4-
* @group unit/parser/schema/
5-
*/
6-
1+
import { describe, expect, it } from 'vitest';
72
import { DynamoDBStreamSchema } from '../../../src/schemas/';
83
import { TestEvents } from './utils.js';
94

Diff for: packages/parser/tests/unit/schema/eventbridge.test.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
/**
2-
* Test built in schema
3-
*
4-
* @group unit/parser/schema/
5-
*/
6-
1+
import { describe, expect, it } from 'vitest';
72
import { EventBridgeSchema } from '../../../src/schemas/';
83
import { TestEvents } from './utils.js';
94

0 commit comments

Comments
 (0)