dialekt 0.1.0 → 0.1.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 +8 -10
- package/TESTING.md +29 -29
- package/dist/cli/main.d.mts +1 -1
- package/dist/cli/main.mjs +549 -362
- package/dist/formatters-De4Q-X1d.mjs +516 -435
- package/dist/index.d.mts +162 -25
- package/dist/index.mjs +119 -34
- package/package.json +3 -3
- package/pnpm-workspace.yaml +3 -3
- package/src/adapter/types.test.ts +57 -57
- package/src/adapter/types.ts +7 -4
- package/src/benchmark/metrics.test.ts +141 -69
- package/src/benchmark/metrics.ts +6 -6
- package/src/benchmark/report.test.ts +38 -38
- package/src/benchmark/report.ts +6 -6
- package/src/benchmark/runner.test.ts +70 -72
- package/src/benchmark/runner.ts +4 -4
- package/src/cli/commands/add.test.ts +90 -109
- package/src/cli/commands/add.ts +40 -28
- package/src/cli/commands/benchmark.test.ts +77 -64
- package/src/cli/commands/benchmark.ts +64 -41
- package/src/cli/commands/languages.test.ts +45 -42
- package/src/cli/commands/languages.ts +16 -12
- package/src/cli/commands/missing.test.ts +143 -92
- package/src/cli/commands/missing.ts +24 -17
- package/src/cli/commands/translate.test.ts +79 -79
- package/src/cli/commands/translate.ts +41 -31
- package/src/cli/commands/unused.test.ts +62 -51
- package/src/cli/commands/unused.ts +18 -14
- package/src/cli/commands/validate.test.ts +130 -72
- package/src/cli/commands/validate.ts +25 -20
- package/src/cli/config-resolution.test.ts +169 -49
- package/src/cli/config-resolution.ts +5 -7
- package/src/cli/format.test.ts +50 -50
- package/src/cli/format.ts +57 -60
- package/src/cli/formatters.test.ts +128 -106
- package/src/cli/formatters.ts +72 -95
- package/src/cli/main.ts +13 -13
- package/src/config/define-config.test.ts +44 -29
- package/src/config/define-config.ts +1 -1
- package/src/config/load-config.test.ts +21 -18
- package/src/config/load-config.ts +5 -5
- package/src/config/types.test.ts +50 -44
- package/src/config/types.ts +2 -2
- package/src/index.ts +22 -26
- package/src/keys/flatten.test.ts +52 -52
- package/src/keys/flatten.ts +7 -9
- package/src/sdk/file-io.test.ts +47 -59
- package/src/sdk/file-io.ts +2 -2
- package/src/sdk/node-layer.test.ts +18 -18
- package/src/sdk/node-layer.ts +2 -2
- package/src/sdk/php-array-reader.test.ts +49 -40
- package/src/sdk/php-array-reader.ts +5 -5
- package/src/translation/chunking.test.ts +52 -44
- package/src/translation/chunking.ts +1 -1
- package/src/translation/missing-keys.test.ts +86 -93
- package/src/translation/missing-keys.ts +4 -6
- package/src/translation/model-registry.test.ts +41 -32
- package/src/translation/model-registry.ts +9 -9
- package/src/translation/one-shot-strategy.test.ts +105 -86
- package/src/translation/one-shot-strategy.ts +10 -12
- package/src/translation/orchestrator.test.ts +90 -101
- package/src/translation/orchestrator.ts +26 -26
- package/src/translation/prompt.test.ts +76 -76
- package/src/translation/prompt.ts +2 -2
- package/src/translation/tool-loop-strategy.test.ts +134 -107
- package/src/translation/tool-loop-strategy.ts +14 -18
- package/src/translation/types.test.ts +22 -22
- package/src/translation/types.ts +3 -3
- package/tsdown.config.ts +3 -3
- package/vitest.config.ts +3 -3
package/src/cli/format.ts
CHANGED
|
@@ -12,21 +12,21 @@
|
|
|
12
12
|
|
|
13
13
|
// ─── Output format ──────────────────────────────────────────────────────────
|
|
14
14
|
|
|
15
|
-
export type OutputFormat =
|
|
15
|
+
export type OutputFormat = "pretty" | "json";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Environment variables that signal dialekt is running inside an AI agent.
|
|
19
19
|
* When any is set (truthy), or stdout is not a TTY, JSON mode is the default.
|
|
20
20
|
*/
|
|
21
21
|
export const AGENT_ENV_VARS = [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
"CLAUDE_CODE",
|
|
23
|
+
"CLAUDECODE",
|
|
24
|
+
"CURSOR",
|
|
25
|
+
"CURSOR_TRACE_ID",
|
|
26
|
+
"DEVIN",
|
|
27
|
+
"GEMINI_CLI",
|
|
28
|
+
"AGENT_TASK_ID",
|
|
29
|
+
"AIDER_CHAT",
|
|
30
30
|
] as const;
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -38,23 +38,23 @@ export const AGENT_ENV_VARS = [
|
|
|
38
38
|
*/
|
|
39
39
|
export function detectFormat(explicit?: OutputFormat | undefined): OutputFormat {
|
|
40
40
|
if (explicit !== undefined) return explicit;
|
|
41
|
-
if (!process.stdout.isTTY) return
|
|
42
|
-
if (AGENT_ENV_VARS.some((k) => process.env[k])) return
|
|
43
|
-
return
|
|
41
|
+
if (!process.stdout.isTTY) return "json";
|
|
42
|
+
if (AGENT_ENV_VARS.some((k) => process.env[k])) return "json";
|
|
43
|
+
return "pretty";
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// ─── ANSI colours ────────────────────────────────────────────────────────────
|
|
47
47
|
|
|
48
48
|
const C = {
|
|
49
|
-
reset:
|
|
50
|
-
bold:
|
|
51
|
-
dim:
|
|
52
|
-
red:
|
|
53
|
-
green:
|
|
54
|
-
yellow:
|
|
55
|
-
blue:
|
|
56
|
-
cyan:
|
|
57
|
-
white:
|
|
49
|
+
reset: "\x1b[0m",
|
|
50
|
+
bold: "\x1b[1m",
|
|
51
|
+
dim: "\x1b[2m",
|
|
52
|
+
red: "\x1b[31m",
|
|
53
|
+
green: "\x1b[32m",
|
|
54
|
+
yellow: "\x1b[33m",
|
|
55
|
+
blue: "\x1b[34m",
|
|
56
|
+
cyan: "\x1b[36m",
|
|
57
|
+
white: "\x1b[37m",
|
|
58
58
|
} as const;
|
|
59
59
|
|
|
60
60
|
function isTty(): boolean {
|
|
@@ -64,7 +64,7 @@ function isTty(): boolean {
|
|
|
64
64
|
/** Wraps text in ANSI codes only when stdout is a TTY; otherwise returns it bare. */
|
|
65
65
|
export function color(text: string, ...codes: string[]): string {
|
|
66
66
|
if (!isTty()) return text;
|
|
67
|
-
return `${codes.join(
|
|
67
|
+
return `${codes.join("")}${text}${C.reset}`;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
// ─── Box-drawing glyphs ──────────────────────────────────────────────────────
|
|
@@ -91,39 +91,39 @@ interface Glyphs {
|
|
|
91
91
|
const PRETTY_GLYPHS: Glyphs = {
|
|
92
92
|
hLine: String.fromCharCode(0x2500),
|
|
93
93
|
vLine: String.fromCharCode(0x2502),
|
|
94
|
-
cornerTL: String.fromCharCode(
|
|
94
|
+
cornerTL: String.fromCharCode(0x250c),
|
|
95
95
|
cornerTR: String.fromCharCode(0x2510),
|
|
96
96
|
cornerBL: String.fromCharCode(0x2514),
|
|
97
97
|
cornerBR: String.fromCharCode(0x2518),
|
|
98
|
-
teeRight: String.fromCharCode(
|
|
98
|
+
teeRight: String.fromCharCode(0x251c),
|
|
99
99
|
teeLeft: String.fromCharCode(0x2524),
|
|
100
|
-
teeDown: String.fromCharCode(
|
|
100
|
+
teeDown: String.fromCharCode(0x252c),
|
|
101
101
|
teeUp: String.fromCharCode(0x2534),
|
|
102
|
-
cross: String.fromCharCode(
|
|
102
|
+
cross: String.fromCharCode(0x253c),
|
|
103
103
|
bullet: String.fromCharCode(0x2022),
|
|
104
104
|
arrow: String.fromCharCode(0x2192),
|
|
105
105
|
check: String.fromCharCode(0x2713),
|
|
106
106
|
crossMark: String.fromCharCode(0x2717),
|
|
107
|
-
warn: String.fromCharCode(
|
|
107
|
+
warn: String.fromCharCode(0x26a0),
|
|
108
108
|
};
|
|
109
109
|
|
|
110
110
|
const ASCII_GLYPHS: Glyphs = {
|
|
111
|
-
hLine:
|
|
112
|
-
vLine:
|
|
113
|
-
cornerTL:
|
|
114
|
-
cornerTR:
|
|
115
|
-
cornerBL:
|
|
116
|
-
cornerBR:
|
|
117
|
-
teeRight:
|
|
118
|
-
teeLeft:
|
|
119
|
-
teeDown:
|
|
120
|
-
teeUp:
|
|
121
|
-
cross:
|
|
122
|
-
bullet:
|
|
123
|
-
arrow:
|
|
124
|
-
check:
|
|
125
|
-
crossMark:
|
|
126
|
-
warn:
|
|
111
|
+
hLine: "-",
|
|
112
|
+
vLine: "|",
|
|
113
|
+
cornerTL: "+",
|
|
114
|
+
cornerTR: "+",
|
|
115
|
+
cornerBL: "+",
|
|
116
|
+
cornerBR: "+",
|
|
117
|
+
teeRight: "+",
|
|
118
|
+
teeLeft: "+",
|
|
119
|
+
teeDown: "+",
|
|
120
|
+
teeUp: "+",
|
|
121
|
+
cross: "+",
|
|
122
|
+
bullet: "*",
|
|
123
|
+
arrow: ">",
|
|
124
|
+
check: "+",
|
|
125
|
+
crossMark: "x",
|
|
126
|
+
warn: "!",
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
export function glyphs(): Glyphs {
|
|
@@ -134,38 +134,35 @@ export function glyphs(): Glyphs {
|
|
|
134
134
|
|
|
135
135
|
export function drawTable(
|
|
136
136
|
headers: readonly string[],
|
|
137
|
-
rows: readonly (readonly string[])[]
|
|
137
|
+
rows: readonly (readonly string[])[],
|
|
138
138
|
): string {
|
|
139
139
|
const g = glyphs();
|
|
140
140
|
const colWidths = headers.map((h, i) =>
|
|
141
|
-
Math.max(h.length, ...rows.map((r) => (r[i] ??
|
|
141
|
+
Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length)),
|
|
142
142
|
);
|
|
143
143
|
|
|
144
144
|
const pad = (text: string, width: number) => text.padEnd(width);
|
|
145
145
|
|
|
146
|
-
const hLine =
|
|
147
|
-
colWidths.map((w) => g.hLine.repeat(w + 2)).join(g.teeDown) +
|
|
148
|
-
g.cornerTR;
|
|
146
|
+
const hLine =
|
|
147
|
+
g.cornerTL + colWidths.map((w) => g.hLine.repeat(w + 2)).join(g.teeDown) + g.cornerTR;
|
|
149
148
|
|
|
150
|
-
const headerRow =
|
|
149
|
+
const headerRow =
|
|
150
|
+
g.vLine +
|
|
151
151
|
headers.map((h, i) => ` ${color(pad(h, colWidths[i]!), C.bold)} `).join(g.vLine) +
|
|
152
152
|
g.vLine;
|
|
153
153
|
|
|
154
|
-
const separator =
|
|
155
|
-
colWidths.map((w) => g.hLine.repeat(w + 2)).join(g.cross) +
|
|
156
|
-
g.teeLeft;
|
|
154
|
+
const separator =
|
|
155
|
+
g.teeRight + colWidths.map((w) => g.hLine.repeat(w + 2)).join(g.cross) + g.teeLeft;
|
|
157
156
|
|
|
158
|
-
const dataRows = rows.map(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
g.vLine
|
|
157
|
+
const dataRows = rows.map(
|
|
158
|
+
(row) =>
|
|
159
|
+
g.vLine + row.map((cell, i) => ` ${pad(cell, colWidths[i]!)} `).join(g.vLine) + g.vLine,
|
|
162
160
|
);
|
|
163
161
|
|
|
164
|
-
const bottomLine =
|
|
165
|
-
colWidths.map((w) => g.hLine.repeat(w + 2)).join(g.teeUp) +
|
|
166
|
-
g.cornerBR;
|
|
162
|
+
const bottomLine =
|
|
163
|
+
g.cornerBL + colWidths.map((w) => g.hLine.repeat(w + 2)).join(g.teeUp) + g.cornerBR;
|
|
167
164
|
|
|
168
|
-
return [hLine, headerRow, separator, ...dataRows, bottomLine].join(
|
|
165
|
+
return [hLine, headerRow, separator, ...dataRows, bottomLine].join("\n");
|
|
169
166
|
}
|
|
170
167
|
|
|
171
168
|
// ─── Banner / header helpers ─────────────────────────────────────────────────
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, it } from
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
2
|
import {
|
|
3
3
|
formatMissingKeys,
|
|
4
4
|
formatUnusedKeys,
|
|
@@ -8,179 +8,201 @@ import {
|
|
|
8
8
|
formatAdd,
|
|
9
9
|
formatBenchmark,
|
|
10
10
|
formatError,
|
|
11
|
-
} from
|
|
11
|
+
} from "./formatters.js";
|
|
12
12
|
|
|
13
|
-
describe(
|
|
14
|
-
it(
|
|
15
|
-
const entries = [{ adapter:
|
|
16
|
-
const result = formatMissingKeys(entries,
|
|
13
|
+
describe("formatMissingKeys", () => {
|
|
14
|
+
it("returns JSON array in json mode", () => {
|
|
15
|
+
const entries = [{ adapter: "a", locale: "de", resource: "r", key: "k" }];
|
|
16
|
+
const result = formatMissingKeys(entries, "json");
|
|
17
17
|
expect(JSON.parse(result)).toEqual(entries);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
it(
|
|
21
|
-
const result = formatMissingKeys([],
|
|
22
|
-
expect(result).toContain(
|
|
20
|
+
it("returns success message when empty in pretty mode", () => {
|
|
21
|
+
const result = formatMissingKeys([], "pretty");
|
|
22
|
+
expect(result).toContain("complete");
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
it(
|
|
25
|
+
it("groups by adapter, locale, resource in pretty mode", () => {
|
|
26
26
|
const entries = [
|
|
27
|
-
{ adapter:
|
|
28
|
-
{ adapter:
|
|
29
|
-
{ adapter:
|
|
27
|
+
{ adapter: "a1", locale: "de", resource: "auth", key: "k1" },
|
|
28
|
+
{ adapter: "a1", locale: "de", resource: "auth", key: "k2" },
|
|
29
|
+
{ adapter: "a1", locale: "fr", resource: "auth", key: "k3" },
|
|
30
30
|
];
|
|
31
|
-
const result = formatMissingKeys(entries,
|
|
32
|
-
expect(result).toContain(
|
|
33
|
-
expect(result).toContain(
|
|
34
|
-
expect(result).toContain(
|
|
35
|
-
expect(result).toContain(
|
|
36
|
-
expect(result).toContain(
|
|
37
|
-
expect(result).toContain(
|
|
38
|
-
expect(result).toContain(
|
|
31
|
+
const result = formatMissingKeys(entries, "pretty");
|
|
32
|
+
expect(result).toContain("a1");
|
|
33
|
+
expect(result).toContain("de");
|
|
34
|
+
expect(result).toContain("fr");
|
|
35
|
+
expect(result).toContain("auth");
|
|
36
|
+
expect(result).toContain("k1");
|
|
37
|
+
expect(result).toContain("k2");
|
|
38
|
+
expect(result).toContain("k3");
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
describe(
|
|
43
|
-
it(
|
|
44
|
-
const entries = [{ adapter:
|
|
45
|
-
const result = formatUnusedKeys(entries,
|
|
42
|
+
describe("formatUnusedKeys", () => {
|
|
43
|
+
it("returns JSON array in json mode", () => {
|
|
44
|
+
const entries = [{ adapter: "a", locale: "en", resource: "r", key: "old" }];
|
|
45
|
+
const result = formatUnusedKeys(entries, "json");
|
|
46
46
|
expect(JSON.parse(result)).toEqual(entries);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
it(
|
|
50
|
-
const result = formatUnusedKeys([],
|
|
51
|
-
expect(result).toContain(
|
|
49
|
+
it("returns success message when empty in pretty mode", () => {
|
|
50
|
+
const result = formatUnusedKeys([], "pretty");
|
|
51
|
+
expect(result).toContain("referenced");
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
it(
|
|
55
|
-
const entries = [{ adapter:
|
|
56
|
-
const result = formatUnusedKeys(entries,
|
|
57
|
-
expect(result).toContain(
|
|
58
|
-
expect(result).toContain(
|
|
54
|
+
it("groups entries in pretty mode", () => {
|
|
55
|
+
const entries = [{ adapter: "a", locale: "en", resource: "r", key: "old" }];
|
|
56
|
+
const result = formatUnusedKeys(entries, "pretty");
|
|
57
|
+
expect(result).toContain("a");
|
|
58
|
+
expect(result).toContain("old");
|
|
59
59
|
});
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
describe(
|
|
63
|
-
it(
|
|
64
|
-
const result = formatValidate({ passing: true, entries: [] },
|
|
62
|
+
describe("formatValidate", () => {
|
|
63
|
+
it("returns JSON in json mode", () => {
|
|
64
|
+
const result = formatValidate({ passing: true, entries: [] }, "json");
|
|
65
65
|
const parsed = JSON.parse(result);
|
|
66
66
|
expect(parsed.passing).toBe(true);
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
it(
|
|
70
|
-
const result = formatValidate({ passing: true, entries: [] },
|
|
71
|
-
expect(result).toContain(
|
|
69
|
+
it("returns success message when passing in pretty mode", () => {
|
|
70
|
+
const result = formatValidate({ passing: true, entries: [] }, "pretty");
|
|
71
|
+
expect(result).toContain("up to date");
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
it(
|
|
74
|
+
it("returns table when failing in pretty mode", () => {
|
|
75
75
|
const result = formatValidate(
|
|
76
|
-
{ passing: false, entries: [{ adapter:
|
|
77
|
-
|
|
76
|
+
{ passing: false, entries: [{ adapter: "a", locale: "de", resource: "r", count: 3 }] },
|
|
77
|
+
"pretty",
|
|
78
78
|
);
|
|
79
|
-
expect(result).toContain(
|
|
80
|
-
expect(result).toContain(
|
|
81
|
-
expect(result).toContain(
|
|
82
|
-
expect(result).toContain(
|
|
79
|
+
expect(result).toContain("Missing");
|
|
80
|
+
expect(result).toContain("a");
|
|
81
|
+
expect(result).toContain("de");
|
|
82
|
+
expect(result).toContain("3");
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
describe(
|
|
87
|
-
it(
|
|
88
|
-
const result = formatLanguages([{ adapter:
|
|
89
|
-
expect(JSON.parse(result)).toEqual([{ adapter:
|
|
86
|
+
describe("formatLanguages", () => {
|
|
87
|
+
it("returns JSON in json mode", () => {
|
|
88
|
+
const result = formatLanguages([{ adapter: "a", locales: ["en", "de"] }], "json");
|
|
89
|
+
expect(JSON.parse(result)).toEqual([{ adapter: "a", locales: ["en", "de"] }]);
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
-
it(
|
|
93
|
-
const result = formatLanguages([],
|
|
94
|
-
expect(result).toContain(
|
|
92
|
+
it("returns warning when empty in pretty mode", () => {
|
|
93
|
+
const result = formatLanguages([], "pretty");
|
|
94
|
+
expect(result).toContain("No adapters");
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
-
it(
|
|
98
|
-
const result = formatLanguages([{ adapter:
|
|
99
|
-
expect(result).toContain(
|
|
100
|
-
expect(result).toContain(
|
|
101
|
-
expect(result).toContain(
|
|
97
|
+
it("lists adapters and locales in pretty mode", () => {
|
|
98
|
+
const result = formatLanguages([{ adapter: "laravel", locales: ["en", "de"] }], "pretty");
|
|
99
|
+
expect(result).toContain("laravel");
|
|
100
|
+
expect(result).toContain("en");
|
|
101
|
+
expect(result).toContain("de");
|
|
102
102
|
});
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
describe(
|
|
106
|
-
it(
|
|
107
|
-
const result = formatTranslate({ success: true, message:
|
|
108
|
-
expect(JSON.parse(result)).toEqual({ success: true, message:
|
|
105
|
+
describe("formatTranslate", () => {
|
|
106
|
+
it("returns JSON in json mode", () => {
|
|
107
|
+
const result = formatTranslate({ success: true, message: "Done" }, "json");
|
|
108
|
+
expect(JSON.parse(result)).toEqual({ success: true, message: "Done" });
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
-
it(
|
|
112
|
-
const result = formatTranslate({ success: true, message:
|
|
113
|
-
expect(result).toContain(
|
|
111
|
+
it("returns success text in pretty mode", () => {
|
|
112
|
+
const result = formatTranslate({ success: true, message: "Done" }, "pretty");
|
|
113
|
+
expect(result).toContain("Done");
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
it(
|
|
116
|
+
it("includes stats in pretty mode", () => {
|
|
117
117
|
const result = formatTranslate(
|
|
118
|
-
{
|
|
119
|
-
|
|
118
|
+
{
|
|
119
|
+
success: true,
|
|
120
|
+
message: "Done",
|
|
121
|
+
stats: { adaptersProcessed: 1, localesTranslated: 2, keysTranslated: 5 },
|
|
122
|
+
},
|
|
123
|
+
"pretty",
|
|
120
124
|
);
|
|
121
|
-
expect(result).toContain(
|
|
122
|
-
expect(result).toContain(
|
|
123
|
-
expect(result).toContain(
|
|
124
|
-
expect(result).toContain(
|
|
125
|
+
expect(result).toContain("Adapters:");
|
|
126
|
+
expect(result).toContain("1");
|
|
127
|
+
expect(result).toContain("Locales:");
|
|
128
|
+
expect(result).toContain("2");
|
|
125
129
|
});
|
|
126
130
|
|
|
127
|
-
it(
|
|
128
|
-
const result = formatTranslate({ success: false, message:
|
|
129
|
-
expect(result).toContain(
|
|
131
|
+
it("returns failure text in pretty mode", () => {
|
|
132
|
+
const result = formatTranslate({ success: false, message: "Failed" }, "pretty");
|
|
133
|
+
expect(result).toContain("Failed");
|
|
130
134
|
});
|
|
131
135
|
});
|
|
132
136
|
|
|
133
|
-
describe(
|
|
134
|
-
it(
|
|
135
|
-
const result = formatAdd({ success: true, message:
|
|
136
|
-
expect(JSON.parse(result)).toEqual({ success: true, message:
|
|
137
|
+
describe("formatAdd", () => {
|
|
138
|
+
it("returns JSON in json mode", () => {
|
|
139
|
+
const result = formatAdd({ success: true, message: "Done" }, "json");
|
|
140
|
+
expect(JSON.parse(result)).toEqual({ success: true, message: "Done" });
|
|
137
141
|
});
|
|
138
142
|
|
|
139
|
-
it(
|
|
140
|
-
const result = formatAdd({ success: true, message:
|
|
141
|
-
expect(result).toContain(
|
|
143
|
+
it("returns success text in pretty mode", () => {
|
|
144
|
+
const result = formatAdd({ success: true, message: "Done" }, "pretty");
|
|
145
|
+
expect(result).toContain("Done");
|
|
142
146
|
});
|
|
143
147
|
|
|
144
|
-
it(
|
|
148
|
+
it("lists added resources in pretty mode", () => {
|
|
145
149
|
const result = formatAdd(
|
|
146
|
-
{ success: true, message:
|
|
147
|
-
|
|
150
|
+
{ success: true, message: "Done", addedResources: ["a/en/messages"] },
|
|
151
|
+
"pretty",
|
|
148
152
|
);
|
|
149
|
-
expect(result).toContain(
|
|
153
|
+
expect(result).toContain("a/en/messages");
|
|
150
154
|
});
|
|
151
155
|
});
|
|
152
156
|
|
|
153
|
-
describe(
|
|
154
|
-
it(
|
|
155
|
-
const entries = [
|
|
156
|
-
|
|
157
|
+
describe("formatBenchmark", () => {
|
|
158
|
+
it("returns JSON in json mode", () => {
|
|
159
|
+
const entries = [
|
|
160
|
+
{
|
|
161
|
+
strategyName: "s",
|
|
162
|
+
totalChunks: 1,
|
|
163
|
+
succeededChunks: 1,
|
|
164
|
+
failedChunks: 0,
|
|
165
|
+
totalDurationMs: 100,
|
|
166
|
+
averageDurationMsPerChunk: 100,
|
|
167
|
+
totalAttempts: 1,
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
const result = formatBenchmark(entries, "json");
|
|
157
171
|
expect(JSON.parse(result)).toEqual(entries);
|
|
158
172
|
});
|
|
159
173
|
|
|
160
|
-
it(
|
|
161
|
-
const result = formatBenchmark([],
|
|
162
|
-
expect(result).toContain(
|
|
174
|
+
it("returns warning when empty in pretty mode", () => {
|
|
175
|
+
const result = formatBenchmark([], "pretty");
|
|
176
|
+
expect(result).toContain("No benchmark");
|
|
163
177
|
});
|
|
164
178
|
|
|
165
|
-
it(
|
|
179
|
+
it("renders table in pretty mode", () => {
|
|
166
180
|
const entries = [
|
|
167
|
-
{
|
|
181
|
+
{
|
|
182
|
+
strategyName: "one-shot",
|
|
183
|
+
totalChunks: 2,
|
|
184
|
+
succeededChunks: 2,
|
|
185
|
+
failedChunks: 0,
|
|
186
|
+
totalDurationMs: 200,
|
|
187
|
+
averageDurationMsPerChunk: 100,
|
|
188
|
+
totalAttempts: 2,
|
|
189
|
+
},
|
|
168
190
|
];
|
|
169
|
-
const result = formatBenchmark(entries,
|
|
170
|
-
expect(result).toContain(
|
|
171
|
-
expect(result).toContain(
|
|
172
|
-
expect(result).toContain(
|
|
191
|
+
const result = formatBenchmark(entries, "pretty");
|
|
192
|
+
expect(result).toContain("Benchmark");
|
|
193
|
+
expect(result).toContain("one-shot");
|
|
194
|
+
expect(result).toContain("2/2");
|
|
173
195
|
});
|
|
174
196
|
});
|
|
175
197
|
|
|
176
|
-
describe(
|
|
177
|
-
it(
|
|
178
|
-
const result = formatError(
|
|
179
|
-
expect(JSON.parse(result)).toEqual({ error:
|
|
198
|
+
describe("formatError", () => {
|
|
199
|
+
it("returns JSON in json mode", () => {
|
|
200
|
+
const result = formatError("Something broke", "json");
|
|
201
|
+
expect(JSON.parse(result)).toEqual({ error: "Something broke" });
|
|
180
202
|
});
|
|
181
203
|
|
|
182
|
-
it(
|
|
183
|
-
const result = formatError(
|
|
184
|
-
expect(result).toContain(
|
|
204
|
+
it("returns failure text in pretty mode", () => {
|
|
205
|
+
const result = formatError("Something broke", "pretty");
|
|
206
|
+
expect(result).toContain("Something broke");
|
|
185
207
|
});
|
|
186
208
|
});
|