Skip to content

Commit a21fcb9

Browse files
committed
tests(maintenance): migrate testing utils to vitest
1 parent 40a6b21 commit a21fcb9

File tree

5 files changed

+61
-97
lines changed

5 files changed

+61
-97
lines changed

packages/testing/jest.config.cjs

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/testing/package.json

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
},
99
"private": true,
1010
"scripts": {
11-
"test": "npm run test:unit",
12-
"test:unit": "jest --group=unit --detectOpenHandles --verbose",
13-
"jest": "jest --detectOpenHandles --verbose",
11+
"test": "vitest --run",
12+
"test:unit": "vitest --run",
1413
"test:e2e": "echo 'Not implemented'",
1514
"watch": "jest --watch",
1615
"build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
@@ -31,49 +30,56 @@
3130
"exports": {
3231
".": {
3332
"require": {
34-
"types": "./lib/cjs/index.d.ts",
35-
"default": "./lib/cjs/index.js"
33+
"source": "./src/index.ts",
34+
"default": "./lib/cjs/index.js",
35+
"types": "./lib/cjs/index.d.ts"
3636
},
3737
"import": {
38-
"types": "./lib/esm/index.d.ts",
39-
"default": "./lib/esm/index.js"
38+
"source": "./src/index.ts",
39+
"default": "./lib/esm/index.js",
40+
"types": "./lib/esm/index.d.ts"
4041
}
4142
},
4243
"./resources/lambda": {
43-
"import": "./lib/esm/resources/TestNodejsFunction.js",
44-
"require": "./lib/cjs/resources/TestNodejsFunction.js"
44+
"import": {
45+
"source": "./src/resources/TestNodejsFunction.ts",
46+
"default": "./lib/esm/resources/TestNodejsFunction.js",
47+
"types": "./lib/esm/resources/TestNodejsFunction.d.ts"
48+
},
49+
"require": {
50+
"source": "./src/resources/TestNodejsFunction.ts",
51+
"default": "./lib/cjs/resources/TestNodejsFunction.js",
52+
"types": "./lib/cjs/resources/TestNodejsFunction.d.ts"
53+
}
4554
},
4655
"./resources/dynamodb": {
47-
"import": "./lib/esm/resources/TestDynamodbTable.js",
48-
"require": "./lib/cjs/resources/TestDynamodbTable.js"
56+
"import": {
57+
"source": "./src/resources/TestDynamodbTable.ts",
58+
"default": "./lib/esm/resources/TestDynamodbTable.js",
59+
"types": "./lib/esm/resources/TestDynamodbTable.d.ts"
60+
},
61+
"require": {
62+
"source": "./src/resources/TestDynamodbTable.ts",
63+
"default": "./lib/cjs/resources/TestDynamodbTable.js",
64+
"types": "./lib/cjs/resources/TestDynamodbTable.d.ts"
65+
}
4966
},
5067
"./context": {
68+
"source": "./src/context.ts",
5169
"import": "./lib/esm/context.js",
5270
"require": "./lib/cjs/context.js"
5371
},
5472
"./types": {
55-
"import": "./lib/esm/types.js",
56-
"require": "./lib/cjs/types.js"
57-
}
58-
},
59-
"typesVersions": {
60-
"*": {
61-
"resources/lambda": [
62-
"lib/cjs/resources/TestNodejsFunction.d.ts",
63-
"lib/esm/resources/TestNodejsFunction.d.ts"
64-
],
65-
"resources/dynamodb": [
66-
"lib/cjs/resources/TestDynamodbTable.d.ts",
67-
"lib/esm/resources/TestDynamodbTable.d.ts"
68-
],
69-
"types": [
70-
"lib/cjs/types.d.ts",
71-
"lib/esm/types.d.ts"
72-
],
73-
"context": [
74-
"lib/cjs/context.d.ts",
75-
"lib/esm/context.d.ts"
76-
]
73+
"import": {
74+
"source": "./src/types.ts",
75+
"default": "./lib/esm/types.js",
76+
"types": "./lib/esm/types.d.ts"
77+
},
78+
"require": {
79+
"source": "./src/types.ts",
80+
"default": "./lib/cjs/types.js",
81+
"types": "./lib/esm/types.d.ts"
82+
}
7783
}
7884
},
7985
"types": "./lib/cjs/index.d.ts",

packages/testing/tests/helpers/populateEnvironmentVariables.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/testing/tests/unit/TestInvocationLogs.test.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
/**
2-
* Test InvocationLogs class
3-
*
4-
* @group unit/commons/invocationLogs
5-
*
6-
*/
1+
import { beforeEach, describe, expect, it } from 'vitest';
72
import { TestInvocationLogs } from '../../src/TestInvocationLogs.js';
83

94
const exampleLogs = `START RequestId: c6af9ac6-7b61-11e6-9a41-93e812345678 Version: $LATEST
@@ -15,7 +10,7 @@ END RequestId: c6af9ac6-7b61-11e6-9a41-93e812345678
1510
REPORT RequestId: c6af9ac6-7b61-11e6-9a41-93e812345678\tDuration: 2.16 ms\tBilled Duration: 3 ms\tMemory Size: 128 MB\tMax Memory Used: 57 MB\t`;
1611

1712
describe('Constructor', () => {
18-
test('it should parse base64 text correctly', () => {
13+
it('parses base64 text correctly', () => {
1914
const invocationLogs = new TestInvocationLogs(
2015
Buffer.from(exampleLogs).toString('base64')
2116
);
@@ -33,29 +28,29 @@ describe('doesAnyFunctionLogsContains()', () => {
3328
Buffer.from(exampleLogs).toString('base64')
3429
);
3530
});
36-
test('it should return true if the text appear in any logs', () => {
31+
it('returns true if the text appear in any of the logs', () => {
3732
const phraseInMessage = 'This is';
3833
expect(invocationLogs.doesAnyFunctionLogsContains(phraseInMessage)).toBe(
3934
true
4035
);
4136
});
42-
test('it should return false if the text does not appear in any logs', () => {
37+
it('returns false if the text does not appear anywhere', () => {
4338
const phraseNotInMessage = 'A quick brown fox jumps over the lazy dog';
4439
expect(invocationLogs.doesAnyFunctionLogsContains(phraseNotInMessage)).toBe(
4540
false
4641
);
4742
});
4843

49-
test('it should return true for key in the log', () => {
44+
it('returns true if the provided key appears in any of the logs', () => {
5045
const keyInLog = 'error';
5146
expect(invocationLogs.doesAnyFunctionLogsContains(keyInLog)).toBe(true);
5247
});
5348

54-
test('it should return true for a text in an error key', () => {
49+
it('returns true it the provided text appears in an error key within the logs', () => {
5550
const textInError = '/var/task/index.js:2778';
5651
expect(invocationLogs.doesAnyFunctionLogsContains(textInError)).toBe(true);
5752
});
58-
test('it should return false for the text that appears only on the ', () => {
53+
it('excludes the report logs from the search', () => {
5954
const textInStartLine = 'Version: $LATEST';
6055
const textInEndLine = 'END RequestId';
6156
const textInReportLine = 'Billed Duration';
@@ -70,7 +65,7 @@ describe('doesAnyFunctionLogsContains()', () => {
7065
);
7166
});
7267

73-
test('it should apply filter log based on the given level', () => {
68+
it('filters log based on the given level', () => {
7469
const debugLogHasWordINFO = invocationLogs.doesAnyFunctionLogsContains(
7570
'INFO',
7671
'DEBUG'
@@ -100,7 +95,7 @@ describe('getFunctionLogs()', () => {
10095
);
10196
});
10297

103-
test('it should retrive logs of the given level only', () => {
98+
it('retrives logs of the given level only', () => {
10499
const infoLogs = invocationLogs.getFunctionLogs('INFO');
105100
expect(infoLogs.length).toBe(2);
106101
expect(infoLogs[0].includes('INFO')).toBe(true);
@@ -114,7 +109,7 @@ describe('getFunctionLogs()', () => {
114109
expect(errorLogs[0].includes('ERROR')).toBe(true);
115110
});
116111

117-
test('it should NOT return logs generated by Lambda service (e.g. START, END, and REPORT)', () => {
112+
it("doesn't return logs generated by Lambda service (e.g. START, END, and REPORT)", () => {
118113
const errorLogs = invocationLogs.getFunctionLogs('ERROR');
119114
expect(errorLogs.length).toBe(1);
120115
expect(errorLogs[0].includes('START')).toBe(false);
@@ -124,7 +119,7 @@ describe('getFunctionLogs()', () => {
124119
});
125120

126121
describe('parseFunctionLog()', () => {
127-
test('it should return object with the correct values based on the given log', () => {
122+
it('returns an object with the correct values based on the given log', () => {
128123
const rawLogStr =
129124
'{"cold_start":true,"function_arn":"arn:aws:lambda:eu-west-1:561912387782:function:loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_memory_size":128,"function_name":"loggerMiddyStandardFeatures-c555a2ec-1121-4586-9c04-185ab36ea34c","function_request_id":"7f586697-238a-4c3b-9250-a5f057c1119c","level":"DEBUG","message":"This is a DEBUG log but contains the word INFO some context and persistent key","service":"logger-e2e-testing","timestamp":"2022-01-27T16:04:39.323Z","persistentKey":"works"}';
130125

@@ -146,7 +141,7 @@ describe('parseFunctionLog()', () => {
146141
});
147142
});
148143

149-
test('it should throw an error if receive incorrect formatted raw log string', () => {
144+
it('throws an error if receive incorrect formatted raw log string', () => {
150145
const notJSONstring = 'not-json-string';
151146
expect(() => {
152147
TestInvocationLogs.parseFunctionLog(notJSONstring);

packages/testing/vitest.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineProject } from 'vitest/config';
2+
3+
export default defineProject({
4+
resolve: {
5+
conditions: ['source'],
6+
},
7+
test: {
8+
environment: 'node',
9+
},
10+
});

0 commit comments

Comments
 (0)