@digitraffic/common 2026.2.23-1 → 2026.3.3-1
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/README.md +3 -8
- package/dist/__test__/asserter.js +1 -3
- package/dist/__test__/db-testutils.js +1 -0
- package/dist/__test__/dependencies.test.js +1 -1
- package/dist/__test__/imports.test.js +1 -1
- package/dist/__test__/infra/acl-builder.test.js +1 -1
- package/dist/__test__/infra/api/handler-factory.test.js +6 -6
- package/dist/__test__/infra/api/integration.test.js +1 -0
- package/dist/__test__/infra/api/response.test.js +1 -0
- package/dist/__test__/infra/api/static-integration.test.js +3 -2
- package/dist/__test__/infra/documentation.test.js +1 -0
- package/dist/__test__/infra/scheduler.test.js +1 -0
- package/dist/__test__/infra/security-rule.test.js +1 -0
- package/dist/__test__/infra/stack/rest-apis.test.js +1 -0
- package/dist/__test__/marine/id_utils.test.js +1 -0
- package/dist/__test__/promise/promise.test.js +17 -17
- package/dist/__test__/runtime/dt-logger.test.js +1 -0
- package/dist/__test__/secrets/secret-holder.test.js +4 -5
- package/dist/__test__/secrets/secret.test.js +7 -5
- package/dist/__test__/stack/dt-function.test.js +1 -0
- package/dist/__test__/stack/rest-apis.test.js +1 -0
- package/dist/__test__/test/mock-ky.test.js +13 -35
- package/dist/__test__/types/lambda-proxy-types.test.js +1 -0
- package/dist/__test__/types/lambda-response-builder.test.js +1 -0
- package/dist/__test__/types/lambda-response.test.js +1 -0
- package/dist/__test__/utils/base64.test.js +1 -0
- package/dist/__test__/utils/date-utils.test.js +1 -0
- package/dist/__test__/utils/geometry.test.js +1 -0
- package/dist/__test__/utils/lambda-proxy-event.test.js +1 -0
- package/dist/__test__/utils/logging.test.js +1 -0
- package/dist/__test__/utils/stop-watch.test.js +1 -1
- package/dist/__test__/utils/utils.test.js +1 -0
- package/package.json +21 -27
package/README.md
CHANGED
|
@@ -42,19 +42,14 @@ Format code
|
|
|
42
42
|
|
|
43
43
|
## Update deps
|
|
44
44
|
|
|
45
|
-
To update all dependencies to the latest versions
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
pnpm up
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
If you want to ignore the version ranges in package.json and install the
|
|
52
|
-
absolute latest versions:
|
|
45
|
+
This project uses exact dependency versions (no semver ranges). To update all dependencies to the latest versions:
|
|
53
46
|
|
|
54
47
|
```bash
|
|
55
48
|
pnpm up --latest
|
|
56
49
|
```
|
|
57
50
|
|
|
51
|
+
After updating, run `pnpm audit` to check for vulnerabilities. If vulnerabilities exist in transitive dependencies, you may need to add overrides in `package.json` and/or exclusions in `.npmrc`. See [DEPENDENCY_OVERRIDES.md](./DEPENDENCY_OVERRIDES.md) for details.
|
|
52
|
+
|
|
58
53
|
## How to use
|
|
59
54
|
|
|
60
55
|
In package.json dependencies:
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const madge = await import("madge");
|
|
2
|
+
import { expect, test } from "vitest";
|
|
2
3
|
const WHITELISTED_DEPENDENCIES = [
|
|
3
4
|
// aspect is using DigitrafficStack with instanceof, can't remove
|
|
4
5
|
`["aws/infra/stack/stack.mjs","aws/infra/stack/stack-checking-aspect.mjs"]`,
|
|
@@ -17,5 +18,4 @@ test("circular dependencies", async () => {
|
|
|
17
18
|
const errors = circulars.filter(whitelist);
|
|
18
19
|
assertNoErrors(errors);
|
|
19
20
|
});
|
|
20
|
-
export {};
|
|
21
21
|
//# sourceMappingURL=dependencies.test.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { HandlerFactory } from "../../../aws/infra/api/handler-factory.js";
|
|
3
3
|
import { DtLogger } from "../../../aws/runtime/dt-logger.js";
|
|
4
4
|
const logger = new DtLogger();
|
|
5
5
|
describe("handler-factory tests", () => {
|
|
6
6
|
test("test defaults", async () => {
|
|
7
7
|
const factory = new HandlerFactory();
|
|
8
|
-
const method =
|
|
8
|
+
const method = vi.fn((method) => {
|
|
9
9
|
return method;
|
|
10
10
|
});
|
|
11
11
|
const handler = factory.createEventHandler(method, logger);
|
|
@@ -13,11 +13,11 @@ describe("handler-factory tests", () => {
|
|
|
13
13
|
expect(method).toHaveBeenCalledTimes(1);
|
|
14
14
|
});
|
|
15
15
|
test("test logging", async () => {
|
|
16
|
-
const loggingHandler =
|
|
16
|
+
const loggingHandler = vi.fn((method) => {
|
|
17
17
|
return method();
|
|
18
18
|
});
|
|
19
19
|
const factory = new HandlerFactory().withLoggingHandler(loggingHandler);
|
|
20
|
-
const method =
|
|
20
|
+
const method = vi.fn((method) => {
|
|
21
21
|
return method;
|
|
22
22
|
});
|
|
23
23
|
const handler = factory.createEventHandler(method, logger);
|
|
@@ -26,11 +26,11 @@ describe("handler-factory tests", () => {
|
|
|
26
26
|
expect(loggingHandler).toHaveBeenCalledTimes(1);
|
|
27
27
|
});
|
|
28
28
|
test("test error handling", async () => {
|
|
29
|
-
const eh =
|
|
29
|
+
const eh = vi.fn((method) => {
|
|
30
30
|
return method;
|
|
31
31
|
});
|
|
32
32
|
const factory = new HandlerFactory().withErrorHandler(eh);
|
|
33
|
-
const method =
|
|
33
|
+
const method = vi.fn(() => {
|
|
34
34
|
throw new Error("MAGIC");
|
|
35
35
|
});
|
|
36
36
|
const handler = factory.createEventHandler(method, logger);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { App, Stack } from "aws-cdk-lib";
|
|
2
2
|
import { Code, Function as LambdaFunction, Runtime, } from "aws-cdk-lib/aws-lambda";
|
|
3
3
|
import velocity from "velocityjs";
|
|
4
|
+
import { describe, expect, test } from "vitest";
|
|
4
5
|
import { DigitrafficIntegration } from "../../../aws/infra/api/integration.js";
|
|
5
6
|
import { MediaType } from "../../../aws/types/mediatypes.js";
|
|
6
7
|
import { decodeBase64ToAscii } from "../../../utils/base64.js";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Model } from "aws-cdk-lib/aws-apigateway";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
2
3
|
import { DigitrafficStaticIntegration } from "../../../aws/infra/api/static-integration.js";
|
|
3
4
|
import { MediaType } from "../../../aws/types/mediatypes.js";
|
|
4
5
|
describe("response tests", () => {
|
|
5
|
-
|
|
6
|
+
test("createIntegrationResponse works", () => {
|
|
6
7
|
const integrationResponse = DigitrafficStaticIntegration.createIntegrationResponse("FakeResource", MediaType.APPLICATION_JSON, { "test-header": "test-value" });
|
|
7
8
|
expect(integrationResponse).toEqual({
|
|
8
9
|
responseParameters: {
|
|
@@ -14,7 +15,7 @@ describe("response tests", () => {
|
|
|
14
15
|
statusCode: "200",
|
|
15
16
|
});
|
|
16
17
|
});
|
|
17
|
-
|
|
18
|
+
test("createMethodResponse works", () => {
|
|
18
19
|
const methodResponse = DigitrafficStaticIntegration.createMethodResponse({
|
|
19
20
|
"test-header": "test-value",
|
|
20
21
|
}, MediaType.TEXT_PLAIN, Model.EMPTY_MODEL);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { App, Stack } from "aws-cdk-lib";
|
|
2
2
|
import { Template } from "aws-cdk-lib/assertions";
|
|
3
|
+
import { describe, test } from "vitest";
|
|
3
4
|
import { Scheduler } from "../../aws/infra/scheduler.js";
|
|
4
5
|
describe("scheduler tests", () => {
|
|
5
6
|
function expectRate(createScheduler, expectedRate) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { App, Stack } from "aws-cdk-lib";
|
|
2
2
|
import { Template } from "aws-cdk-lib/assertions";
|
|
3
3
|
import { Topic } from "aws-cdk-lib/aws-sns";
|
|
4
|
+
import { describe, test } from "vitest";
|
|
4
5
|
import { DigitrafficSecurityRule } from "../../aws/infra/security-rule.js";
|
|
5
6
|
describe("security-rule tests", () => {
|
|
6
7
|
test("create", () => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { App } from "aws-cdk-lib";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
2
3
|
import { DigitrafficRestApi } from "../../../aws/infra/stack/rest-api.js";
|
|
3
4
|
import { DigitrafficStack } from "../../../aws/infra/stack/stack.js";
|
|
4
5
|
describe("DigitrafficRestApi tests", () => {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { getRandomInteger } from "../../__test__/testutils.js";
|
|
3
3
|
import { logger } from "../../aws/runtime/dt-logger-default.js";
|
|
4
4
|
import { RetryLogError, retry } from "../../utils/retry.js";
|
|
5
|
-
|
|
5
|
+
vi.useFakeTimers();
|
|
6
6
|
describe("Promise utils tests", () => {
|
|
7
7
|
test("retry - no retries", async () => {
|
|
8
|
-
const fn =
|
|
8
|
+
const fn = vi.fn(() => Promise.resolve(1));
|
|
9
9
|
const ret = await retry(fn, 0, RetryLogError.NO_LOGGING);
|
|
10
10
|
expect(ret).toBe(1);
|
|
11
11
|
expect(fn.mock.calls.length).toBe(1);
|
|
12
12
|
});
|
|
13
13
|
test("retry - error with n+1 retries", async () => {
|
|
14
|
-
const fn =
|
|
14
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
15
15
|
const retries = getRandomInteger(1, 10);
|
|
16
16
|
try {
|
|
17
17
|
await retry(fn, retries, RetryLogError.NO_LOGGING);
|
|
@@ -24,15 +24,15 @@ describe("Promise utils tests", () => {
|
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
test("retry - no error with n+1 retries", async () => {
|
|
27
|
-
const fn =
|
|
27
|
+
const fn = vi.fn(() => Promise.resolve(1));
|
|
28
28
|
const retries = getRandomInteger(1, 10);
|
|
29
29
|
const ret = await retry(fn, retries, RetryLogError.NO_LOGGING);
|
|
30
30
|
expect(ret).toBe(1);
|
|
31
31
|
expect(fn.mock.calls.length).toBe(1);
|
|
32
32
|
});
|
|
33
33
|
test("retry - errors with no error logging", async () => {
|
|
34
|
-
const fn =
|
|
35
|
-
const consoleErrorSpy =
|
|
34
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
35
|
+
const consoleErrorSpy = vi.spyOn(logger, "error");
|
|
36
36
|
try {
|
|
37
37
|
await retry(fn, getRandomInteger(0, 10), RetryLogError.NO_LOGGING);
|
|
38
38
|
}
|
|
@@ -45,8 +45,8 @@ describe("Promise utils tests", () => {
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
test("retry - no retries with error logging", async () => {
|
|
48
|
-
const fn =
|
|
49
|
-
const consoleErrorSpy =
|
|
48
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
49
|
+
const consoleErrorSpy = vi.spyOn(logger, "error");
|
|
50
50
|
try {
|
|
51
51
|
await retry(fn, 0, RetryLogError.LOG_ALL_AS_ERRORS);
|
|
52
52
|
}
|
|
@@ -59,9 +59,9 @@ describe("Promise utils tests", () => {
|
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
test("retry - retries with error logging", async () => {
|
|
62
|
-
const fn =
|
|
62
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
63
63
|
const retries = getRandomInteger(1, 10);
|
|
64
|
-
const consoleErrorSpy =
|
|
64
|
+
const consoleErrorSpy = vi.spyOn(logger, "error");
|
|
65
65
|
try {
|
|
66
66
|
await retry(fn, retries, RetryLogError.LOG_ALL_AS_ERRORS);
|
|
67
67
|
}
|
|
@@ -74,12 +74,12 @@ describe("Promise utils tests", () => {
|
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
test("retry - exceeded retry count throws error", async () => {
|
|
77
|
-
const fn =
|
|
77
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
78
78
|
await expect(() => retry(fn, 3, RetryLogError.LOG_ALL_AS_ERRORS)).rejects.toThrow();
|
|
79
79
|
});
|
|
80
80
|
test("retry - defaults", async () => {
|
|
81
|
-
const fn =
|
|
82
|
-
const consoleErrorSpy =
|
|
81
|
+
const fn = vi.fn(() => Promise.reject("error"));
|
|
82
|
+
const consoleErrorSpy = vi.spyOn(logger, "error");
|
|
83
83
|
try {
|
|
84
84
|
await retry(fn);
|
|
85
85
|
}
|
|
@@ -92,15 +92,15 @@ describe("Promise utils tests", () => {
|
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
94
|
test("retry - NaN throws error", async () => {
|
|
95
|
-
const fn =
|
|
95
|
+
const fn = vi.fn(() => Promise.resolve(NaN));
|
|
96
96
|
await expect(() => retry(fn, NaN, RetryLogError.NO_LOGGING)).rejects.toThrow();
|
|
97
97
|
});
|
|
98
98
|
test("retry - Infinity throws error", async () => {
|
|
99
|
-
const fn =
|
|
99
|
+
const fn = vi.fn(() => Promise.resolve(NaN));
|
|
100
100
|
await expect(() => retry(fn, Infinity, RetryLogError.NO_LOGGING)).rejects.toThrow();
|
|
101
101
|
});
|
|
102
102
|
test("retry - exceeded maximum retry count throws error", async () => {
|
|
103
|
-
const fn =
|
|
103
|
+
const fn = vi.fn(() => Promise.resolve(NaN));
|
|
104
104
|
await expect(() => retry(fn, getRandomInteger(101, 1000000), RetryLogError.NO_LOGGING)).rejects.toThrow();
|
|
105
105
|
});
|
|
106
106
|
test("retry - use without mocks without retry", async () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SecretsManager } from "@aws-sdk/client-secrets-manager";
|
|
2
|
-
import {
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
3
3
|
import { setEnvVariable, setEnvVariableAwsRegion } from "../../utils/utils.js";
|
|
4
4
|
const SECRET_WITH_PREFIX = {
|
|
5
5
|
"prefix.value": "value",
|
|
@@ -8,10 +8,8 @@ const SECRET_WITH_PREFIX = {
|
|
|
8
8
|
username: "DB_USER",
|
|
9
9
|
};
|
|
10
10
|
const emptySecret = { $metadata: {} };
|
|
11
|
-
const getSecretValueMock =
|
|
12
|
-
|
|
13
|
-
.spyOn(SecretsManager.prototype, "getSecretValue")
|
|
14
|
-
.mockImplementation(getSecretValueMock);
|
|
11
|
+
const getSecretValueMock = vi.fn();
|
|
12
|
+
vi.spyOn(SecretsManager.prototype, "getSecretValue").mockImplementation(getSecretValueMock);
|
|
15
13
|
const { SecretHolder } = await import("../../aws/runtime/secrets/secret-holder.js");
|
|
16
14
|
const { DatabaseEnvironmentKeys } = await import("../../database/database.js");
|
|
17
15
|
function mockSecret(secret) {
|
|
@@ -32,6 +30,7 @@ describe("SecretHolder - tests", () => {
|
|
|
32
30
|
});
|
|
33
31
|
afterEach(() => {
|
|
34
32
|
delete process.env[DatabaseEnvironmentKeys.DB_USER];
|
|
33
|
+
//vi.restoreAllMocks()
|
|
35
34
|
});
|
|
36
35
|
test("get - no secret", () => {
|
|
37
36
|
mockSecret(null);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { afterEach } from "node:test";
|
|
1
2
|
import { SecretsManager } from "@aws-sdk/client-secrets-manager";
|
|
2
|
-
import {
|
|
3
|
+
import { describe, expect, test, vi } from "vitest";
|
|
3
4
|
import { setEnvVariableAwsRegion } from "../../utils/utils.js";
|
|
4
5
|
const SECRET_ID = "test_secret";
|
|
5
6
|
const SECRET_WITH_PREFIX = {
|
|
@@ -8,10 +9,8 @@ const SECRET_WITH_PREFIX = {
|
|
|
8
9
|
"wrong.value": "value",
|
|
9
10
|
};
|
|
10
11
|
const emptySecret = { $metadata: {} };
|
|
11
|
-
const getSecretValueMock =
|
|
12
|
-
|
|
13
|
-
.spyOn(SecretsManager.prototype, "getSecretValue")
|
|
14
|
-
.mockImplementation(getSecretValueMock);
|
|
12
|
+
const getSecretValueMock = vi.fn();
|
|
13
|
+
vi.spyOn(SecretsManager.prototype, "getSecretValue").mockImplementation(getSecretValueMock);
|
|
15
14
|
function mockSecret(secret) {
|
|
16
15
|
if (!secret) {
|
|
17
16
|
getSecretValueMock.mockImplementation(() => Promise.resolve(emptySecret));
|
|
@@ -27,6 +26,9 @@ setEnvVariableAwsRegion("eu-west-1");
|
|
|
27
26
|
const secret = await import("../../aws/runtime/secrets/secret.js");
|
|
28
27
|
const { getSecret } = secret;
|
|
29
28
|
describe("secret - test", () => {
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
vi.restoreAllMocks();
|
|
31
|
+
});
|
|
30
32
|
test("getSecret - no secret", async () => {
|
|
31
33
|
mockSecret(null);
|
|
32
34
|
await expect(async () => {
|
|
@@ -2,6 +2,7 @@ import { App, Duration } from "aws-cdk-lib";
|
|
|
2
2
|
import { Match, Template } from "aws-cdk-lib/assertions";
|
|
3
3
|
import { PolicyStatement, Role, ServicePrincipal } from "aws-cdk-lib/aws-iam";
|
|
4
4
|
import { Architecture, Code, Runtime } from "aws-cdk-lib/aws-lambda";
|
|
5
|
+
import { describe, expect, test } from "vitest";
|
|
5
6
|
import { FunctionBuilder } from "../../aws/infra/stack/dt-function.js";
|
|
6
7
|
import { DigitrafficStack } from "../../aws/infra/stack/stack.js";
|
|
7
8
|
import { EnvKeys } from "../../aws/runtime/environment.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { App } from "aws-cdk-lib";
|
|
2
2
|
import { Match, Template } from "aws-cdk-lib/assertions";
|
|
3
|
+
import { describe, test } from "vitest";
|
|
3
4
|
import { DigitrafficRestApi } from "../../aws/infra/stack/rest-api.js";
|
|
4
5
|
import { DigitrafficStack } from "../../aws/infra/stack/stack.js";
|
|
5
6
|
import { TrafficType } from "../../types/traffictype.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe,
|
|
1
|
+
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { mockKyResponse } from "../../__test__/mock-ky.js";
|
|
3
3
|
const ky = (await import("ky")).default;
|
|
4
4
|
describe("mockKyResponse", () => {
|
|
@@ -6,61 +6,39 @@ describe("mockKyResponse", () => {
|
|
|
6
6
|
const testJson = JSON.stringify(testObj);
|
|
7
7
|
const url = "https://example.com";
|
|
8
8
|
afterEach(() => {
|
|
9
|
-
|
|
9
|
+
vi.restoreAllMocks();
|
|
10
10
|
});
|
|
11
11
|
test("works with all methods", async () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
.spyOn(ky, "post")
|
|
17
|
-
.mockImplementation(() => mockKyResponse(200, testJson));
|
|
18
|
-
jest
|
|
19
|
-
.spyOn(ky, "put")
|
|
20
|
-
.mockImplementation(() => mockKyResponse(200, testJson));
|
|
21
|
-
jest
|
|
22
|
-
.spyOn(ky, "delete")
|
|
23
|
-
.mockImplementation(() => mockKyResponse(200, testJson));
|
|
12
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
|
|
13
|
+
vi.spyOn(ky, "post").mockImplementation(() => mockKyResponse(200, testJson));
|
|
14
|
+
vi.spyOn(ky, "put").mockImplementation(() => mockKyResponse(200, testJson));
|
|
15
|
+
vi.spyOn(ky, "delete").mockImplementation(() => mockKyResponse(200, testJson));
|
|
24
16
|
expect(await ky.get(url).text()).toEqual(testJson);
|
|
25
17
|
expect(await ky.put(url).text()).toEqual(testJson);
|
|
26
18
|
expect(await ky.post(url).text()).toEqual(testJson);
|
|
27
19
|
expect(await ky.delete(url).text()).toEqual(testJson);
|
|
28
20
|
});
|
|
29
21
|
test("returns correct status", async () => {
|
|
30
|
-
|
|
31
|
-
.spyOn(ky, "get")
|
|
32
|
-
.mockImplementation(() => mockKyResponse(200, testJson));
|
|
22
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
|
|
33
23
|
expect((await ky.get(url)).status).toEqual(200);
|
|
34
|
-
|
|
35
|
-
.spyOn(ky, "get")
|
|
36
|
-
.mockImplementation(() => mockKyResponse(400, testJson));
|
|
24
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(400, testJson));
|
|
37
25
|
expect((await ky.get(url)).status).toEqual(400);
|
|
38
26
|
});
|
|
39
27
|
test("returns correct ok", async () => {
|
|
40
|
-
|
|
41
|
-
.spyOn(ky, "get")
|
|
42
|
-
.mockImplementation(() => mockKyResponse(200, testJson));
|
|
28
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
|
|
43
29
|
expect((await ky.get(url)).ok).toEqual(true);
|
|
44
|
-
|
|
45
|
-
.spyOn(ky, "get")
|
|
46
|
-
.mockImplementation(() => mockKyResponse(299, testJson));
|
|
30
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(299, testJson));
|
|
47
31
|
expect((await ky.get(url)).ok).toEqual(true);
|
|
48
|
-
|
|
49
|
-
.spyOn(ky, "get")
|
|
50
|
-
.mockImplementation(() => mockKyResponse(300, testJson));
|
|
32
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(300, testJson));
|
|
51
33
|
expect((await ky.get(url)).ok).toEqual(false);
|
|
52
34
|
});
|
|
53
35
|
test("convenience methods work: text", async () => {
|
|
54
|
-
|
|
55
|
-
.spyOn(ky, "get")
|
|
56
|
-
.mockImplementation(() => mockKyResponse(200, testJson));
|
|
36
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
|
|
57
37
|
expect(await ky.get(url).text()).toEqual(testJson);
|
|
58
38
|
expect(await (await ky.get(url)).text()).toEqual(testJson);
|
|
59
39
|
});
|
|
60
40
|
test("convenience methods work: json", async () => {
|
|
61
|
-
|
|
62
|
-
.spyOn(ky, "get")
|
|
63
|
-
.mockImplementation(() => mockKyResponse(200, testJson));
|
|
41
|
+
vi.spyOn(ky, "get").mockImplementation(() => mockKyResponse(200, testJson));
|
|
64
42
|
expect(await ky.get(url).json()).toEqual(testObj);
|
|
65
43
|
expect(await (await ky.get(url)).json()).toEqual(testObj);
|
|
66
44
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
1
2
|
import { LambdaResponseBuilder } from "../../aws/types/lambda-response.js";
|
|
2
3
|
import { decodeBase64ToUtf8 } from "../../utils/base64.js";
|
|
3
4
|
import { TEST_FILENAME, TEST_JSON, TEST_MESSAGE, TEST_TIMESTAMP, TEST_TIMESTAMP_STR, } from "./lambda-response.test.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
1
2
|
import { compressBuffer, decodeBase64ToAscii, decodeBase64ToUtf8, encodeAsciiToBase64, encodeUtf8ToBase64, } from "../../utils/base64.js";
|
|
2
3
|
describe("Base64UtilTest", () => {
|
|
3
4
|
const EXPECTED_ASCII = "0a9f4967-faaa-445a-ba11-078f7f9556b4";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Writable } from "node:stream";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
2
3
|
import { DtLogger } from "../../aws/runtime/dt-logger.js";
|
|
3
4
|
import { logException, truncateEnd, truncateMiddle, } from "../../utils/logging.js";
|
|
4
5
|
const TEST_METHODNAME = "test.logException";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitraffic/common",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.3.3-1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"repository": {
|
|
@@ -113,51 +113,47 @@
|
|
|
113
113
|
"@aws-sdk/client-secrets-manager": "3.995.0",
|
|
114
114
|
"@aws-sdk/client-sns": "3.995.0",
|
|
115
115
|
"@aws-sdk/lib-storage": "3.995.0",
|
|
116
|
-
"@biomejs/biome": "2.
|
|
116
|
+
"@biomejs/biome": "2.4.4",
|
|
117
117
|
"@date-fns/tz": "1.4.1",
|
|
118
|
-
"@
|
|
119
|
-
"@rushstack/heft": "1.
|
|
120
|
-
"@rushstack/heft-jest-plugin": "1.1.10",
|
|
121
|
-
"@rushstack/heft-typescript-plugin": "1.1.10",
|
|
118
|
+
"@rushstack/heft": "1.2.3",
|
|
119
|
+
"@rushstack/heft-typescript-plugin": "1.2.3",
|
|
122
120
|
"@smithy/fetch-http-handler": "5.3.9",
|
|
123
121
|
"@smithy/types": "4.12.0",
|
|
124
122
|
"@types/aws-lambda": "8.10.160",
|
|
125
123
|
"@types/etag": "1.8.4",
|
|
126
124
|
"@types/geojson": "7946.0.16",
|
|
127
125
|
"@types/geojson-validation": "1.0.3",
|
|
128
|
-
"@types/jest": "30.0.0",
|
|
129
126
|
"@types/lodash-es": "4.17.12",
|
|
130
127
|
"@types/madge": "5.0.3",
|
|
131
|
-
"@types/node": "25.0
|
|
132
|
-
"
|
|
128
|
+
"@types/node": "25.3.0",
|
|
129
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
130
|
+
"aws-cdk-lib": "2.239.0",
|
|
133
131
|
"change-case": "5.4.4",
|
|
134
|
-
"constructs": "10.
|
|
132
|
+
"constructs": "10.5.1",
|
|
135
133
|
"date-fns": "4.1.0",
|
|
136
134
|
"es-toolkit": "1.44.0",
|
|
137
135
|
"etag": "1.8.1",
|
|
138
136
|
"geojson-validation": "1.0.2",
|
|
139
|
-
"jest": "30.2.0",
|
|
140
|
-
"jest-junit": "16.0.0",
|
|
141
137
|
"ky": "1.14.3",
|
|
142
|
-
"lefthook": "2.
|
|
138
|
+
"lefthook": "2.1.1",
|
|
143
139
|
"lodash-es": "4.17.23",
|
|
144
140
|
"madge": "8.0.0",
|
|
145
141
|
"pg-native": "3.5.2",
|
|
146
|
-
"pg-promise": "12.
|
|
147
|
-
"pg-query-stream": "4.
|
|
148
|
-
"rimraf": "6.1.
|
|
142
|
+
"pg-promise": "12.6.1",
|
|
143
|
+
"pg-query-stream": "4.12.0",
|
|
144
|
+
"rimraf": "6.1.3",
|
|
149
145
|
"sort-package-json": "3.6.1",
|
|
150
|
-
"ts-jest": "29.4.6",
|
|
151
146
|
"typescript": "5.9.3",
|
|
152
147
|
"velocityjs": "2.1.5",
|
|
148
|
+
"vitest": "4.0.18",
|
|
153
149
|
"zod": "4.3.6"
|
|
154
150
|
},
|
|
155
151
|
"peerDependencies": {
|
|
156
|
-
"@aws-sdk/client-api-gateway": "3.
|
|
157
|
-
"@aws-sdk/client-s3": "3.
|
|
158
|
-
"@aws-sdk/client-secrets-manager": "3.
|
|
159
|
-
"@aws-sdk/client-sns": "3.
|
|
160
|
-
"@aws-sdk/lib-storage": "3.
|
|
152
|
+
"@aws-sdk/client-api-gateway": "3.975.0",
|
|
153
|
+
"@aws-sdk/client-s3": "3.975.0",
|
|
154
|
+
"@aws-sdk/client-secrets-manager": "3.975.0",
|
|
155
|
+
"@aws-sdk/client-sns": "3.975.0",
|
|
156
|
+
"@aws-sdk/lib-storage": "3.975.0",
|
|
161
157
|
"@date-fns/tz": "1.4.1",
|
|
162
158
|
"@smithy/fetch-http-handler": "5.3.9",
|
|
163
159
|
"@smithy/node-http-handler": "4.4.8",
|
|
@@ -179,16 +175,14 @@
|
|
|
179
175
|
"scripts": {
|
|
180
176
|
"build": "heft build --clean",
|
|
181
177
|
"build:watch": "heft build-watch",
|
|
178
|
+
"ci:test": "vitest run --coverage --reporter=junit --outputFile=junit.xml",
|
|
182
179
|
"format:check": "biome check ",
|
|
183
180
|
"format:check-staged": "biome check --staged",
|
|
184
181
|
"format:fix": "biome check --write",
|
|
185
182
|
"format:fix-staged": "biome check --staged --write",
|
|
186
183
|
"format:package-json": "sort-package-json",
|
|
187
184
|
"setup": "pnpm install; node --experimental-strip-types scripts/setup-digitraffic-common.ts",
|
|
188
|
-
"test": "
|
|
189
|
-
"test:
|
|
190
|
-
"test:jest": "node --trace-warnings --experimental-vm-modules --max-old-space-size=1536 --expose-gc ./node_modules/jest/bin/jest.js --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest --logHeapUsage --runInBand --verbose",
|
|
191
|
-
"test:watch": "NODE_OPTIONS='--experimental-vm-modules' heft test-watch --max-workers=1",
|
|
192
|
-
"test:watch:no-coverage": "NODE_OPTIONS='--experimental-vm-modules' heft test-watch --disable-code-coverage --max-workers=1"
|
|
185
|
+
"test": "vitest run --coverage",
|
|
186
|
+
"test:watch": "vitest"
|
|
193
187
|
}
|
|
194
188
|
}
|