Skip to content

Commit 08dc761

Browse files
committed
add exitCode to tests to run it within a CI
1 parent e6978af commit 08dc761

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

json-to-go.test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,14 @@ function test(includeExampleData) {
141141
const got = jsonToGo(testCase.input, null, null, includeExampleData);
142142
if (got.error) {
143143
console.assert(!got.error, `format('${testCase.input}'): ${got.error}`);
144+
process.exitCode = 16
144145
} else {
145146
const exp = includeExampleData ? testCase.expectedWithExample : testCase.expected
146-
console.assert(
147-
got.go === exp,
147+
const success = got.go === exp
148+
console.assert(success,
148149
`format('${testCase.input}'): \n\tgot: ${quote(got.go)}\n\twant: ${quote(exp)}`
149150
);
151+
if(!success) process.exitCode = 17
150152
}
151153
}
152154
console.log(includeExampleData ? "done testing samples with data" : "done testing samples without data")
@@ -169,14 +171,17 @@ function testFiles() {
169171
const got = jsonToGo(jsonData);
170172
if (got.error) {
171173
console.assert(!got.error, `format('${jsonData}'): ${got.error}`);
174+
process.exitCode = 18
172175
} else {
173-
console.assert(
174-
got.go === expectedGoData,
176+
const success = got.go === expectedGoData
177+
console.assert(success,
175178
`format('${jsonData}'): \n\tgot: ${quote(got.go)}\n\twant: ${quote(expectedGoData)}`
176179
);
180+
if(!success) process.exitCode = 19
177181
}
178182
} catch (err) {
179183
console.error(err);
184+
process.exitCode = 20
180185
}
181186
}
182187
console.log("done testing files")

0 commit comments

Comments
 (0)