-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcli-watch.e2e.test.ts
More file actions
137 lines (119 loc) · 4.95 KB
/
Copy pathcli-watch.e2e.test.ts
File metadata and controls
137 lines (119 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
87
88
89
90
91
92
93
94
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
131
132
133
134
135
136
137
/**
* E2E Tests for Watch Command
* Tests `deepl watch` help text, argument validation, and --dry-run behavior
*/
import * as path from 'path';
import * as os from 'os';
import * as fs from 'fs';
import { createTestConfigDir, makeNodeRunCLI } from '../helpers';
describe('Watch Command E2E', () => {
const testConfig = createTestConfigDir('e2e-watch');
const { runCLI, runCLIAll } = makeNodeRunCLI(testConfig.path);
afterAll(() => {
testConfig.cleanup();
});
describe('watch --help', () => {
it('should show --git-staged option without "not yet implemented"', () => {
const output = runCLI('watch --help');
expect(output).toContain('--git-staged');
expect(output).toContain('snapshot at startup');
expect(output).not.toContain('not yet implemented');
});
it('should show all core options', () => {
const output = runCLI('watch --help');
expect(output).toContain('--to');
expect(output).toContain('--from');
expect(output).toContain('--output');
});
it('should show watch behavior options', () => {
const output = runCLI('watch --help');
expect(output).toContain('--pattern');
expect(output).toContain('--debounce');
expect(output).toContain('--dry-run');
expect(output).toContain('--auto-commit');
});
it('should show translation quality options', () => {
const output = runCLI('watch --help');
expect(output).toContain('--formality');
expect(output).toContain('--glossary');
expect(output).toContain('--preserve-code');
});
it('should show usage examples', () => {
const output = runCLI('watch --help');
expect(output).toContain('deepl watch');
expect(output).toContain('--to');
});
});
describe('watch --dry-run --git-staged', () => {
it('should show git-staged info in dry-run output', () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'deepl-watch-e2e-'));
fs.writeFileSync(path.join(tmpDir, 'test.txt'), 'Hello');
try {
const output = runCLI(`watch ${tmpDir} --to es --dry-run --git-staged`);
expect(output).toContain('[dry-run]');
expect(output).toContain('Git-staged');
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
});
});
describe('watch --dry-run', () => {
it('should show configuration summary without starting watcher', () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'deepl-watch-e2e-'));
fs.writeFileSync(path.join(tmpDir, 'readme.md'), 'Hello world');
try {
const output = runCLI(`watch ${tmpDir} --to de --dry-run`);
expect(output).toContain('[dry-run]');
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
});
});
describe('watch without required arguments', () => {
it('should fail when no path is provided', () => {
try {
runCLIAll('watch');
fail('Should have thrown');
} catch (error: unknown) {
const execError = error as { status: number };
expect(execError.status).toBeGreaterThan(0);
}
});
it('should show actionable error when --to is missing and no config default', () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'deepl-watch-e2e-'));
const { runCLIExpectError } = makeNodeRunCLI(testConfig.path);
try {
const { status, output } = runCLIExpectError(`watch ${tmpDir} --dry-run`);
expect(status).toBeGreaterThan(0);
expect(output).toContain('No target language specified.');
expect(output).toContain('deepl init');
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
});
it('should use config default targetLangs when --to is not specified', () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'deepl-watch-e2e-'));
const configWithDefaults = {
auth: { apiKey: 'test-key:fx' },
api: { baseUrl: 'https://api-free.deepl.com' },
defaults: { targetLangs: ['es', 'fr'], formality: 'default', preserveFormatting: true },
cache: { enabled: false, maxSize: 1048576, ttl: 2592000 },
output: { format: 'text', verbose: false, color: false },
watch: { debounceMs: 500, autoCommit: false, pattern: '*.md' },
};
const configDir = fs.mkdtempSync(path.join(os.tmpdir(), 'deepl-watch-config-'));
fs.writeFileSync(path.join(configDir, 'config.json'), JSON.stringify(configWithDefaults, null, 2));
fs.writeFileSync(path.join(tmpDir, 'test.md'), 'Hello');
const { runCLI: runWithConfig } = makeNodeRunCLI(configDir);
try {
const output = runWithConfig(`watch ${tmpDir} --dry-run`);
expect(output).toContain('[dry-run]');
expect(output).toContain('es');
expect(output).toContain('fr');
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
fs.rmSync(configDir, { recursive: true, force: true });
}
});
});
});