@geekmidas/testkit 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Factory-BFVnMMCC.mjs.map +1 -1
- package/dist/Factory-BhjUOBWN.cjs.map +1 -1
- package/dist/{Factory-c16c27Y6.d.cts → Factory-Bx0AJXZB.d.cts} +3 -2
- package/dist/Factory-Bx0AJXZB.d.cts.map +1 -0
- package/dist/{Factory-BcGJjLc8.d.mts → Factory-SFupxRC2.d.mts} +2 -1
- package/dist/Factory-SFupxRC2.d.mts.map +1 -0
- package/dist/Factory.d.cts +2 -2
- package/dist/Factory.d.mts +1 -1
- package/dist/KyselyFactory-BFqVIn_0.cjs.map +1 -1
- package/dist/KyselyFactory-DMswpwji.mjs.map +1 -1
- package/dist/{KyselyFactory-uZ45h7YU.d.cts → KyselyFactory-KLeKH43i.d.cts} +4 -3
- package/dist/KyselyFactory-KLeKH43i.d.cts.map +1 -0
- package/dist/{KyselyFactory-Cj-EultY.d.mts → KyselyFactory-vAxYodck.d.mts} +3 -2
- package/dist/KyselyFactory-vAxYodck.d.mts.map +1 -0
- package/dist/KyselyFactory.d.cts +3 -3
- package/dist/KyselyFactory.d.mts +2 -2
- package/dist/{ObjectionFactory-DL4qkuF1.d.mts → ObjectionFactory-BWjB49-i.d.mts} +3 -2
- package/dist/ObjectionFactory-BWjB49-i.d.mts.map +1 -0
- package/dist/ObjectionFactory-BeFBYcan.cjs.map +1 -1
- package/dist/ObjectionFactory-QCJ7u0Ql.mjs.map +1 -1
- package/dist/{ObjectionFactory-CdhzKs4f.d.cts → ObjectionFactory-aMGvAKt9.d.cts} +4 -3
- package/dist/ObjectionFactory-aMGvAKt9.d.cts.map +1 -0
- package/dist/ObjectionFactory.d.cts +3 -3
- package/dist/ObjectionFactory.d.mts +2 -2
- package/dist/{PostgresKyselyMigrator-upT-hmrz.mjs → PostgresKyselyMigrator-6sE1KOni.mjs} +2 -2
- package/dist/PostgresKyselyMigrator-6sE1KOni.mjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-CIx3AFSR.d.mts → PostgresKyselyMigrator-CBltSOq5.d.cts} +3 -2
- package/dist/PostgresKyselyMigrator-CBltSOq5.d.cts.map +1 -0
- package/dist/{PostgresKyselyMigrator-CfytARcA.cjs → PostgresKyselyMigrator-D6IbPq8t.cjs} +2 -2
- package/dist/PostgresKyselyMigrator-D6IbPq8t.cjs.map +1 -0
- package/dist/{PostgresKyselyMigrator-CQ3aUoy_.d.cts → PostgresKyselyMigrator-DrVWncqd.d.mts} +3 -2
- package/dist/PostgresKyselyMigrator-DrVWncqd.d.mts.map +1 -0
- package/dist/PostgresKyselyMigrator.cjs +2 -2
- package/dist/PostgresKyselyMigrator.d.cts +2 -2
- package/dist/PostgresKyselyMigrator.d.mts +2 -2
- package/dist/PostgresKyselyMigrator.mjs +2 -2
- package/dist/{PostgresMigrator-DbuJGAVy.mjs → PostgresMigrator-BjjenqSd.mjs} +2 -2
- package/dist/PostgresMigrator-BjjenqSd.mjs.map +1 -0
- package/dist/{PostgresMigrator-D5UkK1_K.d.cts → PostgresMigrator-Bres0U6E.d.cts} +2 -1
- package/dist/PostgresMigrator-Bres0U6E.d.cts.map +1 -0
- package/dist/{PostgresMigrator-DFcNdCvD.cjs → PostgresMigrator-D6dQn0x2.cjs} +2 -2
- package/dist/PostgresMigrator-D6dQn0x2.cjs.map +1 -0
- package/dist/{PostgresMigrator-DQaRxoaY.d.mts → PostgresMigrator-S-YYosAC.d.mts} +2 -1
- package/dist/PostgresMigrator-S-YYosAC.d.mts.map +1 -0
- package/dist/PostgresMigrator.cjs +1 -1
- package/dist/PostgresMigrator.d.cts +1 -1
- package/dist/PostgresMigrator.d.mts +1 -1
- package/dist/PostgresMigrator.mjs +1 -1
- package/dist/{PostgresObjectionMigrator-CZHHcCOv.d.cts → PostgresObjectionMigrator-CPfBAP7r.d.cts} +3 -2
- package/dist/PostgresObjectionMigrator-CPfBAP7r.d.cts.map +1 -0
- package/dist/{PostgresObjectionMigrator-BG6ymgnt.cjs → PostgresObjectionMigrator-DK8ODIHQ.cjs} +2 -2
- package/dist/PostgresObjectionMigrator-DK8ODIHQ.cjs.map +1 -0
- package/dist/{PostgresObjectionMigrator-D_hCcrQu.d.mts → PostgresObjectionMigrator-DVEqB5tp.d.mts} +3 -2
- package/dist/PostgresObjectionMigrator-DVEqB5tp.d.mts.map +1 -0
- package/dist/{PostgresObjectionMigrator-DPj2pOpX.mjs → PostgresObjectionMigrator-D_QxXbIN.mjs} +2 -2
- package/dist/PostgresObjectionMigrator-D_QxXbIN.mjs.map +1 -0
- package/dist/PostgresObjectionMigrator.cjs +2 -2
- package/dist/PostgresObjectionMigrator.d.cts +2 -2
- package/dist/PostgresObjectionMigrator.d.mts +2 -2
- package/dist/PostgresObjectionMigrator.mjs +2 -2
- package/dist/{VitestKyselyTransactionIsolator-D3EZZhjZ.d.cts → VitestKyselyTransactionIsolator-CduJlHoT.d.cts} +4 -3
- package/dist/VitestKyselyTransactionIsolator-CduJlHoT.d.cts.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-Dxlp1u0f.d.mts → VitestKyselyTransactionIsolator-Cswnnj0k.d.mts} +4 -3
- package/dist/VitestKyselyTransactionIsolator-Cswnnj0k.d.mts.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-EvDLk5zg.cjs → VitestKyselyTransactionIsolator-D7RRXOBa.cjs} +2 -2
- package/dist/VitestKyselyTransactionIsolator-D7RRXOBa.cjs.map +1 -0
- package/dist/{VitestKyselyTransactionIsolator-CNURW8y6.mjs → VitestKyselyTransactionIsolator-DceyIqr4.mjs} +2 -2
- package/dist/VitestKyselyTransactionIsolator-DceyIqr4.mjs.map +1 -0
- package/dist/VitestKyselyTransactionIsolator.cjs +1 -1
- package/dist/VitestKyselyTransactionIsolator.d.cts +2 -2
- package/dist/VitestKyselyTransactionIsolator.d.mts +2 -2
- package/dist/VitestKyselyTransactionIsolator.mjs +1 -1
- package/dist/{VitestObjectionTransactionIsolator-1TpsPqfG.d.cts → VitestObjectionTransactionIsolator-BXoR6xdG.d.cts} +4 -3
- package/dist/VitestObjectionTransactionIsolator-BXoR6xdG.d.cts.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-CM5KTAFA.cjs → VitestObjectionTransactionIsolator-CdLRrzNf.cjs} +2 -2
- package/dist/VitestObjectionTransactionIsolator-CdLRrzNf.cjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-jQFaCz0u.mjs → VitestObjectionTransactionIsolator-OF2osYY5.mjs} +2 -2
- package/dist/VitestObjectionTransactionIsolator-OF2osYY5.mjs.map +1 -0
- package/dist/{VitestObjectionTransactionIsolator-i9jIgU8Q.d.mts → VitestObjectionTransactionIsolator-x6hY5j4u.d.mts} +4 -3
- package/dist/VitestObjectionTransactionIsolator-x6hY5j4u.d.mts.map +1 -0
- package/dist/VitestObjectionTransactionIsolator.cjs +1 -1
- package/dist/VitestObjectionTransactionIsolator.d.cts +2 -2
- package/dist/VitestObjectionTransactionIsolator.d.mts +2 -2
- package/dist/VitestObjectionTransactionIsolator.mjs +1 -1
- package/dist/{VitestTransactionIsolator-BvR19bYn.d.mts → VitestTransactionIsolator-BNWJqh9f.d.mts} +3 -2
- package/dist/VitestTransactionIsolator-BNWJqh9f.d.mts.map +1 -0
- package/dist/VitestTransactionIsolator-CMfJXZP8.cjs.map +1 -1
- package/dist/{VitestTransactionIsolator-CwQaxZLP.d.cts → VitestTransactionIsolator-CSroc7Df.d.cts} +3 -2
- package/dist/VitestTransactionIsolator-CSroc7Df.d.cts.map +1 -0
- package/dist/VitestTransactionIsolator-DQ7tLqgV.mjs.map +1 -1
- package/dist/VitestTransactionIsolator.d.cts +1 -1
- package/dist/VitestTransactionIsolator.d.mts +1 -1
- package/dist/aws.cjs.map +1 -1
- package/dist/aws.d.cts +2 -0
- package/dist/aws.d.cts.map +1 -0
- package/dist/aws.d.mts +2 -0
- package/dist/aws.d.mts.map +1 -0
- package/dist/aws.mjs.map +1 -1
- package/dist/benchmark.cjs.map +1 -1
- package/dist/benchmark.d.cts +1 -0
- package/dist/benchmark.d.cts.map +1 -0
- package/dist/benchmark.d.mts +1 -0
- package/dist/benchmark.d.mts.map +1 -0
- package/dist/benchmark.mjs.map +1 -1
- package/dist/better-auth.cjs +29 -30
- package/dist/better-auth.cjs.map +1 -1
- package/dist/better-auth.d.cts +2 -2
- package/dist/better-auth.d.cts.map +1 -0
- package/dist/better-auth.d.mts.map +1 -0
- package/dist/better-auth.mjs +29 -30
- package/dist/better-auth.mjs.map +1 -1
- package/dist/directory-B-Ozljzk.mjs.map +1 -1
- package/dist/directory-BVC8g7cX.cjs.map +1 -1
- package/dist/{directory-BXavAeJZ.d.mts → directory-CVrfTq1I.d.mts} +2 -1
- package/dist/directory-CVrfTq1I.d.mts.map +1 -0
- package/dist/directory-Cys9g76X.d.cts +13 -0
- package/dist/directory-Cys9g76X.d.cts.map +1 -0
- package/dist/faker-B14IEMIN.cjs.map +1 -1
- package/dist/faker-BGKYFoCT.mjs.map +1 -1
- package/dist/{faker-DvxiCtxc.d.cts → faker-BSH1EMtg.d.cts} +3 -3
- package/dist/faker-BSH1EMtg.d.cts.map +1 -0
- package/dist/faker-DHh7xs4u.d.mts.map +1 -0
- package/dist/faker.d.cts +1 -1
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +1 -0
- package/dist/helpers.d.cts.map +1 -0
- package/dist/helpers.d.mts +1 -0
- package/dist/helpers.d.mts.map +1 -0
- package/dist/helpers.mjs.map +1 -1
- package/dist/kysely.cjs +3 -3
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +8 -7
- package/dist/kysely.d.cts.map +1 -0
- package/dist/kysely.d.mts +7 -6
- package/dist/kysely.d.mts.map +1 -0
- package/dist/kysely.mjs +3 -3
- package/dist/kysely.mjs.map +1 -1
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +1 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs.map +1 -1
- package/dist/objection.cjs +3 -3
- package/dist/objection.cjs.map +1 -1
- package/dist/objection.d.cts +8 -7
- package/dist/objection.d.cts.map +1 -0
- package/dist/objection.d.mts +7 -6
- package/dist/objection.d.mts.map +1 -0
- package/dist/objection.mjs +3 -3
- package/dist/objection.mjs.map +1 -1
- package/dist/os/directory.d.cts +1 -1
- package/dist/os/directory.d.mts +1 -1
- package/dist/os/index.d.cts +1 -1
- package/dist/os/index.d.mts +1 -1
- package/dist/timer.cjs.map +1 -1
- package/dist/timer.d.cts +2 -0
- package/dist/timer.d.cts.map +1 -0
- package/dist/timer.d.mts +2 -0
- package/dist/timer.d.mts.map +1 -0
- package/dist/timer.mjs.map +1 -1
- package/package.json +5 -5
- package/src/Factory.ts +72 -72
- package/src/KyselyFactory.ts +330 -330
- package/src/ObjectionFactory.ts +354 -355
- package/src/PostgresKyselyMigrator.ts +37 -37
- package/src/PostgresMigrator.ts +107 -107
- package/src/PostgresObjectionMigrator.ts +91 -91
- package/src/VitestKyselyTransactionIsolator.ts +27 -27
- package/src/VitestObjectionTransactionIsolator.ts +39 -39
- package/src/VitestTransactionIsolator.ts +196 -195
- package/src/__tests__/Factory.spec.ts +163 -155
- package/src/__tests__/KyselyFactory.spec.ts +443 -439
- package/src/__tests__/ObjectionFactory.spec.ts +563 -557
- package/src/__tests__/PostgresKyselyMigrator.spec.ts +641 -641
- package/src/__tests__/PostgresMigrator.spec.ts +341 -341
- package/src/__tests__/PostgresObjectionMigrator.spec.ts +578 -578
- package/src/__tests__/VitestObjectionTransactionIsolator.spec.ts +114 -114
- package/src/__tests__/benchmark.spec.ts +140 -0
- package/src/__tests__/better-auth.spec.ts +15 -15
- package/src/__tests__/faker.spec.ts +226 -137
- package/src/__tests__/integration.spec.ts +597 -597
- package/src/__tests__/utilities.spec.ts +211 -0
- package/src/aws.ts +104 -104
- package/src/benchmark.ts +12 -12
- package/src/better-auth.ts +286 -301
- package/src/faker.ts +153 -153
- package/src/helpers.ts +6 -6
- package/src/kysely.ts +33 -33
- package/src/logger.ts +10 -10
- package/src/objection.ts +31 -31
- package/src/os/directory.ts +11 -10
- package/src/timer.ts +1 -1
- package/test/globalSetup.ts +45 -45
- package/test/helpers.ts +189 -189
- package/test/migrations/1749664623372_user.ts +13 -13
- package/tsconfig.json +9 -0
- package/vitest.config.ts +4 -4
- package/dist/PostgresKyselyMigrator-CfytARcA.cjs.map +0 -1
- package/dist/PostgresKyselyMigrator-upT-hmrz.mjs.map +0 -1
- package/dist/PostgresMigrator-DFcNdCvD.cjs.map +0 -1
- package/dist/PostgresMigrator-DbuJGAVy.mjs.map +0 -1
- package/dist/PostgresObjectionMigrator-BG6ymgnt.cjs.map +0 -1
- package/dist/PostgresObjectionMigrator-DPj2pOpX.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-CNURW8y6.mjs.map +0 -1
- package/dist/VitestKyselyTransactionIsolator-EvDLk5zg.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-CM5KTAFA.cjs.map +0 -1
- package/dist/VitestObjectionTransactionIsolator-jQFaCz0u.mjs.map +0 -1
- package/dist/directory-Mi7tdOuD.d.cts +0 -12
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import {
|
|
5
|
+
createMockContext,
|
|
6
|
+
createMockV1Event,
|
|
7
|
+
createMockV2Event,
|
|
8
|
+
} from '../aws';
|
|
9
|
+
import { createMockLogger } from '../logger';
|
|
10
|
+
import { itWithDir } from '../os/directory';
|
|
11
|
+
import { waitFor } from '../timer';
|
|
12
|
+
|
|
13
|
+
describe('testkit utilities', () => {
|
|
14
|
+
describe('createMockLogger', () => {
|
|
15
|
+
it('should create a logger with all required methods', () => {
|
|
16
|
+
const logger = createMockLogger();
|
|
17
|
+
|
|
18
|
+
expect(logger.debug).toBeDefined();
|
|
19
|
+
expect(logger.info).toBeDefined();
|
|
20
|
+
expect(logger.warn).toBeDefined();
|
|
21
|
+
expect(logger.error).toBeDefined();
|
|
22
|
+
expect(logger.fatal).toBeDefined();
|
|
23
|
+
expect(logger.trace).toBeDefined();
|
|
24
|
+
expect(logger.child).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should have mock functions that can be called', () => {
|
|
28
|
+
const logger = createMockLogger();
|
|
29
|
+
|
|
30
|
+
logger.debug('debug message');
|
|
31
|
+
logger.info({ data: 'test' }, 'info message');
|
|
32
|
+
logger.warn('warning');
|
|
33
|
+
logger.error('error');
|
|
34
|
+
logger.fatal('fatal');
|
|
35
|
+
logger.trace('trace');
|
|
36
|
+
|
|
37
|
+
expect(logger.debug).toHaveBeenCalledWith('debug message');
|
|
38
|
+
expect(logger.info).toHaveBeenCalledWith(
|
|
39
|
+
{ data: 'test' },
|
|
40
|
+
'info message',
|
|
41
|
+
);
|
|
42
|
+
expect(logger.warn).toHaveBeenCalledWith('warning');
|
|
43
|
+
expect(logger.error).toHaveBeenCalledWith('error');
|
|
44
|
+
expect(logger.fatal).toHaveBeenCalledWith('fatal');
|
|
45
|
+
expect(logger.trace).toHaveBeenCalledWith('trace');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should return itself from child()', () => {
|
|
49
|
+
const logger = createMockLogger();
|
|
50
|
+
const childLogger = logger.child({ module: 'test' });
|
|
51
|
+
|
|
52
|
+
expect(childLogger).toBe(logger);
|
|
53
|
+
expect(logger.child).toHaveBeenCalledWith({ module: 'test' });
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('waitFor', () => {
|
|
58
|
+
it('should wait for the specified time', async () => {
|
|
59
|
+
const start = Date.now();
|
|
60
|
+
await waitFor(50);
|
|
61
|
+
const elapsed = Date.now() - start;
|
|
62
|
+
|
|
63
|
+
expect(elapsed).toBeGreaterThanOrEqual(40);
|
|
64
|
+
expect(elapsed).toBeLessThan(150);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should resolve without a value', async () => {
|
|
68
|
+
const result = await waitFor(10);
|
|
69
|
+
expect(result).toBeUndefined();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('AWS mock utilities', () => {
|
|
74
|
+
describe('createMockContext', () => {
|
|
75
|
+
it('should create a valid Lambda context', () => {
|
|
76
|
+
const context = createMockContext();
|
|
77
|
+
|
|
78
|
+
expect(context.awsRequestId).toBe('test-request-id');
|
|
79
|
+
expect(context.functionName).toBe('test-function');
|
|
80
|
+
expect(context.functionVersion).toBe('1');
|
|
81
|
+
expect(context.memoryLimitInMB).toBe('128');
|
|
82
|
+
expect(context.logGroupName).toBe('/aws/lambda/test-function');
|
|
83
|
+
expect(context.invokedFunctionArn).toContain('arn:aws:lambda');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should have mock callback functions', () => {
|
|
87
|
+
const context = createMockContext();
|
|
88
|
+
|
|
89
|
+
expect(context.done).toBeDefined();
|
|
90
|
+
expect(context.fail).toBeDefined();
|
|
91
|
+
expect(context.succeed).toBeDefined();
|
|
92
|
+
|
|
93
|
+
context.done();
|
|
94
|
+
context.fail(new Error('test'));
|
|
95
|
+
context.succeed('result');
|
|
96
|
+
|
|
97
|
+
expect(context.done).toHaveBeenCalled();
|
|
98
|
+
expect(context.fail).toHaveBeenCalled();
|
|
99
|
+
expect(context.succeed).toHaveBeenCalled();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should return remaining time', () => {
|
|
103
|
+
const context = createMockContext();
|
|
104
|
+
const remaining = context.getRemainingTimeInMillis();
|
|
105
|
+
|
|
106
|
+
expect(remaining).toBe(5000);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('createMockV1Event', () => {
|
|
111
|
+
it('should create a valid API Gateway V1 event', () => {
|
|
112
|
+
const event = createMockV1Event();
|
|
113
|
+
|
|
114
|
+
expect(event.httpMethod).toBe('GET');
|
|
115
|
+
expect(event.path).toBe('/test');
|
|
116
|
+
expect(event.headers['content-type']).toBe('application/json');
|
|
117
|
+
expect(event.requestContext.accountId).toBe('123456789012');
|
|
118
|
+
expect(event.requestContext.stage).toBe('test');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should allow overriding properties', () => {
|
|
122
|
+
const event = createMockV1Event({
|
|
123
|
+
httpMethod: 'POST',
|
|
124
|
+
path: '/users',
|
|
125
|
+
body: JSON.stringify({ name: 'test' }),
|
|
126
|
+
pathParameters: { id: '123' },
|
|
127
|
+
queryStringParameters: { page: '1' },
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
expect(event.httpMethod).toBe('POST');
|
|
131
|
+
expect(event.path).toBe('/users');
|
|
132
|
+
expect(event.body).toBe(JSON.stringify({ name: 'test' }));
|
|
133
|
+
expect(event.pathParameters).toEqual({ id: '123' });
|
|
134
|
+
expect(event.queryStringParameters).toEqual({ page: '1' });
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should have correct identity fields', () => {
|
|
138
|
+
const event = createMockV1Event();
|
|
139
|
+
|
|
140
|
+
expect(event.requestContext.identity.sourceIp).toBe('127.0.0.1');
|
|
141
|
+
expect(event.requestContext.identity.userAgent).toBe('test-agent');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('createMockV2Event', () => {
|
|
146
|
+
it('should create a valid API Gateway V2 event', () => {
|
|
147
|
+
const event = createMockV2Event();
|
|
148
|
+
|
|
149
|
+
expect(event.version).toBe('2.0');
|
|
150
|
+
expect(event.routeKey).toBe('GET /test');
|
|
151
|
+
expect(event.rawPath).toBe('/test');
|
|
152
|
+
expect(event.headers['content-type']).toBe('application/json');
|
|
153
|
+
expect(event.requestContext.accountId).toBe('123456789012');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('should allow overriding properties', () => {
|
|
157
|
+
const event = createMockV2Event({
|
|
158
|
+
routeKey: 'POST /users',
|
|
159
|
+
rawPath: '/users',
|
|
160
|
+
body: JSON.stringify({ name: 'test' }),
|
|
161
|
+
pathParameters: { id: '123' },
|
|
162
|
+
queryStringParameters: { page: '1' },
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
expect(event.routeKey).toBe('POST /users');
|
|
166
|
+
expect(event.rawPath).toBe('/users');
|
|
167
|
+
expect(event.body).toBe(JSON.stringify({ name: 'test' }));
|
|
168
|
+
expect(event.pathParameters).toEqual({ id: '123' });
|
|
169
|
+
expect(event.queryStringParameters).toEqual({ page: '1' });
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('should have correct HTTP context', () => {
|
|
173
|
+
const event = createMockV2Event();
|
|
174
|
+
|
|
175
|
+
expect(event.requestContext.http.method).toBe('GET');
|
|
176
|
+
expect(event.requestContext.http.path).toBe('/test');
|
|
177
|
+
expect(event.requestContext.http.sourceIp).toBe('127.0.0.1');
|
|
178
|
+
expect(event.requestContext.http.userAgent).toBe('test-agent');
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe('itWithDir', () => {
|
|
184
|
+
itWithDir('should provide a temporary directory', async ({ dir }) => {
|
|
185
|
+
expect(dir).toBeDefined();
|
|
186
|
+
expect(typeof dir).toBe('string');
|
|
187
|
+
|
|
188
|
+
// Directory should exist
|
|
189
|
+
const stat = await fs.stat(dir);
|
|
190
|
+
expect(stat.isDirectory()).toBe(true);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
itWithDir(
|
|
194
|
+
'should allow creating files in the directory',
|
|
195
|
+
async ({ dir }) => {
|
|
196
|
+
const testFile = path.join(dir, 'test.txt');
|
|
197
|
+
await fs.writeFile(testFile, 'hello');
|
|
198
|
+
|
|
199
|
+
const content = await fs.readFile(testFile, 'utf-8');
|
|
200
|
+
expect(content).toBe('hello');
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
itWithDir('should provide unique directories per test', async ({ dir }) => {
|
|
205
|
+
// The directory should have a UUID-like name (uppercase hex)
|
|
206
|
+
const dirName = path.basename(dir);
|
|
207
|
+
expect(dirName).toMatch(/^[A-F0-9]{32}$/);
|
|
208
|
+
expect(dir.length).toBeGreaterThan(10);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
});
|
package/src/aws.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
APIGatewayProxyEvent,
|
|
3
|
+
APIGatewayProxyEventV2,
|
|
4
|
+
Context,
|
|
5
5
|
} from 'aws-lambda';
|
|
6
6
|
import { vi } from 'vitest';
|
|
7
7
|
|
|
@@ -13,119 +13,119 @@ import { vi } from 'vitest';
|
|
|
13
13
|
* Creates a mock AWS Lambda Context for testing
|
|
14
14
|
*/
|
|
15
15
|
export function createMockContext(): Context {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
return {
|
|
17
|
+
awsRequestId: 'test-request-id',
|
|
18
|
+
callbackWaitsForEmptyEventLoop: false,
|
|
19
|
+
functionName: 'test-function',
|
|
20
|
+
functionVersion: '1',
|
|
21
|
+
invokedFunctionArn:
|
|
22
|
+
'arn:aws:lambda:us-east-1:123456789012:function:test-function',
|
|
23
|
+
memoryLimitInMB: '128',
|
|
24
|
+
logGroupName: '/aws/lambda/test-function',
|
|
25
|
+
logStreamName: '2024/01/01/[$LATEST]abcdef123456',
|
|
26
|
+
getRemainingTimeInMillis: () => 5000,
|
|
27
|
+
done: vi.fn(),
|
|
28
|
+
fail: vi.fn(),
|
|
29
|
+
succeed: vi.fn(),
|
|
30
|
+
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Creates a mock AWS API Gateway V1 (REST API) event for testing
|
|
35
35
|
*/
|
|
36
36
|
export function createMockV1Event(
|
|
37
|
-
|
|
37
|
+
overrides: Partial<APIGatewayProxyEvent> = {},
|
|
38
38
|
): APIGatewayProxyEvent {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
39
|
+
return {
|
|
40
|
+
body: null,
|
|
41
|
+
headers: {
|
|
42
|
+
'content-type': 'application/json',
|
|
43
|
+
'user-agent': 'test-agent',
|
|
44
|
+
host: 'test.example.com',
|
|
45
|
+
},
|
|
46
|
+
multiValueHeaders: {},
|
|
47
|
+
httpMethod: 'GET',
|
|
48
|
+
isBase64Encoded: false,
|
|
49
|
+
path: '/test',
|
|
50
|
+
pathParameters: null,
|
|
51
|
+
queryStringParameters: null,
|
|
52
|
+
multiValueQueryStringParameters: null,
|
|
53
|
+
stageVariables: null,
|
|
54
|
+
requestContext: {
|
|
55
|
+
accountId: '123456789012',
|
|
56
|
+
apiId: 'api-id',
|
|
57
|
+
authorizer: null,
|
|
58
|
+
protocol: 'HTTP/1.1',
|
|
59
|
+
httpMethod: 'GET',
|
|
60
|
+
path: '/test',
|
|
61
|
+
stage: 'test',
|
|
62
|
+
requestId: 'request-id',
|
|
63
|
+
requestTimeEpoch: 1704067200000,
|
|
64
|
+
resourceId: 'resource-id',
|
|
65
|
+
resourcePath: '/test',
|
|
66
|
+
identity: {
|
|
67
|
+
accessKey: null,
|
|
68
|
+
accountId: null,
|
|
69
|
+
apiKey: null,
|
|
70
|
+
apiKeyId: null,
|
|
71
|
+
caller: null,
|
|
72
|
+
cognitoAuthenticationProvider: null,
|
|
73
|
+
cognitoAuthenticationType: null,
|
|
74
|
+
cognitoIdentityId: null,
|
|
75
|
+
cognitoIdentityPoolId: null,
|
|
76
|
+
principalOrgId: null,
|
|
77
|
+
sourceIp: '127.0.0.1',
|
|
78
|
+
user: null,
|
|
79
|
+
userAgent: 'test-agent',
|
|
80
|
+
userArn: null,
|
|
81
|
+
clientCert: null,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
resource: '/test',
|
|
85
|
+
...overrides,
|
|
86
|
+
};
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* Creates a mock AWS API Gateway V2 (HTTP API) event for testing
|
|
91
91
|
*/
|
|
92
92
|
export function createMockV2Event(
|
|
93
|
-
|
|
93
|
+
overrides: Partial<APIGatewayProxyEventV2> = {},
|
|
94
94
|
): APIGatewayProxyEventV2 {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
95
|
+
return {
|
|
96
|
+
version: '2.0',
|
|
97
|
+
routeKey: 'GET /test',
|
|
98
|
+
rawPath: '/test',
|
|
99
|
+
rawQueryString: '',
|
|
100
|
+
headers: {
|
|
101
|
+
'content-type': 'application/json',
|
|
102
|
+
'user-agent': 'test-agent',
|
|
103
|
+
host: 'test.example.com',
|
|
104
|
+
},
|
|
105
|
+
requestContext: {
|
|
106
|
+
accountId: '123456789012',
|
|
107
|
+
apiId: 'api-id',
|
|
108
|
+
domainName: 'test.example.com',
|
|
109
|
+
domainPrefix: 'api',
|
|
110
|
+
requestId: 'request-id',
|
|
111
|
+
routeKey: 'GET /test',
|
|
112
|
+
stage: 'test',
|
|
113
|
+
time: '01/Jan/2024:00:00:00 +0000',
|
|
114
|
+
timeEpoch: 1704067200000,
|
|
115
|
+
http: {
|
|
116
|
+
method: 'GET',
|
|
117
|
+
path: '/test',
|
|
118
|
+
protocol: 'HTTP/1.1',
|
|
119
|
+
sourceIp: '127.0.0.1',
|
|
120
|
+
userAgent: 'test-agent',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
body: undefined,
|
|
124
|
+
pathParameters: undefined,
|
|
125
|
+
isBase64Encoded: false,
|
|
126
|
+
stageVariables: undefined,
|
|
127
|
+
queryStringParameters: undefined,
|
|
128
|
+
cookies: undefined,
|
|
129
|
+
...overrides,
|
|
130
|
+
};
|
|
131
131
|
}
|
package/src/benchmark.ts
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* @returns Array of test data objects
|
|
6
6
|
*/
|
|
7
7
|
export function generateTestData(
|
|
8
|
-
|
|
8
|
+
count: number,
|
|
9
9
|
): Array<{ id: string; name: string; value: number }> {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
return Array.from({ length: count }, (_, i) => ({
|
|
11
|
+
id: `id-${i}`,
|
|
12
|
+
name: `Item ${i}`,
|
|
13
|
+
value: Math.random() * 1000,
|
|
14
|
+
}));
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -22,7 +22,7 @@ export function generateTestData(
|
|
|
22
22
|
* @returns Array of unique cache keys
|
|
23
23
|
*/
|
|
24
24
|
export function generateCacheKeys(prefix: string, count: number): string[] {
|
|
25
|
-
|
|
25
|
+
return Array.from({ length: count }, (_, i) => `${prefix}:${i}`);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -33,16 +33,16 @@ export function generateCacheKeys(prefix: string, count: number): string[] {
|
|
|
33
33
|
* @returns Array of IP addresses
|
|
34
34
|
*/
|
|
35
35
|
export function generateIpAddresses(
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
count: number,
|
|
37
|
+
subnet: string = '192.168.1',
|
|
38
38
|
): string[] {
|
|
39
|
-
|
|
39
|
+
return Array.from({ length: count }, (_, i) => `${subnet}.${i % 256}`);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* Creates a random IP address for rate limit benchmarks.
|
|
44
44
|
*/
|
|
45
45
|
export function randomIpAddress(): string {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const octet = () => Math.floor(Math.random() * 256);
|
|
47
|
+
return `${octet()}.${octet()}.${octet()}.${octet()}`;
|
|
48
48
|
}
|