Skip to content

Commit 91bd574

Browse files
authored
chore(maintenance): migrate testing utility to biome (#2808)
1 parent 4312ca0 commit 91bd574

13 files changed

+44
-67
lines changed

packages/testing/package.json

+6-20
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@
1616
"build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
1717
"build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
1818
"build": "npm run build:esm & npm run build:cjs",
19-
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
20-
"lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .",
19+
"lint": "biome lint .",
20+
"lint:fix": "biome check --write .",
2121
"prepack": "node ../../.github/scripts/release_patch_package_json.js ."
2222
},
2323
"repository": {
2424
"type": "git",
2525
"url": "git+https://github.com/aws-powertools/powertools-lambda-typescript.git"
2626
},
27-
"files": [
28-
"lib"
29-
],
27+
"files": ["lib"],
3028
"type": "module",
3129
"exports": {
3230
".": {
@@ -66,25 +64,13 @@
6664
"lib/cjs/resources/TestDynamodbTable.d.ts",
6765
"lib/esm/resources/TestDynamodbTable.d.ts"
6866
],
69-
"types": [
70-
"lib/cjs/types.d.ts",
71-
"lib/esm/types.d.ts"
72-
],
73-
"context": [
74-
"lib/cjs/context.d.ts",
75-
"lib/esm/context.d.ts"
76-
]
67+
"types": ["lib/cjs/types.d.ts", "lib/esm/types.d.ts"],
68+
"context": ["lib/cjs/context.d.ts", "lib/esm/context.d.ts"]
7769
}
7870
},
7971
"types": "./lib/cjs/index.d.ts",
8072
"main": "./lib/cjs/index.js",
81-
"keywords": [
82-
"aws",
83-
"lambda",
84-
"powertools",
85-
"testing",
86-
"serverless"
87-
],
73+
"keywords": ["aws", "lambda", "powertools", "testing", "serverless"],
8874
"license": "MIT-0",
8975
"bugs": {
9076
"url": "https://github.com/aws-powertools/powertools-lambda-typescript/issues"

packages/testing/src/TestInvocationLogs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class TestInvocationLogs {
8585
try {
8686
const parsedLog = TestInvocationLogs.parseFunctionLog(log);
8787

88-
return parsedLog.level == levelToFilter;
88+
return parsedLog.level === levelToFilter;
8989
} catch (error) {
9090
// If log is not from structured logging : such as metrics one.
9191
return (

packages/testing/src/TestStack.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { readFile } from 'node:fs/promises';
12
import { tmpdir } from 'node:os';
23
import { join } from 'node:path';
3-
import { readFile } from 'node:fs/promises';
4-
import { App, Stack } from 'aws-cdk-lib';
54
import { AwsCdkCli, RequireApproval } from '@aws-cdk/cli-lib-alpha';
65
import type { ICloudAssemblyDirectoryProducer } from '@aws-cdk/cli-lib-alpha';
6+
import { App, Stack } from 'aws-cdk-lib';
77
import { generateTestUniqueName } from './helpers.js';
88
import type { TestStackProps } from './types.js';
99

packages/testing/src/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Runtime, Architecture } from 'aws-cdk-lib/aws-lambda';
1+
import { Architecture, Runtime } from 'aws-cdk-lib/aws-lambda';
22

33
/**
44
* The default AWS Lambda runtime to use when none is provided.

packages/testing/src/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { randomUUID } from 'node:crypto';
22
import {
3-
TEST_RUNTIMES,
4-
defaultRuntime,
53
TEST_ARCHITECTURES,
4+
TEST_RUNTIMES,
65
defaultArchitecture,
6+
defaultRuntime,
77
} from './constants.js';
88

99
const isValidRuntimeKey = (

packages/testing/src/invokeTestFunction.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ const invokeFunctionOnce = async ({
2626

2727
if (result?.LogResult) {
2828
return new TestInvocationLogs(result?.LogResult);
29-
} else {
30-
throw new Error(
31-
'No LogResult field returned in the response of Lambda invocation. This should not happen.'
32-
);
3329
}
30+
throw new Error(
31+
'No LogResult field returned in the response of Lambda invocation. This should not happen.'
32+
);
3433
};
3534

3635
/**
@@ -50,11 +49,11 @@ const invokeFunction = async ({
5049

5150
if (payload && Array.isArray(payload) && payload.length !== times) {
5251
throw new Error(
53-
`The payload array must have the same length as the times parameter.`
52+
'The payload array must have the same length as the times parameter.'
5453
);
5554
}
5655

57-
if (invocationMode == 'PARALLEL') {
56+
if (invocationMode === 'PARALLEL') {
5857
const invocationPromises = Array.from(
5958
{ length: times },
6059
() => invokeFunctionOnce

packages/testing/src/resources/TestDynamodbTable.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { randomUUID } from 'node:crypto';
12
import { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';
23
import { AttributeType, BillingMode, Table } from 'aws-cdk-lib/aws-dynamodb';
3-
import { randomUUID } from 'node:crypto';
4-
import { concatenateResourceName } from '../helpers.js';
54
import type { TestStack } from '../TestStack.js';
6-
import type { TestDynamodbTableProps, ExtraTestProps } from '../types.js';
5+
import { concatenateResourceName } from '../helpers.js';
6+
import type { ExtraTestProps, TestDynamodbTableProps } from '../types.js';
77

88
/**
99
* A DynamoDB Table that can be used in tests.

packages/testing/src/resources/TestNodejsFunction.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
import { randomUUID } from 'node:crypto';
12
import { CfnOutput, Duration } from 'aws-cdk-lib';
23
import { Tracing } from 'aws-cdk-lib/aws-lambda';
34
import { NodejsFunction, OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';
45
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
5-
import { randomUUID } from 'node:crypto';
6-
import { TEST_RUNTIMES, TEST_ARCHITECTURES } from '../constants.js';
6+
import type { TestStack } from '../TestStack.js';
7+
import { TEST_ARCHITECTURES, TEST_RUNTIMES } from '../constants.js';
78
import {
89
concatenateResourceName,
9-
getRuntimeKey,
1010
getArchitectureKey,
11+
getRuntimeKey,
1112
} from '../helpers.js';
12-
import type { TestStack } from '../TestStack.js';
1313
import type { ExtraTestProps, TestNodejsFunctionProps } from '../types.js';
1414

1515
/**

packages/testing/src/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { TableProps, AttributeType } from 'aws-cdk-lib/aws-dynamodb';
2-
import type { NodejsFunctionProps } from 'aws-cdk-lib/aws-lambda-nodejs';
31
import type { App, Stack } from 'aws-cdk-lib';
4-
import { LogLevel } from './constants.js';
2+
import type { AttributeType, TableProps } from 'aws-cdk-lib/aws-dynamodb';
3+
import type { NodejsFunctionProps } from 'aws-cdk-lib/aws-lambda-nodejs';
4+
import type { LogLevel } from './constants.js';
55

66
interface ExtraTestProps {
77
/**

packages/testing/tests/tsconfig.json

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
2-
"extends": "../tsconfig.json",
3-
"compilerOptions": {
4-
"rootDir": "../",
5-
"noEmit": true
6-
},
7-
"include": [
8-
"../src/**/*",
9-
"./**/*",
10-
]
11-
}
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "../",
5+
"noEmit": true
6+
},
7+
"include": ["../src/**/*", "./**/*"]
8+
}

packages/testing/tests/unit/TestInvocationLogs.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* @group unit/commons/invocationLogs
55
*
66
*/
7-
87
import { TestInvocationLogs } from '../../src/TestInvocationLogs.js';
98

109
const exampleLogs = `START RequestId: c6af9ac6-7b61-11e6-9a41-93e812345678 Version: $LATEST

packages/testing/tsconfig.esm.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@
66
"rootDir": "./src",
77
"tsBuildInfoFile": ".tsbuildinfo/esm.json"
88
},
9-
"include": [
10-
"./src/**/*"
11-
]
12-
}
9+
"include": ["./src/**/*"]
10+
}

packages/testing/tsconfig.json

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
2-
"extends": "../../tsconfig.json",
3-
"compilerOptions": {
4-
"outDir": "./lib/cjs",
5-
"rootDir": "./src",
6-
"tsBuildInfoFile": ".tsbuildinfo/cjs.json"
7-
},
8-
"include": [
9-
"./src/**/*"
10-
],
11-
}
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./lib/cjs",
5+
"rootDir": "./src",
6+
"tsBuildInfoFile": ".tsbuildinfo/cjs.json"
7+
},
8+
"include": ["./src/**/*"]
9+
}

0 commit comments

Comments
 (0)