Skip to content

Commit 9b51c9f

Browse files
authored
Merge pull request #5 from open-rpc/fix/remove-emoji
fix: remove emoji from console reporter
2 parents 1c41a11 + f76e940 commit 9b51c9f

File tree

6 files changed

+35
-44
lines changed

6 files changed

+35
-44
lines changed

bin/cli.js

100644100755
+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const program = require('commander');
33
const orpcCoverage = require('../build').default;
44
const { parseOpenRPCDocument } = require('@open-rpc/schema-utils-js');
55

6-
76
const getSkipMethods = (input) => {
87
if (input && input.split(',').length > 0) {
98
return input.split(',');
@@ -18,7 +17,7 @@ program
1817
.option('-s, --schema [schema]', 'JSON string or a Path/Url pointing to an open rpc schema')
1918
.option('-r, --reporter <reporter>', 'Use the specified reporter [console] [json]')
2019
.option('-t, --transport <transport>', 'Use the specified transport [http]')
21-
.option('--skipMethods <skipMethods>', 'Use the specified transport [http]')
20+
.option('--skipMethods <skipMethods>', 'Methods to skip')
2221
.action(async () => {
2322
let schema;
2423
try {

package-lock.json

+13-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
"@open-rpc/meta-schema": "^1.3.1",
2121
"@open-rpc/schema-utils-js": "^1.6.3",
2222
"@types/isomorphic-fetch": "0.0.35",
23-
"json-schema-faker": "^0.5.0-rc16",
23+
"colors": "^1.3.3",
2424
"isomorphic-fetch": "^2.2.1",
25+
"json-schema-faker": "^0.5.0-rc16",
2526
"json-schema-ref-parser": "^6.1.0"
2627
},
2728
"devDependencies": {

src/coverage.ts

+8-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const getParams = async (params: any[]) => {
99
return Promise.all(promises);
1010
}
1111

12-
const results: any[] = [];
1312

1413
interface IOptions {
1514
schema: OpenRPC;
@@ -19,9 +18,10 @@ interface IOptions {
1918
}
2019

2120
export default async (options: IOptions) => {
21+
const results: any[] = [];
2222
const promises = options.schema.methods.map(async (method) => {
2323
if (options.skipMethods.includes(method.name)) {
24-
return Promise.resolve();
24+
return;
2525
}
2626
const params = await getParams(method.params);
2727
const urls = (options.schema.servers || []).map((u) => {
@@ -31,27 +31,16 @@ export default async (options: IOptions) => {
3131
return Promise.all(urls.map((url) => {
3232
return options.transport(url, method.name, params)
3333
.then((r: any) => {
34-
if (r.error && r.error.message.includes('does not exist')) {
35-
results.push({
36-
method: method.name,
37-
error: 'Method Does Not Exist'
38-
});
39-
} else if (r.error) {
40-
results.push({
41-
method: method.name,
42-
error: r.error.message
43-
});
44-
} else {
45-
results.push({
46-
method: method.name,
47-
result: r.result
48-
});
49-
}
34+
results.push({
35+
method: method.name,
36+
params,
37+
...r
38+
})
5039
});
5140
}))
5241
});
5342

5443
return Promise.all(promises).then(() => {
5544
return results;
5645
}).then(options.reporter)
57-
}
46+
}

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ interface IOptions {
2222

2323
export default async (options: IOptions) => {
2424
return coverage({
25-
reporter: reporters[options.reporter],
25+
reporter: reporters[options.reporter || 'console'],
2626
schema: options.schema,
2727
skipMethods: options.skipMethods || [],
28-
transport: transports[options.transport]
28+
transport: transports[options.transport || 'http']
2929
});
3030
}

src/reporters/console.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import colors from 'colors';
2+
13
export default (callResults: any[]) => {
24
const metrics = {
35
errors: 0,
@@ -6,14 +8,16 @@ export default (callResults: any[]) => {
68
callResults.forEach((call) => {
79
if (call.error) {
810
metrics.errors++;
9-
console.log('⛔️', call.method, 'ERROR:', call.error)
11+
console.log(colors.red.underline('Error: '), colors.cyan(call.method));
12+
console.log(call.error);
13+
console.log(call.params);
1014
} else {
1115
metrics.success++;
12-
console.log('✅', call.method)
16+
console.log(colors.green('Success: '), call.method)
1317
}
1418
})
1519
console.log('==========');
16-
console.log('Success: ', metrics.success);
17-
console.log('Errors: ', metrics.errors);
20+
console.log('Success: ', colors.green(metrics.success.toString()));
21+
console.log('Errors: ', colors.red(metrics.errors.toString()));
1822
console.log('==========');
19-
};
23+
};

0 commit comments

Comments
 (0)