Merge pull request #805 from thisandagain/bugfix/802

Replace 'got' module with 'nets'
This commit is contained in:
Andrew Sliwinski 2017-11-27 15:17:04 -05:00 committed by GitHub
commit 519d41d966
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 3 deletions

1
.gitignore vendored
View file

@ -2,6 +2,7 @@
.DS_Store .DS_Store
# NPM # NPM
package-lock.json
/node_modules /node_modules
npm-* npm-*

View file

@ -36,7 +36,6 @@
"eslint-config-scratch": "^5.0.0", "eslint-config-scratch": "^5.0.0",
"expose-loader": "0.7.4", "expose-loader": "0.7.4",
"gh-pages": "^1.1.0", "gh-pages": "^1.1.0",
"got": "5.7.1",
"highlightjs": "^9.8.0", "highlightjs": "^9.8.0",
"htmlparser2": "3.9.2", "htmlparser2": "3.9.2",
"immutable": "3.8.1", "immutable": "3.8.1",
@ -44,6 +43,7 @@
"json": "^9.0.4", "json": "^9.0.4",
"lodash.defaultsdeep": "4.6.0", "lodash.defaultsdeep": "4.6.0",
"minilog": "3.1.0", "minilog": "3.1.0",
"nets": "3.2.0",
"promise": "8.0.1", "promise": "8.0.1",
"scratch-audio": "latest", "scratch-audio": "latest",
"scratch-blocks": "latest", "scratch-blocks": "latest",

View file

@ -1,4 +1,4 @@
const got = require('got'); const nets = require('nets');
const io = require('socket.io-client/dist/socket.io'); const io = require('socket.io-client/dist/socket.io');
const querystring = require('querystring'); const querystring = require('querystring');
@ -312,7 +312,17 @@ class DeviceManager {
}; };
if (deviceSpec) queryObject.spec = deviceSpec; if (deviceSpec) queryObject.spec = deviceSpec;
const url = `${this._serverURL}/${encodeURIComponent(deviceType)}/list?${querystring.stringify(queryObject)}`; const url = `${this._serverURL}/${encodeURIComponent(deviceType)}/list?${querystring.stringify(queryObject)}`;
return got(url).then(response => JSON.parse(response.body)); return new Promise((resolve, reject) => {
nets({
method: 'GET',
url: url,
json: {}
}, (err, res, body) => {
if (err) return reject(err);
if (res.statusCode !== 200) return reject(body);
resolve(body);
});
});
} }
/** /**

View file

@ -19,3 +19,21 @@ test('default connected', t => {
t.strictEqual(deviceManager.isConnected, true); t.strictEqual(deviceManager.isConnected, true);
t.end(); t.end();
}); });
test('list', t => {
const deviceManager = new DeviceManager();
deviceManager
.list('test', 'test', null)
.then(
body => {
// SDM is running
t.type(body, 'object');
t.end();
},
err => {
// If SDM is not running error is expected, continue
t.true(typeof err === 'object' || typeof err === 'undefined');
t.end();
}
);
});