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

chore(maintenance): migrate testing utility to biome #2808

Merged
merged 4 commits into from
Jul 22, 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
26 changes: 6 additions & 20 deletions packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
"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",
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
"lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .",
"lint": "biome lint .",
"lint:fix": "biome check --write .",
"prepack": "node ../../.github/scripts/release_patch_package_json.js ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/aws-powertools/powertools-lambda-typescript.git"
},
"files": [
"lib"
],
"files": ["lib"],
"type": "module",
"exports": {
".": {
Expand Down Expand Up @@ -66,25 +64,13 @@
"lib/cjs/resources/TestDynamodbTable.d.ts",
"lib/esm/resources/TestDynamodbTable.d.ts"
],
"types": [
"lib/cjs/types.d.ts",
"lib/esm/types.d.ts"
],
"context": [
"lib/cjs/context.d.ts",
"lib/esm/context.d.ts"
]
"types": ["lib/cjs/types.d.ts", "lib/esm/types.d.ts"],
"context": ["lib/cjs/context.d.ts", "lib/esm/context.d.ts"]
}
},
"types": "./lib/cjs/index.d.ts",
"main": "./lib/cjs/index.js",
"keywords": [
"aws",
"lambda",
"powertools",
"testing",
"serverless"
],
"keywords": ["aws", "lambda", "powertools", "testing", "serverless"],
"license": "MIT-0",
"bugs": {
"url": "https://github.com/aws-powertools/powertools-lambda-typescript/issues"
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/src/TestInvocationLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class TestInvocationLogs {
try {
const parsedLog = TestInvocationLogs.parseFunctionLog(log);

return parsedLog.level == levelToFilter;
return parsedLog.level === levelToFilter;
} catch (error) {
// If log is not from structured logging : such as metrics one.
return (
Expand Down
4 changes: 2 additions & 2 deletions packages/testing/src/TestStack.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { readFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { readFile } from 'node:fs/promises';
import { App, Stack } from 'aws-cdk-lib';
import { AwsCdkCli, RequireApproval } from '@aws-cdk/cli-lib-alpha';
import type { ICloudAssemblyDirectoryProducer } from '@aws-cdk/cli-lib-alpha';
import { App, Stack } from 'aws-cdk-lib';
import { generateTestUniqueName } from './helpers.js';
import type { TestStackProps } from './types.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/testing/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Runtime, Architecture } from 'aws-cdk-lib/aws-lambda';
import { Architecture, Runtime } from 'aws-cdk-lib/aws-lambda';

/**
* The default AWS Lambda runtime to use when none is provided.
Expand Down
4 changes: 2 additions & 2 deletions packages/testing/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { randomUUID } from 'node:crypto';
import {
TEST_RUNTIMES,
defaultRuntime,
TEST_ARCHITECTURES,
TEST_RUNTIMES,
defaultArchitecture,
defaultRuntime,
} from './constants.js';

const isValidRuntimeKey = (
Expand Down
11 changes: 5 additions & 6 deletions packages/testing/src/invokeTestFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ const invokeFunctionOnce = async ({

if (result?.LogResult) {
return new TestInvocationLogs(result?.LogResult);
} else {
throw new Error(
'No LogResult field returned in the response of Lambda invocation. This should not happen.'
);
}
throw new Error(
'No LogResult field returned in the response of Lambda invocation. This should not happen.'
);
};

/**
Expand All @@ -50,11 +49,11 @@ const invokeFunction = async ({

if (payload && Array.isArray(payload) && payload.length !== times) {
throw new Error(
`The payload array must have the same length as the times parameter.`
'The payload array must have the same length as the times parameter.'
);
}

if (invocationMode == 'PARALLEL') {
if (invocationMode === 'PARALLEL') {
const invocationPromises = Array.from(
{ length: times },
() => invokeFunctionOnce
Expand Down
6 changes: 3 additions & 3 deletions packages/testing/src/resources/TestDynamodbTable.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { randomUUID } from 'node:crypto';
import { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';
import { AttributeType, BillingMode, Table } from 'aws-cdk-lib/aws-dynamodb';
import { randomUUID } from 'node:crypto';
import { concatenateResourceName } from '../helpers.js';
import type { TestStack } from '../TestStack.js';
import type { TestDynamodbTableProps, ExtraTestProps } from '../types.js';
import { concatenateResourceName } from '../helpers.js';
import type { ExtraTestProps, TestDynamodbTableProps } from '../types.js';

/**
* A DynamoDB Table that can be used in tests.
Expand Down
8 changes: 4 additions & 4 deletions packages/testing/src/resources/TestNodejsFunction.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { randomUUID } from 'node:crypto';
import { CfnOutput, Duration } from 'aws-cdk-lib';
import { Tracing } from 'aws-cdk-lib/aws-lambda';
import { NodejsFunction, OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
import { randomUUID } from 'node:crypto';
import { TEST_RUNTIMES, TEST_ARCHITECTURES } from '../constants.js';
import type { TestStack } from '../TestStack.js';
import { TEST_ARCHITECTURES, TEST_RUNTIMES } from '../constants.js';
import {
concatenateResourceName,
getRuntimeKey,
getArchitectureKey,
getRuntimeKey,
} from '../helpers.js';
import type { TestStack } from '../TestStack.js';
import type { ExtraTestProps, TestNodejsFunctionProps } from '../types.js';

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/testing/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { TableProps, AttributeType } from 'aws-cdk-lib/aws-dynamodb';
import type { NodejsFunctionProps } from 'aws-cdk-lib/aws-lambda-nodejs';
import type { App, Stack } from 'aws-cdk-lib';
import { LogLevel } from './constants.js';
import type { AttributeType, TableProps } from 'aws-cdk-lib/aws-dynamodb';
import type { NodejsFunctionProps } from 'aws-cdk-lib/aws-lambda-nodejs';
import type { LogLevel } from './constants.js';

interface ExtraTestProps {
/**
Expand Down
17 changes: 7 additions & 10 deletions packages/testing/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../",
"noEmit": true
},
"include": [
"../src/**/*",
"./**/*",
]
}
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../",
"noEmit": true
},
"include": ["../src/**/*", "./**/*"]
}
1 change: 0 additions & 1 deletion packages/testing/tests/unit/TestInvocationLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @group unit/commons/invocationLogs
*
*/

import { TestInvocationLogs } from '../../src/TestInvocationLogs.js';

const exampleLogs = `START RequestId: c6af9ac6-7b61-11e6-9a41-93e812345678 Version: $LATEST
Expand Down
6 changes: 2 additions & 4 deletions packages/testing/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
"rootDir": "./src",
"tsBuildInfoFile": ".tsbuildinfo/esm.json"
},
"include": [
"./src/**/*"
]
}
"include": ["./src/**/*"]
}
18 changes: 8 additions & 10 deletions packages/testing/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib/cjs",
"rootDir": "./src",
"tsBuildInfoFile": ".tsbuildinfo/cjs.json"
},
"include": [
"./src/**/*"
],
}
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib/cjs",
"rootDir": "./src",
"tsBuildInfoFile": ".tsbuildinfo/cjs.json"
},
"include": ["./src/**/*"]
}