mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
test(cloudcmd) add clear-module, mock-require
This commit is contained in:
parent
41e0d3ad8b
commit
1887b0e13c
5 changed files with 15 additions and 35 deletions
|
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const test = require('tape');
|
||||
const clean = require('clear-module');
|
||||
const DIR = '../../';
|
||||
const UtilPath = DIR + 'common/util';
|
||||
const Util = require(UtilPath);
|
||||
|
|
@ -146,7 +147,3 @@ test('util: scope', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
function clean(path) {
|
||||
delete require.cache[require.resolve(path)];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ const test = require('tape');
|
|||
const diff = require('sinon-called-with-diff');
|
||||
const sinon = diff(require('sinon'));
|
||||
const currify = require('currify');
|
||||
const clean = require('clear-module');
|
||||
|
||||
const DIR = '../../server/';
|
||||
const cloudcmd = require(DIR + 'cloudcmd');
|
||||
|
|
@ -225,10 +226,6 @@ 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 = '';
|
||||
|
|
|
|||
|
|
@ -1,25 +1,27 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
const test = require('tape');
|
||||
|
||||
const diff = require('sinon-called-with-diff');
|
||||
const sinon = diff(require('sinon'));
|
||||
|
||||
const dir = path.join(__dirname, '..', '..', 'server');
|
||||
const dir = path.join('..', '..', 'server');
|
||||
|
||||
const pathConfig = path.join(dir, 'config');
|
||||
const pathRoot = `${dir}/root`;
|
||||
|
||||
const clean = (name) => {
|
||||
delete require.cache[require.resolve(name)];
|
||||
};
|
||||
const stub = require('mock-require');
|
||||
const clean = require('clear-module');
|
||||
|
||||
test('cloudcmd: root: config', (t) => {
|
||||
clean(pathRoot);
|
||||
|
||||
const originalConfig = require(pathConfig);
|
||||
const config = sinon.stub().returns(false);
|
||||
const originalConfig = stub(pathConfig, config);
|
||||
|
||||
stub(pathConfig, config);
|
||||
|
||||
const root = require(pathRoot);
|
||||
|
||||
root('hello');
|
||||
|
|
@ -57,12 +59,3 @@ test('cloudcmd: root: mellow', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
function stub(name, data) {
|
||||
const resolved = require.resolve(name);
|
||||
const {exports} = require.cache[resolved];
|
||||
|
||||
require.cache[resolved].exports = data;
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ const routePath = '../../server/route';
|
|||
const route = require(routePath);
|
||||
const before = require('../before');
|
||||
|
||||
const clean = require('clear-module');
|
||||
|
||||
const warp = (fn, ...a) => (...b) => fn(...b, ...a);
|
||||
const _pullout = promisify(pullout);
|
||||
|
||||
|
|
@ -310,7 +312,3 @@ test('cloudcmd: route: realpath: error', (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
function clean(path) {
|
||||
delete require.cache[require.resolve(path)];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ const mock = require('mock-require');
|
|||
const diff = require('sinon-called-with-diff');
|
||||
const sinon = diff(require('sinon'));
|
||||
|
||||
const stub = require('mock-require');
|
||||
const clean = require('clear-module');
|
||||
|
||||
const configPath = '../../server/config';
|
||||
const terminalPath = '../../server/terminal';
|
||||
|
||||
|
|
@ -88,11 +91,3 @@ test('cloudcmd: terminal: no arg', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
function clean(path) {
|
||||
delete require.cache[require.resolve(path)];
|
||||
}
|
||||
|
||||
function stub(name, fn) {
|
||||
require.cache[require.resolve(name)].exports = fn;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue