Skip to content

Commit a9ff96a

Browse files
committed
fix JSON5 output disabled returning undefined, add tests
1 parent 572232e commit a9ff96a

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

Tasks/JsonPatch/json5Patcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Json5Patcher extends jsonPatcher.JsonPatcher {
1919
if (this.outputJson5) {
2020
return JSON5.stringify(content);
2121
} else {
22-
super.stringify(content)
22+
return super.stringify(content)
2323
}
2424
}
2525
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import json5Patcher = require("../../Tasks/JsonPatch/json5Patcher");
2+
var JSON5 = require("../../Tasks/JsonPatch/node_modules/json5");
3+
4+
5+
6+
describe("JSON5 Patcher", () => {
7+
8+
describe("Operations", () => {
9+
10+
var source: string;
11+
12+
beforeEach(function () {
13+
source = JSON5.stringify({
14+
sampleValue: "12"
15+
});
16+
});
17+
18+
describe("JSON5 Output Enabled", () => {
19+
describe("Add", () => {
20+
it(": should support basic add.", () => {
21+
var patcher = new json5Patcher.Json5Patcher([
22+
{
23+
op: "add", path: "/added", value: {}
24+
}, {
25+
op: "add", path: "/added/value", value: "42"
26+
}
27+
], true);
28+
var result = JSON5.parse(patcher.apply(source));
29+
30+
expect(result).toBeDefined();
31+
expect(result.sampleValue).toBeDefined();
32+
expect(result.sampleValue).toEqual("12");
33+
expect(result.added.value).toEqual("42");
34+
});
35+
});
36+
});
37+
38+
describe("JSON5 Output Disabled", () => {
39+
describe("Add", () => {
40+
it(": should support basic add.", () => {
41+
var patcher = new json5Patcher.Json5Patcher([
42+
{
43+
op: "add", path: "/added", value: {}
44+
}, {
45+
op: "add", path: "/added/value", value: "42"
46+
}
47+
], false);
48+
var result = JSON.parse(patcher.apply(source));
49+
50+
expect(result).toBeDefined();
51+
expect(result.sampleValue).toBeDefined();
52+
expect(result.sampleValue).toEqual("12");
53+
expect(result.added.value).toEqual("42");
54+
});
55+
});
56+
});
57+
});
58+
});

0 commit comments

Comments
 (0)