Skip to content

Commit 8799152

Browse files
committed
Added CLI tests.
1 parent 0f59c43 commit 8799152

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed

packages/doxdox-cli/src/index.test.ts

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
import { promises as fs } from 'fs';
2+
3+
import { promisify } from 'util';
4+
5+
import { exec } from 'child_process';
6+
7+
const execAsync = promisify(exec);
8+
9+
describe('cli', () => {
10+
it('get version (short flag)', async () => {
11+
const pkg = JSON.parse(await fs.readFile('./package.json', 'utf8'));
12+
13+
const { stdout } = await execAsync(`./dist/src/index.js -v`);
14+
15+
expect(stdout.trim()).toBe(pkg.version);
16+
});
17+
it('get version (full flag)', async () => {
18+
const pkg = JSON.parse(await fs.readFile('./package.json', 'utf8'));
19+
20+
const { stdout } = await execAsync(`./dist/src/index.js --version`);
21+
22+
expect(stdout.trim()).toBe(pkg.version);
23+
});
24+
it('get help (short flag)', async () => {
25+
const { stdout } = await execAsync(`./dist/src/index.js -h`);
26+
27+
expect(stdout).toContain('Usage: doxdox');
28+
});
29+
it('get help (long flag)', async () => {
30+
const { stdout } = await execAsync(`./dist/src/index.js --help`);
31+
32+
expect(stdout).toContain('Usage: doxdox');
33+
});
34+
it('set name (short flag)', async () => {
35+
const { stdout } = await execAsync(
36+
`./dist/src/index.js -n "testing the project name"`
37+
);
38+
39+
expect(stdout).toContain('# testing the project name');
40+
});
41+
it('set name (long flag)', async () => {
42+
const { stdout } = await execAsync(
43+
`./dist/src/index.js --name "testing the project name"`
44+
);
45+
46+
expect(stdout).toContain('# testing the project name');
47+
});
48+
it('set description (short flag)', async () => {
49+
const { stdout } = await execAsync(
50+
`./dist/src/index.js -d "testing the project description"`
51+
);
52+
53+
expect(stdout).toContain('> testing the project description');
54+
});
55+
it('set description (long flag)', async () => {
56+
const { stdout } = await execAsync(
57+
`./dist/src/index.js --description "testing the project description"`
58+
);
59+
60+
expect(stdout).toContain('> testing the project description');
61+
});
62+
it('set renderer (short flag)', async () => {
63+
const { stdout } = await execAsync(`./dist/src/index.js -r bootstrap`);
64+
65+
expect(stdout).toContain('<html>');
66+
});
67+
it('set renderer (long flag)', async () => {
68+
const { stdout } = await execAsync(
69+
`./dist/src/index.js --renderer bootstrap`
70+
);
71+
72+
expect(stdout).toContain('<html>');
73+
});
74+
it('set output (no flag)', async () => {
75+
const { stdout } = await execAsync(`./dist/src/index.js`);
76+
77+
expect(stdout).toContain('# doxdox-cli');
78+
});
79+
it('set output (no directory)', async () => {
80+
const { stdout } = await execAsync(`./dist/src/index.js -o temp.md`);
81+
82+
await fs.stat('./temp.md');
83+
84+
expect(stdout).not.toContain('# doxdox-cli');
85+
86+
expect(await fs.readFile('./temp.md', 'utf8')).toContain(
87+
'# doxdox-cli'
88+
);
89+
90+
await fs.unlink('./temp.md');
91+
});
92+
it('set output (inside exisiting directory)', async () => {
93+
const { stdout } = await execAsync(
94+
`./dist/src/index.js -o src/temp.md`
95+
);
96+
97+
await fs.stat('./src/temp.md');
98+
99+
expect(stdout).not.toContain('# doxdox-cli');
100+
101+
expect(await fs.readFile('./src/temp.md', 'utf8')).toContain(
102+
'# doxdox-cli'
103+
);
104+
105+
await fs.unlink('./src/temp.md');
106+
});
107+
it('set output (inside non-exisiting directory)', async () => {
108+
const { stdout } = await execAsync(
109+
`./dist/src/index.js -o temp/temp.md`
110+
);
111+
112+
await fs.stat('./temp/temp.md');
113+
114+
expect(stdout).not.toContain('# doxdox-cli');
115+
116+
expect(await fs.readFile('./temp/temp.md', 'utf8')).toContain(
117+
'# doxdox-cli'
118+
);
119+
120+
await fs.unlink('./temp/temp.md');
121+
});
122+
it('set output (short flag)', async () => {
123+
const { stdout } = await execAsync(`./dist/src/index.js -o temp.md`);
124+
125+
await fs.stat('./temp.md');
126+
127+
expect(stdout).not.toContain('# doxdox-cli');
128+
129+
expect(await fs.readFile('./temp.md', 'utf8')).toContain(
130+
'# doxdox-cli'
131+
);
132+
133+
await fs.unlink('./temp.md');
134+
});
135+
it('set output (long flag)', async () => {
136+
const { stdout } = await execAsync(
137+
`./dist/src/index.js --output temp.md`
138+
);
139+
140+
await fs.stat('./temp.md');
141+
142+
expect(stdout).not.toContain('# doxdox-cli');
143+
144+
expect(await fs.readFile('./temp.md', 'utf8')).toContain(
145+
'# doxdox-cli'
146+
);
147+
148+
await fs.unlink('./temp.md');
149+
});
150+
it('set package location (no flag)', async () => {
151+
const { stdout } = await execAsync(`./dist/src/index.js`);
152+
153+
expect(stdout).toContain('# doxdox-cli');
154+
});
155+
it('set package location (short flag)', async () => {
156+
const { stdout } = await execAsync(
157+
`./dist/src/index.js -p ../../package.json`
158+
);
159+
160+
expect(stdout).toContain('# doxdox-workspace');
161+
});
162+
it('set package location (long flag)', async () => {
163+
const { stdout } = await execAsync(
164+
`./dist/src/index.js --package ../../package.json`
165+
);
166+
167+
expect(stdout).toContain('# doxdox-workspace');
168+
});
169+
});

0 commit comments

Comments
 (0)