简体   繁体   中英

Unable to run nodejs script for a json rpc test case automation

I am trying to run a nodejs script written for a json rpc test case automation. However, I keep getting the error:

npm run test\resources\nv-jsonrpc-tests\pingServer.spec.js
error missing script: test\resources\nv-jsonrpc-tests\pingServer.spec.js
verbose exit [ 1, true ]/>

var rpc = require('node-json-rpc');

var options = {
// int port of rpc server
port: 8080,
// string domain name or ip of rpc server, default '127.0.0.1'
host: '127.0.0.1',
// string with default path, default '/'
path: 'https://',
// boolean false to turn rpc checks off, default true
strict: true
};

// Create a server object with options
var client = new rpc.Client(options);

client.call(
{"jsonrpc": "2.0", "method": "Ping", "params": {classname: 'NServer'}, 
"id": 1},
function (err, res) {
// Check whether it worked and capture the response and error
if (err) { console.log(err); }
else { console.log(res); }
}
);

Expectation:

Client send request with 'Ping' and receives 'Pong' from the server response.

You seems to confuse npm run and node

npm run is meant to execute scripts declared in your package.json
node can directly execute the script in the file you give

Running this should work

node test\resources\nv-jsonrpc-tests\pingServer.spec.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM