update
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import Stream from 'stream';
|
||||
import https from 'https';
|
||||
import getDistVersion from './getDistVersion';
|
||||
|
||||
jest.mock('https', () => ({
|
||||
get: jest.fn(),
|
||||
}));
|
||||
|
||||
test('Valid response returns version', async () => {
|
||||
const st = new Stream();
|
||||
(https.get as jest.Mock).mockImplementation((url, cb) => {
|
||||
cb(st);
|
||||
|
||||
st.emit('data', '{"latest":"1.0.0"}');
|
||||
st.emit('end');
|
||||
});
|
||||
|
||||
const version = await getDistVersion('test', 'latest');
|
||||
|
||||
expect(version).toEqual('1.0.0');
|
||||
});
|
||||
|
||||
test('Invalid response throws error', async () => {
|
||||
const st = new Stream();
|
||||
(https.get as jest.Mock).mockImplementation((url, cb) => {
|
||||
cb(st);
|
||||
|
||||
st.emit('data', 'some invalid json');
|
||||
st.emit('end');
|
||||
});
|
||||
|
||||
expect(getDistVersion('test', 'latest')).rejects.toThrow(
|
||||
'Could not parse version response'
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
var parse = require('./parse');
|
||||
|
||||
/**
|
||||
* Converts a string to command line args, in particular
|
||||
* groups together quoted values.
|
||||
* This is a utility function to allow calling nodemon as a required
|
||||
* library, but with the CLI args passed in (instead of an object).
|
||||
*
|
||||
* @param {String} string
|
||||
* @return {Array}
|
||||
*/
|
||||
function stringToArgs(string) {
|
||||
var args = [];
|
||||
|
||||
var parts = string.split(' ');
|
||||
var length = parts.length;
|
||||
var i = 0;
|
||||
var open = false;
|
||||
var grouped = '';
|
||||
var lead = '';
|
||||
|
||||
for (; i < length; i++) {
|
||||
lead = parts[i].substring(0, 1);
|
||||
if (lead === '"' || lead === '\'') {
|
||||
open = lead;
|
||||
grouped = parts[i].substring(1);
|
||||
} else if (open && parts[i].slice(-1) === open) {
|
||||
open = false;
|
||||
grouped += ' ' + parts[i].slice(0, -1);
|
||||
args.push(grouped);
|
||||
} else if (open) {
|
||||
grouped += ' ' + parts[i];
|
||||
} else {
|
||||
args.push(parts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
parse: function (argv) {
|
||||
if (typeof argv === 'string') {
|
||||
argv = stringToArgs(argv);
|
||||
}
|
||||
|
||||
return parse(argv);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2012-2019 Thorsten Lorenz, Paul Miller (https://paulmillr.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
/** @type {import('./isNaN')} */
|
||||
module.exports = Number.isNaN || function isNaN(a) {
|
||||
return a !== a;
|
||||
};
|
||||
Reference in New Issue
Block a user