Skip to content

Commit 7ee13ce

Browse files
almost there
Signed-off-by: ivan katliarchuk <[email protected]>
1 parent e45019f commit 7ee13ce

File tree

6 files changed

+216
-473
lines changed

6 files changed

+216
-473
lines changed

with-tests/eks-addons/jest.config.js

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import crypto from 'node:crypto';
2+
import os from 'node:os';
3+
import { env } from 'node:process';
4+
import v8 from 'node:v8';
5+
import { minimatch } from 'minimatch';
6+
import type { JestConfigWithTsJest } from 'ts-jest';
7+
8+
const ci = !!process.env.CI;
9+
10+
type JestConfig = JestConfigWithTsJest & {
11+
// https://github.com/renovatebot/renovate/issues/17034
12+
workerIdleMemoryLimit?: string;
13+
};
14+
15+
const cpus = os.cpus();
16+
const mem = os.totalmem();
17+
const stats = v8.getHeapStatistics();
18+
19+
/**
20+
* https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
21+
* Currently it seems the runner only have 4GB
22+
*/
23+
function jestGithubRunnerSpecs(): JestConfig {
24+
// if (os.platform() === 'darwin') {
25+
// return {
26+
// maxWorkers: 2,
27+
// workerIdleMemoryLimit: '4GB',
28+
// };
29+
// }
30+
31+
return {
32+
maxWorkers: cpus.length,
33+
workerIdleMemoryLimit: '1500MB', // '2GB',
34+
};
35+
}
36+
37+
/**
38+
* Configuration for single test shard.
39+
*/
40+
interface ShardConfig {
41+
/**
42+
* Path patterns to match against the test file paths, of two types:
43+
*
44+
* 1. Particular file, e.g. `lib/util/git/index.spec.ts`
45+
*
46+
* - File pattern MUST end with `.spec.ts`
47+
* - This will only search for the particular test file
48+
* - It enables coverage for the `*.ts` file with the same name,
49+
* e.g. `lib/util/git/index.ts`
50+
* - You probably want to use directory pattern instead
51+
*
52+
* 2. Whole directory, e.g. `lib/modules/datasource`
53+
*
54+
* - This will search for all `*.spec.ts` files under the directory
55+
* - It enables coverage all `*.ts` files under the directory,
56+
* e.g. `lib/modules/datasource/foo/bar/baz.ts`
57+
*/
58+
matchPaths: string[];
59+
}
60+
61+
62+
63+
const config: JestConfig = {
64+
...configureShardingOrFallbackTo({
65+
coverageDirectory: './coverage',
66+
}),
67+
collectCoverageFrom: [
68+
'lib/**/*.{js,ts}',
69+
'!lib/**/*.{d,spec}.ts',
70+
'!lib/**/{__fixtures__,__mocks__,__testutil__,test}/**/*.{js,ts}',
71+
'!lib/**/types.ts',
72+
],
73+
coveragePathIgnorePatterns: getCoverageIgnorePatterns(),
74+
cacheDirectory: '.cache/jest',
75+
collectCoverage: true,
76+
coverageReporters: ci
77+
? ['lcovonly', 'json']
78+
: ['html', 'text-summary', 'json'],
79+
transform: {
80+
'\\.ts$': [
81+
'ts-jest',
82+
{
83+
tsconfig: '<rootDir>/tsconfig.spec.json',
84+
diagnostics: false,
85+
isolatedModules: true,
86+
},
87+
],
88+
},
89+
modulePathIgnorePatterns: [
90+
'<rootDir>/dist/',
91+
'/__fixtures__/',
92+
'/__mocks__/',
93+
],
94+
reporters: ci ? ['default', 'github-actions'] : ['default'],
95+
resetMocks: true,
96+
setupFilesAfterEnv: [
97+
'jest-extended/all',
98+
'expect-more-jest',
99+
'<rootDir>/test/setup.ts',
100+
'<rootDir>/test/to-migrate.ts',
101+
],
102+
snapshotSerializers: ['<rootDir>/test/newline-snapshot-serializer.ts'],
103+
testEnvironment: 'node',
104+
testRunner: 'jest-circus/runner',
105+
watchPathIgnorePatterns: ['<rootDir>/.cache/', '<rootDir>/coverage/'],
106+
// We can play with that value later for best dev experience
107+
workerIdleMemoryLimit: '500MB',
108+
// add github runner specific limits
109+
...(ci && jestGithubRunnerSpecs()),
110+
};
111+
112+
export default config;
113+
114+
type RunsOn = 'ubuntu-latest' | 'windows-latest' | 'macos-latest';
115+
116+
interface ShardGroup {
117+
/**
118+
* Input for `runs-on` field.
119+
*/
120+
os: RunsOn;
121+
122+
/**
123+
* Controls whether coverage is collected for this shard group.
124+
*/
125+
coverage: boolean;
126+
127+
/**
128+
* Input for `name` field.
129+
*/
130+
name: string;
131+
132+
/**
133+
* Space-separated list of shard keys, it's
134+
* meant to be inserted into bash for-loop.
135+
*/
136+
shards: string;
137+
138+
/**
139+
* It's meant to be used for Jest caching.
140+
*/
141+
'cache-key': string;
142+
143+
/**
144+
* It's used to set test runner timeout.
145+
*/
146+
'runner-timeout-minutes': number;
147+
148+
/**
149+
* It's used to set `--test-timeout` Jest CLI flag.
150+
*/
151+
'test-timeout-milliseconds': number;
152+
153+
/**
154+
* It's used as the name for coverage artifact.
155+
*/
156+
'upload-artifact-name': string;
157+
}

