@miketako3/cloki 0.1.17 → 0.1.19
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/logger.test.js +34 -23
- package/dist/logger.test.js.map +1 -1
- package/package.json +40 -42
package/dist/logger.test.js
CHANGED
|
@@ -9,61 +9,72 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const vitest_1 = require("vitest");
|
|
12
13
|
const logger_1 = require("./logger"); // Adjust the import path as necessary
|
|
13
|
-
global.fetch =
|
|
14
|
+
global.fetch = vitest_1.vi.fn(() => Promise.resolve({
|
|
14
15
|
ok: true,
|
|
15
16
|
}));
|
|
16
|
-
Date.now =
|
|
17
|
-
describe("Loki Logger", () => {
|
|
17
|
+
Date.now = vitest_1.vi.fn(() => 1482363367071);
|
|
18
|
+
(0, vitest_1.describe)("Loki Logger", () => {
|
|
18
19
|
const mockConfig = {
|
|
19
20
|
lokiHost: "testhost",
|
|
20
21
|
lokiToken: "token123",
|
|
21
22
|
lokiUser: "user",
|
|
22
23
|
};
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
|
|
24
|
+
(0, vitest_1.beforeEach)(() => {
|
|
25
|
+
vitest_1.vi.clearAllMocks();
|
|
25
26
|
});
|
|
26
|
-
it("should create a logger with the correct methods", () => {
|
|
27
|
+
(0, vitest_1.it)("should create a logger with the correct methods", () => {
|
|
27
28
|
const logger = (0, logger_1.getLokiLogger)(mockConfig);
|
|
28
|
-
expect(logger).toHaveProperty("info");
|
|
29
|
-
expect(logger).toHaveProperty("warn");
|
|
30
|
-
expect(logger).toHaveProperty("error");
|
|
31
|
-
expect(logger).toHaveProperty("debug");
|
|
29
|
+
(0, vitest_1.expect)(logger).toHaveProperty("info");
|
|
30
|
+
(0, vitest_1.expect)(logger).toHaveProperty("warn");
|
|
31
|
+
(0, vitest_1.expect)(logger).toHaveProperty("error");
|
|
32
|
+
(0, vitest_1.expect)(logger).toHaveProperty("debug");
|
|
32
33
|
});
|
|
33
|
-
describe("Logging Methods", () => {
|
|
34
|
-
it.each([
|
|
34
|
+
(0, vitest_1.describe)("Logging Methods", () => {
|
|
35
|
+
vitest_1.it.each([
|
|
36
|
+
"info",
|
|
37
|
+
"warn",
|
|
38
|
+
"error",
|
|
39
|
+
"debug",
|
|
40
|
+
])("should call log for %s method", (method) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
41
|
const logger = (0, logger_1.getLokiLogger)(mockConfig);
|
|
36
42
|
const mockMessage = { test: "message" };
|
|
37
|
-
const consoleSpy =
|
|
43
|
+
const consoleSpy = vitest_1.vi.spyOn(console, "log").mockImplementation(() => { });
|
|
38
44
|
yield logger[method](mockMessage);
|
|
39
|
-
expect(consoleSpy).toHaveBeenCalledWith(JSON.stringify(mockMessage));
|
|
40
|
-
expect(fetch).toHaveBeenCalledTimes(1);
|
|
41
|
-
expect(fetch).toHaveBeenCalledWith("https://testhost/loki/api/v1/push", {
|
|
45
|
+
(0, vitest_1.expect)(consoleSpy).toHaveBeenCalledWith(JSON.stringify(mockMessage));
|
|
46
|
+
(0, vitest_1.expect)(fetch).toHaveBeenCalledTimes(1);
|
|
47
|
+
(0, vitest_1.expect)(fetch).toHaveBeenCalledWith("https://testhost/loki/api/v1/push", {
|
|
42
48
|
method: "POST",
|
|
43
49
|
headers: {
|
|
44
50
|
"Content-Type": "application/json",
|
|
45
51
|
Authorization: `Basic ${btoa("user:token123")}`,
|
|
46
52
|
},
|
|
47
|
-
body: `{
|
|
53
|
+
body: `{"streams":[{"stream":{"level":"${method}"},"values":[["1482363367071000000","{\\"test\\":\\"message\\"}"]]}]}`,
|
|
48
54
|
});
|
|
49
55
|
// Reset the spy
|
|
50
56
|
consoleSpy.mockRestore();
|
|
51
57
|
}));
|
|
52
|
-
it.each([
|
|
58
|
+
vitest_1.it.each([
|
|
59
|
+
"info",
|
|
60
|
+
"warn",
|
|
61
|
+
"error",
|
|
62
|
+
"debug",
|
|
63
|
+
])("should call log for %s method with some labels", (method) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
64
|
const logger = (0, logger_1.getLokiLogger)(mockConfig);
|
|
54
65
|
const mockMessage = { test: "message" };
|
|
55
66
|
const mockLabels = { hoge: "huga" };
|
|
56
|
-
const consoleSpy =
|
|
67
|
+
const consoleSpy = vitest_1.vi.spyOn(console, "log").mockImplementation(() => { });
|
|
57
68
|
yield logger[method](mockMessage, mockLabels);
|
|
58
|
-
expect(consoleSpy).toHaveBeenCalledWith(JSON.stringify(mockMessage));
|
|
59
|
-
expect(fetch).toHaveBeenCalledTimes(1);
|
|
60
|
-
expect(fetch).toHaveBeenCalledWith("https://testhost/loki/api/v1/push", {
|
|
69
|
+
(0, vitest_1.expect)(consoleSpy).toHaveBeenCalledWith(JSON.stringify(mockMessage));
|
|
70
|
+
(0, vitest_1.expect)(fetch).toHaveBeenCalledTimes(1);
|
|
71
|
+
(0, vitest_1.expect)(fetch).toHaveBeenCalledWith("https://testhost/loki/api/v1/push", {
|
|
61
72
|
method: "POST",
|
|
62
73
|
headers: {
|
|
63
74
|
"Content-Type": "application/json",
|
|
64
75
|
Authorization: `Basic ${btoa("user:token123")}`,
|
|
65
76
|
},
|
|
66
|
-
body: `{
|
|
77
|
+
body: `{"streams":[{"stream":{"level":"${method}","hoge":"huga"},"values":[["1482363367071000000","{\\"test\\":\\"message\\"}"]]}]}`,
|
|
67
78
|
});
|
|
68
79
|
// Reset the spy
|
|
69
80
|
consoleSpy.mockRestore();
|
package/dist/logger.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.test.js","sourceRoot":"","sources":["../src/logger.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,qCAAyC,CAAC,sCAAsC;AAEhF,MAAM,CAAC,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"logger.test.js","sourceRoot":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}
|
|
2
|
+
"name": "@miketako3/cloki",
|
|
3
|
+
"version": "0.1.19",
|
|
4
|
+
"description": "cloki is zero dependency and simple logger library for Loki and Cloudflare Workers.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"format": "bunx @biomejs/biome check . --write",
|
|
15
|
+
"lint": "bunx @biomejs/biome check .",
|
|
16
|
+
"test": "vitest run"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/miketako3/cloki.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"cloudflare",
|
|
24
|
+
"workers",
|
|
25
|
+
"loki",
|
|
26
|
+
"grafana",
|
|
27
|
+
"logger",
|
|
28
|
+
"logging"
|
|
29
|
+
],
|
|
30
|
+
"author": "miketako3 (Kaito Hiruta)",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/miketako3/cloki/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/miketako3/cloki#readme",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@biomejs/biome": "^2.3.10",
|
|
38
|
+
"@types/node": "^20.11.5",
|
|
39
|
+
"typescript": "^5.3.3",
|
|
40
|
+
"vitest": "^4.0.16"
|
|
41
|
+
}
|
|
44
42
|
}
|