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
|
| import path from 'path';
| import { exec, ExecException } from 'child_process';
|
|
| function runCLI (args: string[] = []): Promise<{
| code: number;
| error: ExecException | null;
| stdout: string;
| stderr: string;
| }> {
| return new Promise(resolve => {
| exec(
| `node ${path.resolve(__dirname + '../../../bin/vue-i18n-extract.js')} ${args.join(' ')}`,
| { cwd: '.' },
| (error, stdout, stderr) => {
| resolve({
| code: error && error.code ? error.code : 0,
| error,
| stdout,
| stderr,
| });
| },
| );
| })}
|
|
| describe('vue-i18n-extract CLI', () => {
| it('Not run without arguments, but show tip', async () => {
| const result = await runCLI();
| expect(result.code).not.toBe(0);
| expect(result.stderr).toContain(`required option '-v, --vueFiles <vueFiles>' not specified`);
|
| const result2 = await runCLI(['report']);
| expect(result2.code).not.toBe(0);
| expect(result2.stderr).toContain(`required option '-v, --vueFiles <vueFiles>' not specified`);
| });
|
| it('Show help', async () => {
| const result = await runCLI(['--help']);
| expect(result.code).toBe(0);
| expect(result.stdout).toContain(`Usage: vue-i18n-extract`);
|
| const result2 = await runCLI(['report', '--help']);
| expect(result2.code).toBe(0);
| expect(result2.stdout).toContain(`Usage: vue-i18n-extract report`);
| });
|
| describe('Report Command', () => {
| it('Run the command with defined options', async () => {
| expect((await runCLI([
| 'report',
| '-v',
| `'./fixtures/vue-files/**/*.?(vue|js)'`,
| ])).code).not.toBe(0);
|
| expect((await runCLI([
| 'report',
| '-v',
| `'./fixtures/vue-files/**/*.?(vue|js)'`,
| '-l',
| `'./fixtures/language-files/**/*.?(json|yml|yaml)'`,
| ])).code).toBe(0);
|
| expect((await runCLI([
| 'report',
| '-v',
| `'./fixtures/vue-files/**/*.?(vue|js)'`,
| '-l',
| `'./fixtures/language-files/**/*.?(json|yml|yaml)'`,
| '-o',
| `'/dev/null'`
| ])).code).toBe(0);
|
| expect((await runCLI([
| 'report',
| '-v',
| `'./fixtures/vue-files/**/*.?(vue|js)'`,
| '-l',
| `'./fixtures/language-files/**/*.?(json|yml|yaml)'`,
| '-o',
| `'/dev/null'`,
| '-a',
| ])).code).toBe(0);
|
| expect((await runCLI([
| 'report',
| '-v',
| `'./fixtures/vue-files/**/*.?(vue|js)'`,
| '-l',
| `'./fixtures/language-files/**/*.?(json|yml|yaml)'`,
| '-o',
| `'/dev/null'`,
| '-a',
| '-r'
| ])).code).toBe(0);
|
| expect((await runCLI([
| 'report',
| '-v',
| `'./fixtures/vue-files/**/*.?(vue|js)'`,
| '-l',
| `'./fixtures/language-files/**/*.?(json|yml|yaml)'`,
| '-o',
| `'/dev/null'`,
| '-a',
| '-ci',
| ])).code).toBe(0);
| });
| });
|
| describe('Init Command', () => {
|
| beforeEach(() => {
| jest.resetModules();
| jest.resetAllMocks();
| });
|
| it('creates a config file', async () => {
| expect((await runCLI([
| 'init',
| ])).code).toBe(0);
| });
| });
| });
|
|