mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature: server: columns: get rid of mock-require
This commit is contained in:
parent
46c8accd84
commit
98d3a4cc56
41 changed files with 233 additions and 215 deletions
|
|
@ -1,8 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
const process = require('process');
|
||||
const http = require('http');
|
||||
const os = require('os');
|
||||
const process = require('node:process');
|
||||
const http = require('node:http');
|
||||
const os = require('node:os');
|
||||
|
||||
const express = require('express');
|
||||
const io = require('socket.io');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const fs = require('node:fs');
|
||||
const tryCatch = require('try-catch');
|
||||
|
||||
const DIR = `${__dirname}/../../`;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const {mkdirSync} = require('fs');
|
||||
const {join} = require('path');
|
||||
const {mkdirSync} = require('node:fs');
|
||||
const {join} = require('node:path');
|
||||
const test = require('supertape');
|
||||
const rimraf = require('rimraf');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const fs = require('node:fs');
|
||||
|
||||
const test = require('supertape');
|
||||
const {Volume} = require('memfs');
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const {join} = require('path');
|
||||
const {promisify} = require('util');
|
||||
const fs = require('node:fs');
|
||||
const {join} = require('node:path');
|
||||
const {promisify} = require('node:util');
|
||||
|
||||
const {reRequire} = require('mock-require');
|
||||
const test = require('supertape');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const fs = require('node:fs');
|
||||
|
||||
const test = require('supertape');
|
||||
const {Volume} = require('memfs');
|
||||
|
|
@ -19,45 +19,45 @@ test('cloudcmd: rest: rename', async (t) => {
|
|||
'/fixture/mv.txt': 'hello',
|
||||
'/fixture/tmp/a.txt': 'a',
|
||||
};
|
||||
|
||||
|
||||
const vol = Volume.fromJSON(volume, '/');
|
||||
|
||||
|
||||
const unionFS = ufs
|
||||
.use(vol)
|
||||
.use(fs);
|
||||
|
||||
mockRequire('fs', unionFS);
|
||||
|
||||
|
||||
mockRequire('node:fs', unionFS);
|
||||
|
||||
reRequire('@cloudcmd/rename-files');
|
||||
reRequire('@cloudcmd/move-files');
|
||||
reRequire(restPath);
|
||||
|
||||
|
||||
const cloudcmd = reRequire(cloudcmdPath);
|
||||
const {createConfigManager} = cloudcmd;
|
||||
const configManager = createConfigManager();
|
||||
|
||||
|
||||
configManager('auth', false);
|
||||
configManager('root', '/');
|
||||
|
||||
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
configManager,
|
||||
});
|
||||
|
||||
|
||||
const files = {
|
||||
from: '/fixture/mv.txt',
|
||||
to: '/fixture/tmp/mv.txt',
|
||||
};
|
||||
|
||||
|
||||
const {body} = await request.put(`/api/v1/rename`, {
|
||||
body: files,
|
||||
});
|
||||
|
||||
mockRequire.stop('fs');
|
||||
|
||||
|
||||
mockRequire.stopAll();
|
||||
|
||||
const expected = 'rename: ok("{"from":"/fixture/mv.txt","to":"/fixture/tmp/mv.txt"}")';
|
||||
|
||||
|
||||
stopAll();
|
||||
|
||||
|
||||
t.equal(body, expected, 'should move');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -65,23 +65,23 @@ test('cloudcmd: rest: rename', async (t) => {
|
|||
test('cloudcmd: rest: rename: no from', async (t) => {
|
||||
const cloudcmd = reRequire(cloudcmdPath);
|
||||
const {createConfigManager} = cloudcmd;
|
||||
|
||||
|
||||
const configManager = createConfigManager();
|
||||
configManager('auth', false);
|
||||
configManager('root', '/');
|
||||
|
||||
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
configManager,
|
||||
});
|
||||
|
||||
|
||||
const files = {};
|
||||
|
||||
|
||||
const {body} = await request.put(`/api/v1/rename`, {
|
||||
body: files,
|
||||
});
|
||||
|
||||
|
||||
const expected = '"from" should be filled';
|
||||
|
||||
|
||||
t.equal(body, expected);
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -89,25 +89,25 @@ test('cloudcmd: rest: rename: no from', async (t) => {
|
|||
test('cloudcmd: rest: rename: no to', async (t) => {
|
||||
const cloudcmd = reRequire(cloudcmdPath);
|
||||
const {createConfigManager} = cloudcmd;
|
||||
|
||||
|
||||
const configManager = createConfigManager();
|
||||
configManager('auth', false);
|
||||
configManager('root', '/');
|
||||
|
||||
|
||||
const {request} = serveOnce(cloudcmd, {
|
||||
configManager,
|
||||
});
|
||||
|
||||
|
||||
const files = {
|
||||
from: '/',
|
||||
};
|
||||
|
||||
|
||||
const {body} = await request.put(`/api/v1/rename`, {
|
||||
body: files,
|
||||
});
|
||||
|
||||
|
||||
const expected = '"to" should be filled';
|
||||
|
||||
|
||||
t.equal(body, expected);
|
||||
t.end();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const process = require('process');
|
||||
const test = require('supertape');
|
||||
const fs = require('fs');
|
||||
const {reRequire} = require('mock-require');
|
||||
const columnsPath = '../../server/columns';
|
||||
|
||||
test('columns: prod', (t) => {
|
||||
const {NODE_ENV} = process.env;
|
||||
|
||||
process.env.NODE_ENV = '';
|
||||
const columns = reRequire(columnsPath);
|
||||
|
||||
process.env.NODE_ENV = NODE_ENV;
|
||||
|
||||
t.equal(columns[''], '');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('columns: dev', (t) => {
|
||||
const {NODE_ENV} = process.env;
|
||||
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
const columns = reRequire(columnsPath);
|
||||
const css = fs.readFileSync(`${__dirname}/../../css/columns/name-size-date.css`, 'utf8');
|
||||
|
||||
process.env.NODE_ENV = NODE_ENV;
|
||||
|
||||
t.equal(columns['name-size-date'], css);
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const {once} = require('events');
|
||||
const path = require('node:path');
|
||||
const {once} = require('node:events');
|
||||
|
||||
const test = require('supertape');
|
||||
const io = require('socket.io-client');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const process = require('process');
|
||||
const process = require('node:process');
|
||||
const test = require('supertape');
|
||||
const env = require('../../server/env');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const {join} = require('path');
|
||||
const {join} = require('node:path');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const cloudcmdPath = join(__dirname, '..', '..');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue