Skip to content

Commit 733b113

Browse files
committed
chore(smithy-client): create emitWarningIfUnsupportedVersion
1 parent 5c9152a commit 733b113

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { emitWarningIfUnsupportedVersion } from "./emitWarningIfUnsupportedVersion";
2+
3+
describe(emitWarningIfUnsupportedVersion.name, () => {
4+
const emitWarning = process.emitWarning;
5+
const supportedVersion = "12.0.0";
6+
7+
afterEach(() => {
8+
jest.clearAllMocks();
9+
process.emitWarning = emitWarning;
10+
});
11+
12+
describe(`emits warning for Node.js <${supportedVersion}`, () => {
13+
const getPreviousMajorVersion = (major: number) => (major === 0 ? 0 : major - 1);
14+
15+
const getPreviousMinorVersion = ([major, minor]: [number, number]) =>
16+
minor === 0 ? [getPreviousMajorVersion(major), 9] : [major, minor - 1];
17+
18+
const getPreviousPatchVersion = ([major, minor, patch]: [number, number, number]) =>
19+
patch === 0 ? [...getPreviousMinorVersion([major, minor]), 9] : [major, minor, patch - 1];
20+
21+
const [major, minor, patch] = supportedVersion.split(".").map(Number);
22+
it.each(
23+
[
24+
getPreviousPatchVersion([major, minor, patch]),
25+
[...getPreviousMinorVersion([major, minor]), 0],
26+
[getPreviousMajorVersion(major), 0, 0],
27+
].map((arr) => `v${arr.join(".")}`)
28+
)(`%s`, async (unsupportedVersion) => {
29+
process.emitWarning = jest.fn();
30+
emitWarningIfUnsupportedVersion(unsupportedVersion);
31+
expect(process.emitWarning).toHaveBeenCalledTimes(1);
32+
expect(process.emitWarning).toHaveBeenCalledWith(
33+
`The AWS SDK for JavaScript (v3) will\n` +
34+
`no longer support Node.js ${unsupportedVersion} as of January 1, 2022.\n` +
35+
`To continue receiving updates to AWS services, bug fixes, and security\n` +
36+
`updates please upgrade to Node.js 12.x or later.\n\n` +
37+
`More information can be found at: https://a.co/1l6FLnu`,
38+
`NodeDeprecationWarning`
39+
);
40+
});
41+
});
42+
43+
describe(`emits no warning for Node.js >=${supportedVersion}`, () => {
44+
const [major, minor, patch] = supportedVersion.split(".").map(Number);
45+
it.each(
46+
[
47+
[major, minor, patch],
48+
[major, minor, patch + 1],
49+
[major, minor + 1, 0],
50+
[major + 1, 0, 0],
51+
].map((arr) => `v${arr.join(".")}`)
52+
)(`%s`, async (unsupportedVersion) => {
53+
process.emitWarning = jest.fn();
54+
emitWarningIfUnsupportedVersion(unsupportedVersion);
55+
expect(process.emitWarning).not.toHaveBeenCalled();
56+
});
57+
});
58+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const emitWarningIfUnsupportedVersion = (version: string) => {
2+
if (version && parseInt(version.substring(1, version.indexOf("."))) < 12) {
3+
process.emitWarning(
4+
`The AWS SDK for JavaScript (v3) will\n` +
5+
`no longer support Node.js ${version} as of January 1, 2022.\n` +
6+
`To continue receiving updates to AWS services, bug fixes, and security\n` +
7+
`updates please upgrade to Node.js 12.x or later.\n\n` +
8+
`More information can be found at: https://a.co/1l6FLnu`,
9+
`NodeDeprecationWarning`
10+
);
11+
}
12+
};

packages/smithy-client/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./client";
22
export * from "./command";
3+
export * from "./emitWarningIfUnsupportedVersion";
34
export * from "./extended-encode-uri-component";
45
export * from "./get-array-if-single-item";
56
export * from "./get-value-from-text-node";

0 commit comments

Comments
 (0)