Skip to content
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

test(parser): migrate to vitest #3299

Merged
merged 3 commits into from
Nov 8, 2024
Merged
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 @@ -48,6 +48,7 @@ jobs:
"packages/jmespath",
"packages/logger",
"packages/tracer",
"packages/parser",
]
fail-fast: false
steps:
Expand Down Expand Up @@ -91,13 +92,11 @@ jobs:
- name: Run linting
run: |
npm run lint -w packages/metrics \
-w packages/parameters \
-w packages/parser
-w packages/parameters
- name: Run unit tests
run: |
npm t -w packages/metrics \
-w packages/parameters \
-w packages/parser
-w packages/parameters
check-examples:
runs-on: ubuntu-latest
env:
Expand Down
9 changes: 6 additions & 3 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
npm t \
-w packages/metrics \
-w packages/parameters \
-w packages/parser
-w packages/parameters

npx vitest --run --coverage --changed="$(git merge-base HEAD main)" tests/unit
npx vitest --run \
--exclude tests/unit/layer-publisher.test.ts \
--coverage --coverage.thresholds.100 \
--changed="$(git merge-base HEAD main)" \
tests/unit
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": "vitest --run tests/types --typecheck",
"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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from 'vitest';
import { z } from 'zod';
import {
ApiGatewayEnvelope,
Expand Down Expand Up @@ -30,7 +31,7 @@ describe('Types ', () => {
{ envelope: LambdaFunctionUrlEnvelope, name: 'LambdaFunctionUrl' },
{ envelope: VpcLatticeEnvelope, name: 'VpcLattice' },
{ envelope: VpcLatticeV2Envelope, name: 'VpcLatticeV2' },
])('should infer object for $name envelope', (testCase) => {
])('infers object types for $name envelope', (testCase) => {
type Result = ParserOutput<typeof userSchema, typeof testCase.envelope>;
// Define the expected type

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

Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelope.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/**
* Test decorator parser
*
* @group unit/parser
*/

import { describe, expect, it } from 'vitest';
import { ZodError, z } from 'zod';
import { Envelope } from '../../src/envelopes/envelope.js';

Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelopes/apigw.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/**
* Test built-in API Gateway REST envelope
*
* @group unit/parser/envelopes/apigw
*/

import { describe, expect, it } from 'vitest';
import { ZodError } from 'zod';
import { ApiGatewayEnvelope } from '../../../src/envelopes/index.js';
import { ParseError } from '../../../src/errors.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelopes/apigwv2.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/**
* Test built-in API Gateway HTTP API (v2) envelope
*
* @group unit/parser/envelopes/apigwv2
*/

import { describe, expect, it } from 'vitest';
import { ZodError } from 'zod';
import { ApiGatewayV2Envelope } from '../../../src/envelopes/index.js';
import { ParseError } from '../../../src/errors.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelopes/cloudwatch.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* Test built in schema envelopes for CloudWatch
*
* @group unit/parser/envelopes
*/

import { gzipSync } from 'node:zlib';
import { generateMock } from '@anatine/zod-mock';
import { describe, expect, it } from 'vitest';
import { ZodError } from 'zod';
import { ParseError } from '../../../src';
import { CloudWatchEnvelope } from '../../../src/envelopes/index.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelopes/dynamodb.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* Test built in schema envelopes for api gateway v2
*
* @group unit/parser/envelopes
*/

import { generateMock } from '@anatine/zod-mock';
import type { AttributeValue, DynamoDBStreamEvent } from 'aws-lambda';
import { describe, expect, it } from 'vitest';
import { ZodError, z } from 'zod';
import { DynamoDBStreamEnvelope } from '../../../src/envelopes/index.js';
import { ParseError } from '../../../src/errors.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelopes/eventbridge.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* Test built in schema envelopes for event bridge
*
* @group unit/parser/envelopes
*/

import { generateMock } from '@anatine/zod-mock';
import type { EventBridgeEvent } from 'aws-lambda';
import { describe, expect, it } from 'vitest';
import { ZodError } from 'zod';
import { EventBridgeEnvelope } from '../../../src/envelopes/index.js';
import { ParseError } from '../../../src/errors.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelopes/kafka.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* Test built in schema envelopes for api gateway v2
*
* @group unit/parser/envelopes
*/

import { generateMock } from '@anatine/zod-mock';
import type { MSKEvent, SelfManagedKafkaEvent } from 'aws-lambda';
import { describe, expect, it } from 'vitest';
import { ParseError } from '../../../src';
import { KafkaEnvelope } from '../../../src/envelopes/index.js';
import { TestEvents, TestSchema } from '../schema/utils.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
* Test built in schema envelopes for Kinesis Firehose
*
* @group unit/parser/envelopes
*/

import { generateMock } from '@anatine/zod-mock';
import { describe, expect, it } from 'vitest';
import { ZodError, type z } from 'zod';
import { ParseError } from '../../../src';
import { KinesisFirehoseEnvelope } from '../../../src/envelopes/index.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelopes/kinesis.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* Test built in schema envelopes for Kinesis
*
* @group unit/parser/envelopes
*/

import { generateMock } from '@anatine/zod-mock';
import type { KinesisStreamEvent } from 'aws-lambda';
import { describe, expect, it } from 'vitest';
import { KinesisEnvelope } from '../../../src/envelopes/index.js';
import { ParseError } from '../../../src/errors.js';
import { TestEvents, TestSchema } from '../schema/utils.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelopes/lambda.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* Test built in schema envelopes for Lambda Functions URL
*
* @group unit/parser/envelopes
*/

import { generateMock } from '@anatine/zod-mock';
import type { APIGatewayProxyEventV2 } from 'aws-lambda';
import { describe, expect, it } from 'vitest';
import { ZodError } from 'zod';
import { ParseError } from '../../../src';
import { LambdaFunctionUrlEnvelope } from '../../../src/envelopes/index.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelopes/sns.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* Test built in schema envelopes for SNS
*
* @group unit/parser/envelopes
*/

import { generateMock } from '@anatine/zod-mock';
import type { SNSEvent, SQSEvent } from 'aws-lambda';
import { describe, expect, it } from 'vitest';
import { ZodError, type z } from 'zod';
import { SnsEnvelope, SnsSqsEnvelope } from '../../../src/envelopes/index.js';
import { ParseError } from '../../../src/errors.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelopes/sqs.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/**
* Test built in schema envelopes for sqs
*
* @group unit/parser/envelopes
*/

import { generateMock } from '@anatine/zod-mock';
import type { SQSEvent } from 'aws-lambda';
import { describe, expect, it } from 'vitest';
import { ZodError } from 'zod';
import { SqsEnvelope } from '../../../src/envelopes/sqs.js';
import { ParseError } from '../../../src/errors.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/envelopes/vpc-lattice.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
* Test built in schema envelopes for VPC Lattice
*
* @group unit/parser/envelopes
*/

import { generateMock } from '@anatine/zod-mock';
import { describe, expect, it } from 'vitest';
import { ZodError } from 'zod';
import { ParseError } from '../../../src';
import { VpcLatticeEnvelope } from '../../../src/envelopes/index.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
* Test built in schema envelopes for VPC Lattice V2
*
* @group unit/parser/envelopes
*/

import { generateMock } from '@anatine/zod-mock';
import { describe, expect, it } from 'vitest';
import { ZodError } from 'zod';
import { ParseError } from '../../../src';
import { VpcLatticeV2Envelope } from '../../../src/envelopes/index.js';
Expand Down
6 changes: 1 addition & 5 deletions packages/parser/tests/unit/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/**
* Test decorator parser
*
* @group unit/parser
*/
import { describe, expect, it } from 'vitest';
import { z } from 'zod';
import { JSONStringified } from '../../src/helpers.js';
import { AlbSchema } from '../../src/schemas/alb.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/parser.decorator.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/**
* Test decorator parser
*
* @group unit/parser
*/

import { generateMock } from '@anatine/zod-mock';
import type { LambdaInterface } from '@aws-lambda-powertools/commons/lib/esm/types';
import type { Context } from 'aws-lambda';
import { describe, expect, it } from 'vitest';
import type { z } from 'zod';
import { EventBridgeEnvelope } from '../../src/envelopes/index.js';
import { ParseError } from '../../src/errors.js';
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/parser.middy.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/**
* Test middleware parser
*
* @group unit/parser
*/

import { generateMock } from '@anatine/zod-mock';
import middy from '@middy/core';
import type { Context } from 'aws-lambda';
import { describe, expect, it } from 'vitest';
import type { ZodSchema, z } from 'zod';
import { ParseError } from '../../src';
import { EventBridgeEnvelope, SqsEnvelope } from '../../src/envelopes';
Expand Down
6 changes: 1 addition & 5 deletions packages/parser/tests/unit/schema/alb.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/**
* Test built in schema
*
* @group unit/parser/schema/
*/
import { describe, expect, it } from 'vitest';
import { AlbMultiValueHeadersSchema, AlbSchema } from '../../../src/schemas/';
import { TestEvents } from './utils.js';

Expand Down
6 changes: 1 addition & 5 deletions packages/parser/tests/unit/schema/apigw.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/**
* Test built-in API Gateway REST schemas
*
* @group unit/parser/schema/apigw
*/
import { describe, expect, it } from 'vitest';
import {
APIGatewayProxyEventSchema,
APIGatewayRequestAuthorizerEventSchema,
Expand Down
6 changes: 1 addition & 5 deletions packages/parser/tests/unit/schema/apigwv2.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/**
* Test built-in API Gateway HTTP API (v2) schemas
*
* @group unit/parser/schema/apigwv2
*/
import { describe, expect, it } from 'vitest';
import {
APIGatewayProxyEventV2Schema,
APIGatewayRequestAuthorizerEventV2Schema,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/**
* Test built in schema
*
* @group unit/parser/schema/
*/

import { describe, expect, it } from 'vitest';
import {
CloudFormationCustomResourceCreateSchema,
CloudFormationCustomResourceDeleteSchema,
Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/schema/cloudwatch.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/**
* Test built in schema
*
* @group unit/parser/schema/
*/

import { describe, expect, it } from 'vitest';
import { CloudWatchLogsSchema } from '../../../src/schemas/';
import { TestEvents } from './utils.js';

Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/schema/dynamodb.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/**
* Test built in schema
*
* @group unit/parser/schema/
*/

import { describe, expect, it } from 'vitest';
import { DynamoDBStreamSchema } from '../../../src/schemas/';
import { TestEvents } from './utils.js';

Expand Down
7 changes: 1 addition & 6 deletions packages/parser/tests/unit/schema/eventbridge.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
/**
* Test built in schema
*
* @group unit/parser/schema/
*/

import { describe, expect, it } from 'vitest';
import { EventBridgeSchema } from '../../../src/schemas/';
import { TestEvents } from './utils.js';

Expand Down
Loading