Skip to content

Commit fba34f4

Browse files
committed
migrate syncer to vitest
1 parent 6a82ac7 commit fba34f4

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'aws-sdk-client-mock-jest/vitest';

lambdas/functions/gh-agent-syncer/src/lambda.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Context } from 'aws-lambda';
2-
import { mocked } from 'jest-mock';
2+
33

44
import { handler } from './lambda';
55
import { sync } from './syncer/syncer';
6+
import { describe, it, expect, beforeEach, beforeAll, afterEach, afterAll, vi } from 'vitest';
7+
68

7-
jest.mock('./syncer/syncer');
9+
vi.mock('./syncer/syncer');
810

911
const context: Context = {
1012
awsRequestId: '1',
@@ -29,7 +31,7 @@ const context: Context = {
2931

3032
describe('Test download sync wrapper.', () => {
3133
it('Test successful download.', async () => {
32-
const mock = mocked(sync);
34+
const mock = vi.mocked(sync);
3335
mock.mockImplementation(() => {
3436
return new Promise((resolve) => {
3537
resolve();
@@ -39,7 +41,7 @@ describe('Test download sync wrapper.', () => {
3941
});
4042

4143
it('Test wrapper with returning an error. ', async () => {
42-
const mock = mocked(sync);
44+
const mock = vi.mocked(sync);
4345
mock.mockRejectedValue(new Error(''));
4446

4547
await expect(handler({}, context)).resolves;

lambdas/functions/gh-agent-syncer/src/syncer/syncer.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import { PassThrough } from 'stream';
77
import mockDataLatestRelease from '../../test/resources/github-latest-release.json';
88
import noX64Assets from '../../test/resources/github-releases-no-x64.json';
99
import { sync } from './syncer';
10+
import { describe, test, expect, beforeEach, beforeAll, afterEach, afterAll, vi } from 'vitest';
11+
1012

1113
const mockOctokit = {
1214
repos: {
13-
getLatestRelease: jest.fn(),
15+
getLatestRelease: vi.fn(),
1416
},
1517
};
16-
jest.mock('@octokit/rest', () => ({
17-
Octokit: jest.fn().mockImplementation(() => mockOctokit),
18+
vi.mock('@octokit/rest', () => ({
19+
Octokit: vi.fn().mockImplementation(() => mockOctokit),
1820
}));
1921

2022
// mock stream for Axios
@@ -23,8 +25,8 @@ const mockStream = new PassThrough();
2325
mockStream.push(mockResponse);
2426
mockStream.end();
2527

26-
jest.mock('axios');
27-
const mockAxios = axios as jest.Mocked<typeof axios>;
28+
vi.mock('axios');
29+
const mockAxios = axios as vi.Mocked<typeof axios>;
2830
mockAxios.get.mockResolvedValue({
2931
data: mockStream,
3032
});
@@ -49,11 +51,11 @@ const runnerOs = [['linux'], ['win']];
4951
const latestRelease = '2.296.2';
5052

5153
beforeEach(() => {
52-
jest.clearAllMocks();
54+
vi.clearAllMocks();
5355
mockS3client.reset();
5456
});
5557

56-
jest.setTimeout(60 * 1000);
58+
vi.setConfig({ testTimeout: 60 * 1000 });
5759

5860
describe('Synchronize action distribution (no S3 tags).', () => {
5961
beforeEach(() => {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { mergeConfig } from 'vitest/config';
2+
import defaultConfig from '../../vitest.base.config';
3+
4+
export default mergeConfig(defaultConfig, {
5+
test: {
6+
setupFiles: ['./aws-vitest-setup.ts'],
7+
coverage: {
8+
include: ['src/**/*.ts'],
9+
exclude: ['src/**/*.test.ts', 'src/**/*.d.ts'],
10+
thresholds: {
11+
statements: 100,
12+
branches: 96,
13+
functions: 100,
14+
lines: 100,
15+
}
16+
},
17+
},
18+
});

0 commit comments

Comments
 (0)