This repository was archived by the owner on Jun 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 393
Expand file tree
/
Copy pathmain.test.js
More file actions
156 lines (151 loc) · 5.67 KB
/
Copy pathmain.test.js
File metadata and controls
156 lines (151 loc) · 5.67 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { spawn, exec as execCB } from 'child_process';
import streamToString from 'stream-to-string';
import { promisify } from 'util';
import packageJson from '../package.json';
const exec = promisify(execCB);
const run = async (argv, { waitForVolumeExport = true, stdin = '' } = {}) => {
let volume;
let exitCode;
const child = spawn(
process.execPath,
['build/test-utils/cli-test-entry.js', ...argv],
{
stdio: ['pipe', 'pipe', 2, 'ipc'],
},
);
const allChecks = Promise.all([
waitForVolumeExport
? new Promise((volumeSet) => {
child.on('message', async (message) => {
if (message.type === 'volumeExport') {
volume = message.data;
volumeSet();
}
});
})
: true,
new Promise((processExited) => {
child.on('exit', (code) => {
exitCode = code;
processExited();
});
}),
]);
child.stdin.write(stdin);
child.stdin.end();
const stdout = await streamToString(child.stdout);
await allChecks;
return {
volume,
code: exitCode,
stdout,
};
};
describe('cli configuration', () => {
beforeAll(() => exec(packageJson.scripts.prepare));
it('should show help', async () => {
const { stdout } = await run(['help'], { waitForVolumeExport: false });
expect(stdout).toMatchInlineSnapshot(`
"Usage: resume [command] [options]
Options:
-V, --version output the version number
-F, --force Used by \`publish\` and \`export\` - bypasses
schema testing.
-t, --theme <theme name> Specify theme used by \`export\` and
\`serve\` or specify a path starting with .
(use . for current directory or
../some/other/dir) (default:
\\"jsonresume-theme-even\\")
-f, --format <file type extension> Used by \`export\`.
-r, --resume <resume filename> path to the resume in json format. Use
'-' to read from stdin (default:
\\"resume.json\\")
-p, --port <port> Used by \`serve\` (default: 4000) (default:
4000)
-s, --silent Used by \`serve\` to tell it if open
browser auto or not. (default: false)
-d, --dir <path> Used by \`serve\` to indicate a public
directory path. (default: \\"public\\")
-T, --type <mime type> Specify the mime type of the resume file.
--schema <relativePath> Used by \`validate\` to validate against a
custom schema.
-h, --help display help for command
Commands:
init Initialize a resume.json file
validate Validate your resume's schema
export [fileName] Export locally to .html or .pdf. Supply
a --format <file format> flag and
argument to specify export format.
serve Serve resume at http://localhost:4000/
help [command] display help for command
"
`);
});
describe('validate', () => {
it('should use the schema override arg', async () => {
const { stdout } = await run([
'validate',
'--schema',
'/test-resumes/only-number-schema.json',
'--resume',
'/test-resumes/only-number.json',
]);
expect(stdout).toMatchInlineSnapshot(`""`);
});
it('should fail when trying to validate an invalid resume specified by the --resume option', async () => {
expect(
(
await run([
'validate',
'--resume',
'/test-resumes/invalid-resume.json',
])
).code,
).toEqual(1);
});
it('should validate a resume specified by the --resume option', async () => {
const { stdout } = await run([
'validate',
'--resume',
'/test-resumes/resume.json',
]);
expect(stdout).toMatchInlineSnapshot(`""`);
});
});
describe('export', () => {
it('should read from stdin when path is a dash', async () => {
const { stdout, volume } = await run(
[
'export',
'/test-resumes/exported-resume-from-stdin.html',
'--resume',
'-', // this is the dash
],
{ stdin: JSON.stringify({ basics: { name: 'thomas-from-stdin' } }) },
);
expect(volume['/test-resumes/exported-resume-from-stdin.html']).toEqual(
expect.stringContaining('thomas-from-stdin'),
);
expect(stdout).toMatchInlineSnapshot(`
"
Done! Find your new .html resume at:
/test-resumes/exported-resume-from-stdin.html
"
`);
});
it('should export a resume from the path specified by --resume to the path specified immediately after the export command', async () => {
const { stdout } = await run([
'export',
'/test-resumes/exported-resume.html',
'--resume',
'/test-resumes/resume.json',
]);
expect(stdout).toMatchInlineSnapshot(`
"
Done! Find your new .html resume at:
/test-resumes/exported-resume.html
"
`);
});
});
});