Skip to content

Commit a76d4c4

Browse files
author
antialias
committed
exiting with code 1 when failing validation
1 parent bed89f3 commit a76d4c4

4 files changed

Lines changed: 29 additions & 8 deletions

File tree

lib/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ const normalizeTheme = (value, defaultValue) => {
7373
.description("Validate your resume's schema")
7474
.action(async () => {
7575
const resume = await getResume({ path: program.resume });
76-
await validate(resume);
76+
try {
77+
await validate(resume);
78+
} catch (e) {
79+
console.error(e.message)
80+
process.exitCode = 1;
81+
}
7782
});
7883

7984
program

lib/main.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ describe('cli configuration', () => {
4848
"
4949
`);
5050
});
51+
describe('validate', () => {
52+
it('should fail when trying to validate an invalid resume specified by the --resume option', async () => {
53+
await expect(
54+
run('validate --resume /test-resumes/invalid-resume.json'),
55+
).rejects.toEqual(
56+
expect.objectContaining({
57+
code: 1,
58+
}),
59+
);
60+
});
61+
it('should validate a resume specified by the --resume option', async () => {
62+
const output = await run('validate --resume /test-resumes/resume.json');
63+
expect(output.stdout).toMatchInlineSnapshot(`""`);
64+
expect(output.stderr).toMatchInlineSnapshot(`""`);
65+
});
66+
});
5167
describe('export', () => {
5268
it('should export a resume from the path specified by --resume to the path specified immediately after the export command', async () => {
5369
const output = await run(

lib/test-utils/mocked-volume-builder.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ module.exports = ({ mount = '/' } = {}) => {
55
return Volume.fromJSON(
66
flat(
77
{
8+
'invalid-resume.json': JSON.stringify({
9+
notAValidKey: {
10+
foo: 'bar',
11+
},
12+
}),
813
'resume.json': JSON.stringify({
914
basics: {
1015
name: 'thomas',

lib/validate.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ const getSchema = function () {
1111
return schema;
1212
} // Return the default schema, if a custom schema wasn't specified
1313

14-
try {
15-
const customSchemaPath = path.join(process.cwd(), process.argv[index + 1]);
16-
return JSON.parse(fs.readFileSync(customSchemaPath, { encoding: 'utf-8' }));
17-
} catch (error) {
18-
console.log(error.message);
19-
process.exit();
20-
}
14+
const customSchemaPath = path.join(process.cwd(), process.argv[index + 1]);
15+
return JSON.parse(fs.readFileSync(customSchemaPath, { encoding: 'utf-8' }));
2116
};
2217

2318
const reporter = ZSchemaErrors.init();

0 commit comments

Comments
 (0)