mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
use jest for CI
This commit is contained in:
17
test/lib/httpsServerMgr.spec.js
Normal file
17
test/lib/httpsServerMgr.spec.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const httpsServerMgr = require('../../lib/httpsServerMgr');
|
||||
|
||||
describe('httpsServerMgr', () => {
|
||||
it('get https server', async () => {
|
||||
const serverMgr = new httpsServerMgr({
|
||||
hostname: '127.0.0.1',
|
||||
handler: () => {
|
||||
console.log('this is handler');
|
||||
},
|
||||
wsHandler: () => {
|
||||
console.log('this is handler');
|
||||
},
|
||||
});
|
||||
await serverMgr.getSharedHttpsServer();
|
||||
serverMgr.close();
|
||||
});
|
||||
});
|
||||
42
test/lib/ruleLoader.spec.js
Normal file
42
test/lib/ruleLoader.spec.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const ruleLoader = require('../../lib/ruleLoader');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const localModulePath = path.join(__dirname, '../fixtures/someRule.js');
|
||||
describe('ruleLoader', () => {
|
||||
it('should successfully cache a remote file', async () => {
|
||||
await ruleLoader.cacheRemoteFile('https://cdn.bootcss.com/lodash.js/4.16.4/lodash.min.js')
|
||||
.then(filePath => {
|
||||
let content;
|
||||
if (filePath) {
|
||||
content = fs.readFileSync(filePath, { encoding: 'utf8' });
|
||||
}
|
||||
expect(content && content.length > 100).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should load a local module ../util/CommonUtil', async () => {
|
||||
await ruleLoader.loadLocalPath(localModulePath)
|
||||
.then(module => {
|
||||
expect(module.foo).not.toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should smart load a remote module', done => {
|
||||
ruleLoader.requireModule('https://cdn.bootcss.com/lodash.js/4.16.4/lodash.min.js')
|
||||
.then(module => {
|
||||
expect(module.VERSION).toEqual('4.16.4');
|
||||
done();
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it('should smart load a local module', done => {
|
||||
ruleLoader.requireModule(localModulePath)
|
||||
.then(module => {
|
||||
expect(module.foo).not.toBeUndefined();
|
||||
done();
|
||||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
});
|
||||
20
test/lib/util.spec.js
Normal file
20
test/lib/util.spec.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const util = require('../../lib/util');
|
||||
|
||||
describe('utils', () => {
|
||||
it('getFreePort', async () => {
|
||||
const count = 100;
|
||||
const tasks = [];
|
||||
for (let i = 1; i <= count; i++) {
|
||||
tasks.push(util.getFreePort());
|
||||
}
|
||||
await Promise.all(tasks)
|
||||
.then((results) => {
|
||||
// ensure ports are unique
|
||||
const portMap = {};
|
||||
results.map((portNumber) => {
|
||||
portMap[portNumber] = true;
|
||||
});
|
||||
expect(Object.keys(portMap).length).toEqual(count);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user