Skip to content

Commit 3620788

Browse files
committed
chore: convert tap test to jest
1 parent e827486 commit 3620788

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,8 @@ jobs:
812812
command: |
813813
npm run lint &&
814814
npm run build &&
815-
npm run test:unit
815+
npm run test:unit:tap &&
816+
npm run test:unit:jest
816817
name: Unit tests
817818
- run:
818819
command: |

.circleci/config/jobs/@jobs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ unit_tests:
9292
command: |
9393
npm run lint &&
9494
npm run build &&
95-
npm run test:unit
95+
npm run test:unit:tap &&
96+
npm run test:unit:jest
9697
- run:
9798
name: Notify Slack on failure
9899
command: |

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"main": "dist/index.js",
55
"scripts": {
66
"pretest": "./scripts/docker/build-image.sh",
7-
"test": "npm run lint && npm run build && npm run test:unit && npm run test:integration:kind:helm",
8-
"test:unit": "NODE_ENV=test tap test/unit --timeout=300",
7+
"test": "npm run lint && npm run build && npm run test:unit:tap && npm run test:unit:jest && npm run test:integration:kind:helm",
8+
"test:unit:tap": "NODE_ENV=test tap test/unit/*.test.ts test/unit/**/*.test.ts --timeout=300",
9+
"test:unit:jest": "jest --logHeapUsage --ci test/unit",
910
"test:system": "jest --logHeapUsage --ci --maxWorkers=1 test/system",
1011
"test:integration:kind:yaml": "DEPLOYMENT_TYPE=YAML TEST_PLATFORM=kind CREATE_CLUSTER=true jest --logHeapUsage --ci --maxWorkers=1 test/integration/kubernetes.spec.ts",
1112
"test:integration:kind:helm": "DEPLOYMENT_TYPE=Helm TEST_PLATFORM=kind CREATE_CLUSTER=true jest --logHeapUsage --ci --maxWorkers=1 test/integration/kubernetes.spec.ts",
Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import * as tap from 'tap';
2-
import * as sinon from 'sinon';
3-
import * as sleep from 'sleep-promise';
1+
import * as async from 'async';
42
import * as fs from 'fs';
3+
import * as sleep from 'sleep-promise';
54
import * as YAML from 'yaml';
6-
import async = require('async');
75

86
import { V1PodSpec, V1Pod } from '@kubernetes/client-node';
97
import { IWorkload } from '../../../src/transmitter/types';
108
import * as metadataExtractor from '../../../src/supervisor/metadata-extractor';
119

1210
let pushCallCount = 0;
13-
sinon.stub(async, 'queue').returns({ error: () => { }, push: () => pushCallCount++ } as any);
11+
const asyncQueueSpy = jest.spyOn(async, 'queue').mockReturnValue({ error: () => {}, push: () => pushCallCount++ } as any);
1412

1513
import * as pod from '../../../src/supervisor/watchers/handlers/pod';
1614

17-
tap.test('image and workload image cache', async (t) => {
15+
describe('image and workload image cache', () => {
1816
const podSpecFixture = fs.readFileSync('./test/fixtures/pod-spec.json', 'utf8');
1917
const podSpec: V1PodSpec = YAML.parse(podSpecFixture);
2018
const workloadMetadata: IWorkload[] = [
@@ -36,25 +34,33 @@ tap.test('image and workload image cache', async (t) => {
3634
},
3735
];
3836

39-
sinon.stub(metadataExtractor, 'buildMetadataForWorkload').resolves(workloadMetadata);
4037

41-
t.teardown(() => {
42-
(async['queue'] as any).restore();
43-
(metadataExtractor['buildMetadataForWorkload'] as any).restore();
38+
const buildMetadataSpy = jest.spyOn(metadataExtractor, 'buildMetadataForWorkload').mockResolvedValue(workloadMetadata);
39+
40+
afterAll(() => {
41+
asyncQueueSpy.mockRestore();
42+
buildMetadataSpy.mockRestore();
4443
});
4544

4645
const podFixture = fs.readFileSync('./test/fixtures/sidecar-containers/pod.yaml', 'utf8');
4746
const podObject: V1Pod = YAML.parse(podFixture);
48-
await pod.podWatchHandler(podObject);
49-
await sleep(500);
50-
t.equals(pushCallCount, 1, 'pushed data to send');
51-
52-
await pod.podWatchHandler(podObject);
53-
await sleep(500);
54-
t.equals(pushCallCount, 1, 'cached info, no data pushed to send');
55-
56-
workloadMetadata[0].imageId = 'newImageName';
57-
await pod.podWatchHandler(podObject);
58-
await sleep(1000);
59-
t.equals(pushCallCount, 2, 'new image parsed, workload is cached');
47+
48+
it('pushed data to send', async () => {
49+
await pod.podWatchHandler(podObject);
50+
await sleep(500);
51+
expect(pushCallCount).toEqual(1);
52+
});
53+
54+
it('cached info, no data pushed to send', async () => {
55+
await pod.podWatchHandler(podObject);
56+
await sleep(500);
57+
expect(pushCallCount).toEqual(1);
58+
});
59+
60+
it('new image parsed, workload is cached', async () => {
61+
workloadMetadata[0].imageId = 'newImageName';
62+
await pod.podWatchHandler(podObject);
63+
await sleep(1000);
64+
expect(pushCallCount).toEqual(2);
65+
});
6066
});

0 commit comments

Comments
 (0)