mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
teste(cloudcmd) replaceDist: coverage
This commit is contained in:
parent
81262a0711
commit
69807a729d
2 changed files with 52 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ const {
|
|||
_getPrefix,
|
||||
_authCheck,
|
||||
_replacePrefix,
|
||||
_replaceDist,
|
||||
} = cloudcmd;
|
||||
|
||||
test('cloudcmd: args: no', (t) => {
|
||||
|
|
@ -89,6 +90,33 @@ test('cloudcmd: replacePrefix', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: replaceDist', (t) => {
|
||||
const url = '/dist/hello';
|
||||
const result = _replaceDist(url);
|
||||
const expected = '/dist-dev/hello';
|
||||
|
||||
t.equal(result, expected, 'should equal');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: replaceDist: !isDev', (t) => {
|
||||
const url = '/dist/hello';
|
||||
const cloudcmdPath = DIR + 'cloudcmd';
|
||||
|
||||
const reset = cleanNodeEnv();
|
||||
|
||||
clean(cloudcmdPath);
|
||||
const {_replaceDist} = require(cloudcmdPath);
|
||||
|
||||
const result = _replaceDist(url);
|
||||
const expected = '/dist-dev/hello';
|
||||
|
||||
reset();
|
||||
|
||||
t.equal(result, expected, 'should equal');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: authCheck: success', (t) => {
|
||||
const auth = config('auth');
|
||||
const success = sinon.stub();
|
||||
|
|
@ -197,3 +225,18 @@ function credentials() {
|
|||
return set(reset);
|
||||
}
|
||||
|
||||
function clean(path) {
|
||||
delete require.cache[require.resolve(path)];
|
||||
}
|
||||
|
||||
function cleanNodeEnv() {
|
||||
const {NODE_ENV} = process.env;
|
||||
process.env.NODE_ENV = '';
|
||||
|
||||
const reset = () => {
|
||||
process.env.NODE_ENV = NODE_ENV;
|
||||
};
|
||||
|
||||
return reset;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue