Skip to content

Commit ac14f41

Browse files
committed
tests: coverage tests
1 parent 4e5ba62 commit ac14f41

Some content is hidden

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

50 files changed

+1613
-1010
lines changed

Diff for: package-lock.json

+15-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/commons/package.json

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
"default": "./lib/esm/index.js"
4141
}
4242
},
43+
"./typeutils": {
44+
"import": "./lib/esm/typeUtils.js",
45+
"require": "./lib/cjs/typeUtils.js"
46+
},
4347
"./types": {
4448
"import": "./lib/esm/types/index.js",
4549
"require": "./lib/cjs/types/index.js"
@@ -50,6 +54,10 @@
5054
"types": [
5155
"lib/cjs/types/index.d.ts",
5256
"lib/esm/types/index.d.ts"
57+
],
58+
"typeutils": [
59+
"lib/cjs/typeUtils.d.ts",
60+
"lib/esm/typeUtils.d.ts"
5361
]
5462
}
5563
},

Diff for: packages/commons/src/guards.ts

-52
This file was deleted.

Diff for: packages/commons/src/index.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
export { isRecord, isString, isTruthy, isNullOrUndefined } from './guards.js';
1+
export {
2+
isRecord,
3+
isString,
4+
isNumber,
5+
isIntegerNumber,
6+
isTruthy,
7+
isNull,
8+
isNullOrUndefined,
9+
getType,
10+
isStrictEqual,
11+
} from './typeUtils.js';
212
export { Utility } from './Utility.js';
313
export { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js';
414
export { addUserAgentMiddleware, isSdkClient } from './awsSdkUtils.js';

Diff for: packages/commons/src/typeUtils.ts

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/**
2+
* Returns true if the passed value is a record (object).
3+
*
4+
* @param value The value to check
5+
*/
6+
const isRecord = (value: unknown): value is Record<string, unknown> => {
7+
return (
8+
Object.prototype.toString.call(value) === '[object Object]' &&
9+
!Object.is(value, null)
10+
);
11+
};
12+
13+
/**
14+
* Check if a value is a string.
15+
*
16+
* @param value The value to check
17+
*/
18+
const isString = (value: unknown): value is string => {
19+
return typeof value === 'string';
20+
};
21+
22+
/**
23+
* Check if a value is a number.
24+
*
25+
* @param value The value to check
26+
*/
27+
const isNumber = (value: unknown): value is number => {
28+
return typeof value === 'number';
29+
};
30+
31+
/**
32+
* Check if a value is an integer number.
33+
*
34+
* @param value The value to check
35+
*/
36+
const isIntegerNumber = (value: unknown): value is number => {
37+
return isNumber(value) && Number.isInteger(value);
38+
};
39+
40+
/**
41+
* Check if a value is truthy.
42+
*
43+
* @param value The value to check
44+
*/
45+
const isTruthy = (value: unknown): boolean => {
46+
if (isString(value)) {
47+
return value !== '';
48+
} else if (isNumber(value)) {
49+
return value !== 0;
50+
} else if (typeof value === 'boolean') {
51+
return value;
52+
} else if (Array.isArray(value)) {
53+
return value.length > 0;
54+
} else if (isRecord(value)) {
55+
return Object.keys(value).length > 0;
56+
} else {
57+
return false;
58+
}
59+
};
60+
61+
/**
62+
* Check if a value is null.
63+
*
64+
* @param value The value to check
65+
*/
66+
const isNull = (value: unknown): value is null => {
67+
return Object.is(value, null);
68+
};
69+
70+
/**
71+
* Check if a value is null or undefined.
72+
*
73+
* @param value The value to check
74+
*/
75+
const isNullOrUndefined = (value: unknown): value is null | undefined => {
76+
return isNull(value) || Object.is(value, undefined);
77+
};
78+
79+
/**
80+
* Get the type of a value as a string.
81+
*
82+
* @param value The value to check
83+
*/
84+
const getType = (value: unknown): string => {
85+
if (Array.isArray(value)) {
86+
return 'array';
87+
} else if (isRecord(value)) {
88+
return 'object';
89+
} else if (isString(value)) {
90+
return 'string';
91+
} else if (isNumber(value)) {
92+
return 'number';
93+
} else if (typeof value === 'boolean') {
94+
return 'boolean';
95+
} else if (isNull(value)) {
96+
return 'null';
97+
} else {
98+
return 'unknown';
99+
}
100+
};
101+
102+
/**
103+
* Check if two unknown values are strictly equal.
104+
*
105+
* If the values are arrays, then each element is compared, regardless of
106+
* order. If the values are objects, then each key and value from left
107+
* is compared to the corresponding key and value from right. If the
108+
* values are primitives, then they are compared using strict equality.
109+
*
110+
* @param left Left side of strict equality comparison
111+
* @param right Right side of strict equality comparison
112+
*/
113+
const isStrictEqual = (left: unknown, right: unknown): boolean => {
114+
if (left === right) {
115+
return true;
116+
} else if (typeof left !== typeof right) {
117+
return false;
118+
} else if (Array.isArray(left) && Array.isArray(right)) {
119+
if (left.length !== right.length) {
120+
return false;
121+
}
122+
for (const [i, value] of left.entries()) {
123+
if (!isStrictEqual(value, right[i])) {
124+
return false;
125+
}
126+
}
127+
128+
return true;
129+
} else if (isRecord(left) && isRecord(right)) {
130+
const leftKeys = Object.keys(left);
131+
const leftValues = Object.values(left);
132+
const rightKeys = Object.keys(right);
133+
const rightValues = Object.values(right);
134+
if (
135+
leftKeys.length !== rightKeys.length ||
136+
leftValues.length !== rightValues.length
137+
) {
138+
return false;
139+
}
140+
141+
return (
142+
isStrictEqual(leftKeys, rightKeys) &&
143+
isStrictEqual(leftValues, rightValues)
144+
);
145+
} else {
146+
return false;
147+
}
148+
};
149+
150+
export {
151+
isRecord,
152+
isString,
153+
isNumber,
154+
isIntegerNumber,
155+
isTruthy,
156+
isNull,
157+
isNullOrUndefined,
158+
getType,
159+
isStrictEqual,
160+
};

Diff for: packages/jmespath/README.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Powertools for AWS Lambda (TypeScript) - JMESPath Utility <!-- omit in toc -->
2+
3+
Powertools for AWS Lambda (TypeScript) is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.powertools.aws.dev/lambda/typescript/latest/#features).
4+
5+
You can use the package in both TypeScript and JavaScript code bases.
6+
7+
- [Intro](#intro)
8+
- [Usage](#usage)
9+
- [Contribute](#contribute)
10+
- [Roadmap](#roadmap)
11+
- [Connect](#connect)
12+
- [How to support Powertools for AWS Lambda (TypeScript)?](#how-to-support-powertools-for-aws-lambda-typescript)
13+
- [Becoming a reference customer](#becoming-a-reference-customer)
14+
- [Sharing your work](#sharing-your-work)
15+
- [Using Lambda Layer](#using-lambda-layer)
16+
- [License](#license)
17+
18+
## Intro
19+
20+
The JMESPath utility is a high-level function to parse and extract data from JSON objects using JMESPath expressions.
21+
22+
## Usage
23+
24+
To get started, install the library by running:
25+
26+
```sh
27+
npm i @aws-lambda-powertools/jmespath
28+
```
29+
30+
## Contribute
31+
32+
If you are interested in contributing to this project, please refer to our [Contributing Guidelines](https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/CONTRIBUTING.md).
33+
34+
## Roadmap
35+
36+
The roadmap of Powertools for AWS Lambda (TypeScript) is driven by customers’ demand.
37+
Help us prioritize upcoming functionalities or utilities by [upvoting existing RFCs and feature requests](https://github.com/aws-powertools/powertools-lambda-typescript/issues), or [creating new ones](https://github.com/aws-powertools/powertools-lambda-typescript/issues/new/choose), in this GitHub repository.
38+
39+
## Connect
40+
41+
* **Powertools for AWS Lambda on Discord**: `#typescript` - **[Invite link](https://discord.gg/B8zZKbbyET)**
42+
* **Email**: [email protected]
43+
44+
## How to support Powertools for AWS Lambda (TypeScript)?
45+
46+
### Becoming a reference customer
47+
48+
Knowing which companies are using this library is important to help prioritize the project internally. If your company is using Powertools for AWS Lambda (TypeScript), you can request to have your name and logo added to the README file by raising a [Support Powertools for AWS Lambda (TypeScript) (become a reference)](https://github.com/aws-powertools/powertools-lambda-typescript/issues/new?assignees=&labels=customer-reference&template=support_powertools.yml&title=%5BSupport+Lambda+Powertools%5D%3A+%3Cyour+organization+name%3E) issue.
49+
50+
The following companies, among others, use Powertools:
51+
52+
* [Hashnode](https://hashnode.com/)
53+
* [Trek10](https://www.trek10.com/)
54+
* [Elva](https://elva-group.com)
55+
* [globaldatanet](https://globaldatanet.com/)
56+
* [Bailey Nelson](https://www.baileynelson.com.au)
57+
* [Perfect Post](https://www.perfectpost.fr)
58+
* [Sennder](https://sennder.com/)
59+
* [Certible](https://www.certible.com/)
60+
* [tecRacer GmbH & Co. KG](https://www.tecracer.com/)
61+
* [AppYourself](https://appyourself.net)
62+
* [Alma Media](https://www.almamedia.fi)
63+
64+
### Sharing your work
65+
66+
Share what you did with Powertools for AWS Lambda (TypeScript) 💞💞. Blog post, workshops, presentation, sample apps and others. Check out what the community has already shared about Powertools for AWS Lambda (TypeScript) [here](https://docs.powertools.aws.dev/lambda/typescript/latest/we_made_this).
67+
68+
### Using Lambda Layer
69+
70+
This helps us understand who uses Powertools for AWS Lambda (TypeScript) in a non-intrusive way, and helps us gain future investments for other Powertools for AWS Lambda languages. When [using Layers](https://docs.powertools.aws.dev/lambda/typescript/latest/#lambda-layer), you can add Powertools as a dev dependency to not impact the development process.
71+
72+
## License
73+
74+
This library is licensed under the MIT-0 License. See the LICENSE file.

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module.exports = {
44
color: 'purple',
55
},
66
runner: 'groups',
7-
preset: 'ts-jest',
7+
moduleNameMapper: {
8+
'^(\\.{1,2}/.*)\\.js$': '$1',
9+
},
810
transform: {
911
'^.+\\.ts?$': 'ts-jest',
1012
},
@@ -14,7 +16,11 @@ module.exports = {
1416
roots: ['<rootDir>/src', '<rootDir>/tests'],
1517
testPathIgnorePatterns: ['/node_modules/'],
1618
testEnvironment: 'node',
17-
coveragePathIgnorePatterns: ['/node_modules/', '/types/'],
19+
coveragePathIgnorePatterns: [
20+
'/node_modules/',
21+
'src/index.ts',
22+
'src/types/index.ts',
23+
],
1824
coverageThreshold: {
1925
global: {
2026
statements: 100,

0 commit comments

Comments
 (0)