Skip to content

Commit f3b0d9e

Browse files
committed
fix some bugs
1 parent 9996c3b commit f3b0d9e

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ url1, url2, method, headers, body, sortKey, ignore
120120

121121
**`ignore`**: keys to ignore. Pipe delimted. (`|`)
122122

123+
**`expectedStatusCode`**: Expected status code (defaults to 200)
124+
123125
```csv
124126
url1,url2
125127
https://gist.githubusercontent.com/nahtnam/920171eeef10e911a6ee7698d9c226ae/raw/bdd86427b8c807e149251d4737d2886620f7fcdc/a.json,https://gist.githubusercontent.com/nahtnam/920171eeef10e911a6ee7698d9c226ae/raw/bdd86427b8c807e149251d4737d2886620f7fcdc/b.json

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-diff-cli",
3-
"version": "0.4.1",
3+
"version": "0.4.9",
44
"description": "json-diff-cli",
55
"main": "index.js",
66
"scripts": {
@@ -35,7 +35,7 @@
3535
"chalk": "^1.1.3",
3636
"csvtojson": "^1.1.5",
3737
"easy-table": "^1.1.0",
38-
"json-diff-core": "^0.1.1",
38+
"json-diff-core": "^0.1.6",
3939
"yargs": "^8.0.1"
4040
},
4141
"release": {

scripts/csv.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const csvScript = async (args) => {
7272
const body = row.body;
7373
const timeout = args.timeout;
7474
const skipcertificate = row.skipCertificate || false;
75+
const expectedStatusCode = row.expectedStatusCode ? parseInt(row.expectedStatusCode, 10) : null;
7576

7677
if (url1.charAt(0) === '#') {
7778
continue; // eslint-disable-line
@@ -99,6 +100,15 @@ const csvScript = async (args) => {
99100
}
100101
sortKeys.push('id');
101102

103+
const skipHeadersInputs = row.skipHeaders || '';
104+
const skipHeaders = [];
105+
if (skipHeadersInputs) {
106+
const list = skipHeadersInputs.split('|');
107+
list.forEach((splitHeaders) => {
108+
skipHeaders.push(splitHeaders);
109+
});
110+
}
111+
102112
const ignore = row.ignore;
103113
const ignores = [];
104114
if (ignore) {
@@ -116,6 +126,8 @@ const csvScript = async (args) => {
116126
headers,
117127
timeout,
118128
skipcertificate,
129+
expectedStatusCode,
130+
skipHeaders,
119131
ignore: ignores,
120132
};
121133

@@ -128,8 +140,12 @@ const csvScript = async (args) => {
128140
const diff = await core.diffURLs(url1, url2, options);
129141

130142
if (args.diffheaders) {
143+
options.skipHeaders.forEach((h) => {
144+
delete diff.leftHeaders[h];
145+
delete diff.rightHeaders[h];
146+
});
131147
const headersDiff = await core.diffJSON(diff.leftHeaders, diff.rightHeaders);
132-
if (headersDiff.length !== 0) {
148+
if (headersDiff.length !== 0 && headersDiff[0].diff !== 'none') {
133149
if (diff.differences[0].diff === 'none') {
134150
diff.differences.splice(0, 1);
135151
}
@@ -183,6 +199,7 @@ const csvScript = async (args) => {
183199

184200
console.log(output);
185201
} catch (err) {
202+
console.log(err);
186203
console.log(chalk.red(err.toString()), '\n');
187204
}
188205
}

0 commit comments

Comments
 (0)