with-tests/eks-addons/package.json

+14-13
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@
1616
"@aws-sdk/client-eks": "3.718.0",
1717
"@aws-sdk/credential-providers": "3.699.0",
1818
"@types/node": "^22.10.2",
19-
"typescript": "^5.7.2",
20-
"zod": "3.24.1",
21-
"type-fest": "4.30.2",
19+
"jsonc-parser": "3.3.1",
2220
"luxon": "3.5.0",
23-
"jsonc-parser": "3.3.1"
21+
"type-fest": "4.30.2",
22+
"typescript": "^5.7.2",
23+
"zod": "3.24.1"
2424
},
2525
"devDependencies": {
26-
"ts-jest": "29.2.5",
27-
"ts-node": "10.9.2",
28-
"@jest/types": "29.6.3",
29-
"jest": "29.7.0",
30-
"jest-extended": "4.0.2",
31-
"jest-mock": "29.7.0",
32-
"jest-mock-extended": "3.0.7",
33-
"jest-snapshot": "29.7.0",
34-
"aws-sdk-client-mock": "4.1.0"
26+
"@jest/types": "29.6.3",
27+
"@types/jest": "^29.5.14",
28+
"aws-sdk-client-mock": "4.1.0",
29+
"jest": "29.7.0",
30+
"ts-jest": "29.2.5",
31+
"ts-node": "10.9.2",
32+
"jest-extended": "4.0.2",
33+
"jest-mock": "29.7.0",
34+
"jest-mock-extended": "3.0.7",
35+
"jest-snapshot": "29.7.0"
3536
}
3637
}

with-tests/eks-addons/readme.md

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ npm install @aws-sdk/client-eks
1010
yarn add @aws-sdk/client-eks
1111
pnpm add @aws-sdk/client-eks
1212
npm i -g run-s
13-
1413
```
1514

1615
Can be added to package.json

with-tests/eks-addons/src/app.spec.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { EKSClient } from '@aws-sdk/client-eks';
2+
import { mockClient } from 'aws-sdk-client-mock';
3+
import { AwsEKSAddonDataSource } from './app';
4+
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
5+
6+
const eksClientMock = mockClient(EKSClient);
7+
8+
describe('AwsEKSAddonDataSource', () => {
9+
it('should create a new EKSClient if not cached', async () => {
10+
11+
});
12+
})
13+
14+
// describe('AwsEKSAddonDataSource', () => {
15+
// let dataSource: AwsEKSAddonDataSource;
16+
//
17+
// beforeEach(() => {
18+
// eksClientMock.reset();
19+
// dataSource = new AwsEKSAddonDataSource();
20+
// });
21+
//
22+
// it('should create a new EKSClient if not cached', async () => {
23+
// const region = 'us-west-2';
24+
// const profile = 'default';
25+
// const client = dataSource['getClient']({ region, profile });
26+
//
27+
// expect(client).toBeInstanceOf(EKSClient);
28+
// expect(eksClientMock.calls()).toHaveLength(1);
29+
// expect(eksClientMock.calls()[0].args[0]).toEqual({
30+
// region,
31+
// credentials: fromNodeProviderChain({ profile }),
32+
// });
33+
// });
34+
//
35+
// it('should return cached EKSClient if already created', async () => {
36+
// const region = 'us-west-2';
37+
// const profile = 'default';
38+
// const client1 = dataSource['getClient']({ region, profile });
39+
// const client2 = dataSource['getClient']({ region, profile });
40+
//
41+
// expect(client1).toBe(client2);
42+
// expect(eksClientMock.calls()).toHaveLength(1);
43+
// });
44+
// });

with-tests/eks-addons/src/app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { EksAddonsFilter } from './schema';
2121
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-eks/Interface/DescribeAddonVersionsCommandInput/
2222

2323
// if cluster version not specified return latest cluster default
24-
class AwsEKSAddonDataSource {
24+
export class AwsEKSAddonDataSource {
2525

2626
private readonly clients: Record<string, EKSClient> = {};
2727

0 commit comments

Comments
 (0)