diff --git a/package.json b/package.json index b8d652a754..17cf9be6c1 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,6 @@ "rds": "^0.1.0", "rimraf": "^2.6.1", "runscript": "^1.2.1", - "should": "^11.2.1", "spy": "^1.0.0", "supertest": "^3.0.0", "taffydb": "^2.7.3", diff --git a/test/app/extend/agent.test.js b/test/app/extend/agent.test.js index 03d8d63964..e032519a91 100644 --- a/test/app/extend/agent.test.js +++ b/test/app/extend/agent.test.js @@ -1,5 +1,7 @@ 'use strict'; +const assert = require('assert'); + const mm = require('egg-mock'); const utils = require('../../utils'); @@ -16,12 +18,12 @@ describe('test/app/extend/agent.test.js', () => { it('should add singleton success', function* () { let config = yield app.agent.dataService.get('second').getConfig(); - config.foo.should.equal('bar'); - config.foo2.should.equal('bar2'); + assert(config.foo === 'bar'); + assert(config.foo2 === 'bar2'); const ds = app.agent.dataService.createInstance({ foo: 'barrr' }); config = yield ds.getConfig(); - config.foo.should.equal('barrr'); + assert(config.foo === 'barrr'); }); }); diff --git a/test/app/extend/application.test.js b/test/app/extend/application.test.js index cff8438679..171c9f2c60 100644 --- a/test/app/extend/application.test.js +++ b/test/app/extend/application.test.js @@ -1,5 +1,7 @@ 'use strict'; +const assert = require('assert'); + const request = require('supertest'); const sleep = require('mz-modules/sleep'); const fs = require('fs'); @@ -16,19 +18,19 @@ describe('test/app/extend/application.test.js', () => { after(() => app.close()); it('should alias app.logger => app.loggers.logger', () => { - app.logger.should.equal(app.loggers.logger); + assert(app.logger === app.loggers.logger); }); it('should alias app.coreLooger => app.loggers.coreLooger', () => { - app.coreLogger.should.equal(app.loggers.coreLogger); + assert(app.coreLogger === app.loggers.coreLogger); }); it('should alias app.getLogger(\'coreLogger\') => app.loggers.coreLooger', () => { - app.getLogger('coreLogger').should.equal(app.loggers.coreLogger); + assert(app.getLogger('coreLogger') === app.loggers.coreLogger); }); it('should alias app.getLogger(\'noexist\') => null', () => { - (app.getLogger('noexist') === null).should.be.true(); + assert(app.getLogger('noexist') === null); }); }); @@ -41,13 +43,13 @@ describe('test/app/extend/application.test.js', () => { after(() => app.close()); it('should inspect app properties', () => { - app.inspect().should.have.properties([ + assert([ 'name', 'baseDir', 'env', 'subdomainOffset', 'controller', 'middlewares', 'serviceClasses', 'config', 'httpclient', 'loggers', - ]); - app.inspect().name.should.equal('demo'); + ].every(p => Object.prototype.hasOwnProperty.call(app.inspect(), p))); + assert(app.inspect().name === 'demo'); }); }); @@ -97,10 +99,10 @@ describe('test/app/extend/application.test.js', () => { }, url: '/foobar?ok=1', }); - ctx.ip.should.equal('10.0.0.1'); - ctx.url.should.equal('/foobar?ok=1'); - ctx.socket.remoteAddress.should.equal('10.0.0.1'); - ctx.socket.remotePort.should.equal(7001); + assert(ctx.ip === '10.0.0.1'); + assert(ctx.url === '/foobar?ok=1'); + assert(ctx.socket.remoteAddress === '10.0.0.1'); + assert(ctx.socket.remotePort === 7001); }); }); @@ -114,12 +116,12 @@ describe('test/app/extend/application.test.js', () => { it('should add singleton success', function* () { let config = yield app.dataService.get('first').getConfig(); - config.foo.should.equal('bar'); - config.foo1.should.equal('bar1'); + assert(config.foo === 'bar'); + assert(config.foo1 === 'bar1'); const ds = app.dataService.createInstance({ foo: 'barrr' }); config = yield ds.getConfig(); - config.foo.should.equal('barrr'); + assert(config.foo === 'barrr'); }); }); @@ -139,9 +141,10 @@ describe('test/app/extend/application.test.js', () => { yield sleep(5000); const logdir = app.config.logger.dir; const log = fs.readFileSync(path.join(logdir, 'ctx-background-web.log'), 'utf8'); - log.should.match(/mock background run at app result file size: \d+/); - fs.readFileSync(path.join(logdir, 'egg-web.log'), 'utf8') - .should.match(/\[egg:background] task:saveUserInfo success \(\d+ms\)/); + assert(/mock background run at app result file size: \d+/.test(log)); + assert( + /\[egg:background] task:saveUserInfo success \(\d+ms\)/.test(fs.readFileSync(path.join(logdir, 'egg-web.log'), 'utf8')) + ); }); }); }); diff --git a/test/app/extend/context.test.js b/test/app/extend/context.test.js index d10133591c..b321483eea 100644 --- a/test/app/extend/context.test.js +++ b/test/app/extend/context.test.js @@ -29,18 +29,18 @@ describe('test/app/extend/context.test.js', () => { yield sleep(5000); const errorContent = fs.readFileSync(path.join(logdir, 'common-error.log'), 'utf8'); - errorContent.should.containEql('nodejs.Error: error foo'); - errorContent.should.containEql('nodejs.Error: core error foo'); + assert(errorContent.includes('nodejs.Error: error foo')); + assert(errorContent.includes('nodejs.Error: core error foo')); const loggerContent = fs.readFileSync(path.join(logdir, 'demo-web.log'), 'utf8'); // loggerContent.should.containEql('debug foo'); - loggerContent.should.containEql('info foo'); - loggerContent.should.containEql('warn foo'); + assert(loggerContent.includes('info foo')); + assert(loggerContent.includes('warn foo')); const coreLoggerContent = fs.readFileSync(path.join(logdir, 'egg-web.log'), 'utf8'); // coreLoggerContent.should.containEql('core debug foo'); - coreLoggerContent.should.containEql('core info foo'); - coreLoggerContent.should.containEql('core warn foo'); + assert(coreLoggerContent.includes('core info foo')); + assert(coreLoggerContent.includes('core warn foo')); }); it('env=unittest: level => info', function* () { @@ -61,19 +61,19 @@ describe('test/app/extend/context.test.js', () => { yield sleep(5000); const errorContent = fs.readFileSync(path.join(logdir, 'common-error.log'), 'utf8'); - errorContent.should.containEql('nodejs.Error: error foo'); - errorContent.should.containEql('nodejs.Error: core error foo'); - errorContent.should.match(/\[123123\/[\d.]+\/-\/\d+ms GET \/logger\?message=foo]/); + assert(errorContent.includes('nodejs.Error: error foo')); + assert(errorContent.includes('nodejs.Error: core error foo')); + assert(/\[123123\/[\d.]+\/-\/\d+ms GET \/logger\?message=foo]/.test(errorContent)); const loggerContent = fs.readFileSync(path.join(logdir, 'demo-web.log'), 'utf8'); - loggerContent.should.not.containEql('debug foo'); - loggerContent.should.containEql('info foo'); - loggerContent.should.containEql('warn foo'); + assert(!loggerContent.includes('debug foo')); + assert(loggerContent.includes('info foo')); + assert(loggerContent.includes('warn foo')); const coreLoggerContent = fs.readFileSync(path.join(logdir, 'egg-web.log'), 'utf8'); - coreLoggerContent.should.not.containEql('core debug foo'); - coreLoggerContent.should.containEql('core info foo'); - coreLoggerContent.should.containEql('core warn foo'); + assert(!coreLoggerContent.includes('core debug foo')); + assert(coreLoggerContent.includes('core info foo')); + assert(coreLoggerContent.includes('core warn foo')); }); it('env=prod: level => info', function* () { @@ -90,18 +90,18 @@ describe('test/app/extend/context.test.js', () => { yield sleep(5000); const errorContent = fs.readFileSync(path.join(logdir, 'common-error.log'), 'utf8'); - errorContent.should.containEql('nodejs.Error: error foo'); - errorContent.should.containEql('nodejs.Error: core error foo'); + assert(errorContent.includes('nodejs.Error: error foo')); + assert(errorContent.includes('nodejs.Error: core error foo')); const loggerContent = fs.readFileSync(path.join(logdir, 'demo-web.log'), 'utf8'); - loggerContent.should.not.containEql('debug foo'); - loggerContent.should.containEql('info foo'); - loggerContent.should.containEql('warn foo'); + assert(!loggerContent.includes('debug foo')); + assert(loggerContent.includes('info foo')); + assert(loggerContent.includes('warn foo')); const coreLoggerContent = fs.readFileSync(path.join(logdir, 'egg-web.log'), 'utf8'); - coreLoggerContent.should.not.containEql('core debug foo'); - coreLoggerContent.should.containEql('core info foo'); - coreLoggerContent.should.containEql('core warn foo'); + assert(!coreLoggerContent.includes('core debug foo')); + assert(coreLoggerContent.includes('core info foo')); + assert(coreLoggerContent.includes('core warn foo')); }); }); @@ -126,7 +126,9 @@ describe('test/app/extend/context.test.js', () => { yield sleep(100); const logPath = utils.getFilepath('apps/get-logger/logs/get-logger/a.log'); - fs.readFileSync(logPath, 'utf8').should.match(/\[-\/127.0.0.1\/-\/\d+ms GET \/logger] aaa/); + assert( + /\[-\/127.0.0.1\/-\/\d+ms GET \/logger] aaa/.test(fs.readFileSync(logPath, 'utf8')) + ); }); }); @@ -239,9 +241,10 @@ describe('test/app/extend/context.test.js', () => { yield sleep(5000); const logdir = app.config.logger.dir; const log = fs.readFileSync(path.join(logdir, 'ctx-background-web.log'), 'utf8'); - log.should.match(/background run result file size: \d+/); - fs.readFileSync(path.join(logdir, 'egg-web.log'), 'utf8') - .should.match(/\[egg:background] task:saveUserInfo success \(\d+ms\)/); + assert(/background run result file size: \d+/.test(log)); + assert( + /\[egg:background] task:saveUserInfo success \(\d+ms\)/.test(fs.readFileSync(path.join(logdir, 'egg-web.log'), 'utf8')) + ); }); it('should run background task error', function* () { @@ -253,9 +256,10 @@ describe('test/app/extend/context.test.js', () => { yield sleep(5000); const logdir = app.config.logger.dir; const log = fs.readFileSync(path.join(logdir, 'common-error.log'), 'utf8'); - log.should.match(/ENOENT: no such file or directory/); - fs.readFileSync(path.join(logdir, 'egg-web.log'), 'utf8') - .should.match(/\[egg:background] task:mockError fail \(\d+ms\)/); + assert(/ENOENT: no such file or directory/.test(log)); + assert( + /\[egg:background] task:mockError fail \(\d+ms\)/.test(fs.readFileSync(path.join(logdir, 'egg-web.log'), 'utf8')) + ); }); }); @@ -272,13 +276,13 @@ describe('test/app/extend/context.test.js', () => { const localServer = yield utils.startLocalServer(); const context = app.mockContext(); const res = yield context.curl(`${localServer}/foo/bar`); - res.status.should.equal(200); + assert(res.status === 200); }); it('should curl as promise ok', () => { return utils.startLocalServer() .then(localServer => app.mockContext().curl(`${localServer}/foo/bar`)) - .then(res => res.status.should.equal(200)); + .then(res => assert(res.status === 200)); }); }); @@ -311,8 +315,8 @@ describe('test/app/extend/context.test.js', () => { const context = app.mockContext(); context.locals = { a: 'a', b: 'b' }; context.state = { a: 'aa', c: 'cc' }; - context.state.should.eql({ a: 'aa', b: 'b', c: 'cc' }); - context.state.should.equal(context.locals); + assert.deepEqual(context.state, { a: 'aa', b: 'b', c: 'cc' }); + assert(context.state === context.locals); }); }); diff --git a/test/app/extend/request.test.js b/test/app/extend/request.test.js index b45ad2d546..c4b9ca5ed0 100644 --- a/test/app/extend/request.test.js +++ b/test/app/extend/request.test.js @@ -25,72 +25,72 @@ describe('test/app/extend/request.test.js', () => { describe('req.host', () => { it('should return host with port', function* () { mm(req.header, 'host', 'foo.com:3000'); - req.hostname.should.equal('foo.com'); + assert(req.hostname === 'foo.com'); }); it('should return "" when no host present', function* () { - req.host.should.be.a.String; - req.host.should.equal(''); + assert(typeof req.host === 'string'); + assert(req.host === ''); }); it('should return host from X-Forwarded-Host header', function* () { mm(req.header, 'x-forwarded-host', 'foo.com'); - req.host.should.be.a.String; - req.host.should.equal('foo.com'); + assert(typeof req.host === 'string'); + assert(req.host === 'foo.com'); }); it('should return host from Host header when proxy=false', function* () { mm(app.config, 'proxy', false); mm(req.header, 'x-forwarded-host', 'foo.com'); mm(req.header, 'host', 'bar.com'); - req.host.should.be.a.String; - req.host.should.equal('bar.com'); + assert(typeof req.host === 'string'); + assert(req.host === 'bar.com'); }); }); describe('req.hostname', () => { it('should return hostname with port', function* () { mm(req.header, 'host', 'foo.com:3000'); - req.hostname.should.equal('foo.com'); + assert(req.hostname === 'foo.com'); }); it('should return "" when no host present', function* () { - req.hostname.should.be.a.String; - req.hostname.should.equal(''); + assert(typeof req.hostname === 'string'); + assert(req.hostname === ''); }); }); describe('req.ip', () => { it('should return ipv4', function* () { mm(req.socket, 'remoteAddress', '::ffff:127.0.0.1'); - req.ip.should.equal('127.0.0.1'); - req.ip.should.equal('127.0.0.1'); + assert(req.ip === '127.0.0.1'); + assert(req.ip === '127.0.0.1'); }); }); describe('req.ips', () => { it('should used x-forwarded-for', function* () { mm(req.header, 'x-forwarded-for', '127.0.0.1,127.0.0.2'); - req.ips.should.eql([ '127.0.0.1', '127.0.0.2' ]); + assert.deepEqual(req.ips, [ '127.0.0.1', '127.0.0.2' ]); }); it('should used x-real-ip', function* () { mm(app.config, 'ipHeaders', 'X-Forwarded-For, X-Real-IP'); mm(req.header, 'x-forwarded-for', ''); mm(req.header, 'x-real-ip', '127.0.0.1,127.0.0.2'); - req.ips.should.eql([ '127.0.0.1', '127.0.0.2' ]); + assert.deepEqual(req.ips, [ '127.0.0.1', '127.0.0.2' ]); }); it('should return []', function* () { mm(req.header, 'x-forwarded-for', ''); mm(req.header, 'x-real-ip', ''); - req.ips.should.eql([]); + assert.deepEqual(req.ips, []); }); it('should return [] when proxy=false', function* () { mm(app.config, 'proxy', false); mm(req.header, 'x-forwarded-for', '127.0.0.1,127.0.0.2'); - req.ips.should.eql([]); + assert.deepEqual(req.ips, []); }); }); @@ -158,7 +158,7 @@ describe('test/app/extend/request.test.js', () => { describe('this.query[key] => String', () => { function expectQuery(querystring, query) { mm(req, 'querystring', querystring); - req.query.should.eql(query); + assert.deepEqual(req.query, query); mm.restore(); } @@ -189,7 +189,7 @@ describe('test/app/extend/request.test.js', () => { describe('this.queries[key] => Array', () => { function expectQueries(querystring, query) { mm(req, 'querystring', querystring); - req.queries.should.eql(query); + assert.deepEqual(req.queries, query); mm.restore(); } @@ -261,25 +261,25 @@ describe('test/app/extend/request.test.js', () => { describe('this.query = obj', () => { it('should set query with object', () => { mm(req, 'querystring', 'a=c'); - req.query.should.eql({ a: 'c' }); + assert.deepEqual(req.query, { a: 'c' }); req.query = {}; - req.query.should.eql({}); - req.querystring.should.equal(''); + assert.deepEqual(req.query, {}); + assert(req.querystring === ''); req.query = { foo: 'bar' }; - req.query.should.eql({ foo: 'bar' }); - req.querystring.should.equal('foo=bar'); + assert.deepEqual(req.query, { foo: 'bar' }); + assert(req.querystring === 'foo=bar'); req.query = { array: [ 1, 2 ] }; - req.query.should.eql({ array: '1' }); - req.querystring.should.equal('array=1&array=2'); + assert.deepEqual(req.query, { array: '1' }); + assert(req.querystring === 'array=1&array=2'); }); }); describe('request.acceptJSON', () => { it('should true when url path ends with .json', function* () { mm(req, 'path', 'hello.json'); - req.acceptJSON.should.equal(true); + assert(req.acceptJSON === true); }); it('should true when response is json', function* () { @@ -290,7 +290,7 @@ describe('test/app/extend/request.test.js', () => { url: '/', }); context.type = 'application/json'; - context.request.acceptJSON.should.equal(true); + assert(context.request.acceptJSON === true); }); it('should true when accept json', function* () { @@ -300,7 +300,7 @@ describe('test/app/extend/request.test.js', () => { }, url: '/', }); - context.request.acceptJSON.should.equal(true); + assert(context.request.acceptJSON === true); }); it('should false when do not accept json', function* () { @@ -311,7 +311,7 @@ describe('test/app/extend/request.test.js', () => { url: '/', }); const request = context.request; - request.acceptJSON.should.equal(false); + assert(request.acceptJSON === false); }); }); @@ -336,7 +336,7 @@ describe('test/app/extend/request.test.js', () => { urllib.request(`${host}/?p=a,b&p=b,c&a[foo]=bar`, { dataType: 'json', }, (err, body) => { - body.should.eql({ + assert.deepEqual(body, { query: { p: 'a,b', 'a[foo]': 'bar' }, queries: { p: [ 'a,b', 'b,c' ], 'a[foo]': [ 'bar' ] }, }); @@ -348,7 +348,7 @@ describe('test/app/extend/request.test.js', () => { urllib.request(`${host}/?p=a,b&p=b,c&${encodeURIComponent('a[foo]')}=bar`, { dataType: 'json', }, (err, body) => { - body.should.eql({ + assert.deepEqual(body, { query: { p: 'a,b', 'a[foo]': 'bar' }, queries: { p: [ 'a,b', 'b,c' ], 'a[foo]': [ 'bar' ] }, }); diff --git a/test/app/middleware/body_parser.test.js b/test/app/middleware/body_parser.test.js index 5cf40f8c5c..866eeeca61 100644 --- a/test/app/middleware/body_parser.test.js +++ b/test/app/middleware/body_parser.test.js @@ -1,7 +1,7 @@ 'use strict'; +const assert = require('assert'); const querystring = require('querystring'); -const should = require('should'); const request = require('supertest'); const utils = require('../../utils'); @@ -16,10 +16,10 @@ describe('test/app/middleware/body_parser.test.js', () => { request(app.callback()) .get('/test/body_parser/user') .expect(200, (err, res) => { - should.not.exist(err); + assert(!err); csrf = res.body.csrf || ''; cookies = res.headers['set-cookie'].join(';'); - should.exist(csrf); + assert(csrf); done(); }); }); diff --git a/test/app/middleware/site_file.test.js b/test/app/middleware/site_file.test.js index dd2366d00a..7d8c8e4583 100644 --- a/test/app/middleware/site_file.test.js +++ b/test/app/middleware/site_file.test.js @@ -1,6 +1,5 @@ 'use strict'; -const should = require('should'); const request = require('supertest'); const assert = require('assert'); const utils = require('../../utils'); @@ -91,9 +90,9 @@ describe('test/app/middleware/site_file.test.js', () => { return request(app.callback()) .get('/favicon.ico') .expect(302, (err, res) => { - should.not.exist(err); - should.not.exist(res.headers['set-cookie']); - res.headers.location.should.eql('https://eggjs.org/favicon.ico'); + assert(!err); + assert(!res.headers['set-cookie']); + assert(res.headers.location === 'https://eggjs.org/favicon.ico'); }); }); }); diff --git a/test/lib/core/config/config.test.js b/test/lib/core/config/config.test.js index 7c8910f5fa..cd90ffb9b7 100644 --- a/test/lib/core/config/config.test.js +++ b/test/lib/core/config/config.test.js @@ -1,5 +1,7 @@ 'use strict'; +const assert = require('assert'); + const mm = require('egg-mock'); const utils = require('../../../utils'); @@ -14,6 +16,6 @@ describe('test/lib/core/config/config.test.js', () => { afterEach(mm.restore); it('should return config.name', () => { - app.config.name.should.equal('demo'); + assert(app.config.name === 'demo'); }); }); diff --git a/test/lib/core/httpclient.test.js b/test/lib/core/httpclient.test.js index ef50b32345..8da7387804 100644 --- a/test/lib/core/httpclient.test.js +++ b/test/lib/core/httpclient.test.js @@ -1,5 +1,7 @@ 'use strict'; +const assert = require('assert'); + const mm = require('egg-mock'); const createHttpclient = require('../../../lib/core/httpclient'); const utils = require('../../utils'); @@ -31,8 +33,8 @@ describe('test/lib/core/httpclient.test.js', () => { dataType: 'text', }; client.once('response', info => { - info.req.options.headers['mock-traceid'].should.equal('mock-traceid'); - info.req.options.headers['mock-rpcid'].should.equal('mock-rpcid'); + assert(info.req.options.headers['mock-traceid'] === 'mock-traceid'); + assert(info.req.options.headers['mock-rpcid'] === 'mock-rpcid'); done(); }); @@ -41,8 +43,8 @@ describe('test/lib/core/httpclient.test.js', () => { it('should request callback with log', done => { client.once('response', info => { - info.req.options.headers['mock-traceid'].should.equal('mock-traceid'); - info.req.options.headers['mock-rpcid'].should.equal('mock-rpcid'); + assert(info.req.options.headers['mock-traceid'] === 'mock-traceid'); + assert(info.req.options.headers['mock-rpcid'] === 'mock-rpcid'); done(); }); @@ -54,8 +56,8 @@ describe('test/lib/core/httpclient.test.js', () => { dataType: 'text', }; client.once('response', info => { - info.req.options.headers['mock-traceid'].should.equal('mock-traceid'); - info.req.options.headers['mock-rpcid'].should.equal('mock-rpcid'); + assert(info.req.options.headers['mock-traceid'] === 'mock-traceid'); + assert(info.req.options.headers['mock-rpcid'] === 'mock-rpcid'); done(); }); @@ -67,8 +69,8 @@ describe('test/lib/core/httpclient.test.js', () => { dataType: 'text', }; client.once('response', info => { - info.req.options.headers['mock-traceid'].should.equal('mock-traceid'); - info.req.options.headers['mock-rpcid'].should.equal('mock-rpcid'); + assert(info.req.options.headers['mock-traceid'] === 'mock-traceid'); + assert(info.req.options.headers['mock-rpcid'] === 'mock-rpcid'); }); yield client.requestThunk(url, args); @@ -78,9 +80,9 @@ describe('test/lib/core/httpclient.test.js', () => { mm.http.requestError(/.*/i, null, 'mock res error'); client.once('response', info => { - info.req.options.headers['mock-traceid'].should.equal('mock-traceid'); - info.req.options.headers['mock-rpcid'].should.equal('mock-rpcid'); - info.error.message.should.containEql('mock res error'); + assert(info.req.options.headers['mock-traceid'] === 'mock-traceid'); + assert(info.req.options.headers['mock-rpcid'] === 'mock-rpcid'); + assert(info.error.message.includes('mock res error')); done(); }); diff --git a/test/lib/core/loader/config_loader.test.js b/test/lib/core/loader/config_loader.test.js index da67cb010d..3419bad1e4 100644 --- a/test/lib/core/loader/config_loader.test.js +++ b/test/lib/core/loader/config_loader.test.js @@ -1,5 +1,7 @@ 'use strict'; +const assert = require('assert'); + const path = require('path'); const mm = require('egg-mock'); const utils = require('../../../utils'); @@ -13,7 +15,7 @@ describe('test/lib/core/loader/config_loader.test.js', () => { it('should get middlewares', function* () { app = utils.app('apps/demo'); yield app.ready(); - app.config.coreMiddleware.slice(0, 6).should.eql([ + assert.deepEqual(app.config.coreMiddleware.slice(0, 6), [ 'meta', 'siteFile', 'notfound', @@ -28,7 +30,7 @@ describe('test/lib/core/loader/config_loader.test.js', () => { mm(process.env, 'EGG_SERVER_ENV', 'unittest'); app = utils.app('apps/demo'); yield app.ready(); - app.config.logger.dir.should.eql(utils.getFilepath('apps/demo/logs/demo')); + assert.deepEqual(app.config.logger.dir, utils.getFilepath('apps/demo/logs/demo')); }); it('should get logger dir when default', function* () { @@ -36,6 +38,6 @@ describe('test/lib/core/loader/config_loader.test.js', () => { mm(process.env, 'EGG_SERVER_ENV', 'default'); app = utils.app('apps/demo'); yield app.ready(); - app.config.logger.dir.should.eql(path.join(home, 'logs/demo')); + assert.deepEqual(app.config.logger.dir, path.join(home, 'logs/demo')); }); }); diff --git a/test/lib/core/loader/load_app.test.js b/test/lib/core/loader/load_app.test.js index 84494bd860..1b449cd91e 100644 --- a/test/lib/core/loader/load_app.test.js +++ b/test/lib/core/loader/load_app.test.js @@ -1,6 +1,6 @@ 'use strict'; -const should = require('should'); +const assert = require('assert'); const utils = require('../../../utils'); describe('test/lib/core/loader/load_app.test.js', () => { @@ -12,17 +12,17 @@ describe('test/lib/core/loader/load_app.test.js', () => { after(() => app.close()); it('should load app.js', () => { - app.b.should.equal('plugin b'); - app.c.should.equal('plugin c'); - app.app.should.equal('app'); + assert(app.b === 'plugin b'); + assert(app.c === 'plugin c'); + assert(app.app === 'app'); }); it('should load plugin app.js first', () => { - (app.dateB <= app.date).should.equal(true); - (app.dateC <= app.date).should.equal(true); + assert(app.dateB <= app.date === true); + assert(app.dateC <= app.date === true); }); it('should not load disable plugin', () => { - should.not.exists(app.a); + assert(!app.a); }); }); diff --git a/test/lib/core/loader/load_plugin.test.js b/test/lib/core/loader/load_plugin.test.js index 8f72ad5efd..fd8187b398 100644 --- a/test/lib/core/loader/load_plugin.test.js +++ b/test/lib/core/loader/load_plugin.test.js @@ -1,6 +1,6 @@ 'use strict'; -const should = require('should'); +const assert = require('assert'); const path = require('path'); const fs = require('fs'); const mm = require('egg-mock'); @@ -27,7 +27,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { logger, }); appLoader.loadConfig(); - appLoader.plugins.b.should.eql({ + assert.deepEqual(appLoader.plugins.b, { enable: true, name: 'b', dependencies: [], @@ -36,7 +36,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { path: path.join(baseDir, 'node_modules/b'), from: path.join(baseDir, 'config/plugin.js'), }); - appLoader.plugins.c.should.eql({ + assert.deepEqual(appLoader.plugins.c, { enable: true, name: 'c', dependencies: [], @@ -45,7 +45,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { path: path.join(baseDir, 'node_modules/c'), from: path.join(baseDir, 'config/plugin.js'), }); - appLoader.plugins.e.should.eql({ + assert.deepEqual(appLoader.plugins.e, { enable: true, name: 'e', dependencies: [ 'f' ], @@ -54,10 +54,12 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { path: path.join(baseDir, 'plugins/e'), from: path.join(baseDir, 'config/plugin.js'), }); - appLoader.plugins.onerror.path.should.equal(fs.realpathSync(path.join(EGG_BASE, 'node_modules/egg-onerror'))); - appLoader.plugins.onerror.package.should.equal('egg-onerror'); - appLoader.plugins.onerror.version.should.match(/\d+\.\d+\.\d+/); - appLoader.orderPlugins.should.be.an.Array; + assert( + appLoader.plugins.onerror.path === fs.realpathSync(path.join(EGG_BASE, 'node_modules/egg-onerror')) + ); + assert(appLoader.plugins.onerror.package === 'egg-onerror'); + assert(/\d+\.\d+\.\d+/.test(appLoader.plugins.onerror.version)); + assert(Array.isArray(appLoader.orderPlugins)); }); it('should same name plugin level follow: app > framework > egg', () => { @@ -69,7 +71,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { }); appLoader.loadConfig(); - appLoader.plugins.rds.should.eql({ + assert.deepEqual(appLoader.plugins.rds, { enable: true, name: 'rds', dependencies: [ 'session' ], @@ -89,7 +91,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { logger, }); appLoader.loadConfig(); - appLoader.plugins.d1.should.eql({ + assert.deepEqual(appLoader.plugins.d1, { enable: true, name: 'd1', package: 'd', @@ -99,7 +101,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { path: path.join(baseDir, 'node_modules/d'), from: path.join(baseDir, 'config/plugin.js'), }); - should.not.exists(appLoader.plugins.d); + assert(!appLoader.plugins.d); }); it('should support package.json config', () => { @@ -110,7 +112,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { logger, }); appLoader.loadConfig(); - appLoader.plugins.g.should.eql({ + assert.deepEqual(appLoader.plugins.g, { enable: true, name: 'g', dependencies: [ 'f' ], @@ -136,7 +138,9 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { }); appLoader.loadConfig(); - message.should.eql('[egg:loader] pluginName(e) is different from pluginConfigName(wrong-name)'); + assert( + message === '[egg:loader] pluginName(e) is different from pluginConfigName(wrong-name)' + ); }); it('should loadConfig plugins with custom plugins config', () => { @@ -158,7 +162,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { }); appLoader.loadConfig(); - appLoader.plugins.d1.should.eql({ + assert.deepEqual(appLoader.plugins.d1, { enable: true, name: 'd1', package: 'd', @@ -168,7 +172,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { path: path.join(baseDir, 'node_modules/d'), from: path.join(baseDir, 'config/plugin.js'), }); - appLoader.plugins.foo.should.eql({ + assert.deepEqual(appLoader.plugins.foo, { enable: true, name: 'foo', dependencies: [], @@ -176,11 +180,11 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { env: [], path: path.join(baseDir, 'node_modules/d'), }); - should.not.exists(appLoader.plugins.d); + assert(!appLoader.plugins.d); }); it('should throw error when plugin not exists', () => { - (function() { + assert.throws(function() { const baseDir = utils.getFilepath('apps/loader-plugin-noexist'); const appLoader = new AppWorkerLoader({ baseDir, @@ -188,11 +192,11 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { logger, }); appLoader.loadConfig(); - }).should.throw(/Can not find plugin noexist in /); + }, /Can not find plugin noexist in /); }); it('should throw error when app baseDir not exists', () => { - (function() { + assert.throws(function() { const baseDir = utils.getFilepath('apps/notexist-app'); const appLoader = new AppWorkerLoader({ baseDir, @@ -200,7 +204,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { logger, }); appLoader.loadConfig(); - }).should.throw(/notexist-app not exists/); + }, /notexist-app not exists/); }); it('should keep plugin list sorted', () => { @@ -212,9 +216,9 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { logger, }); appLoader.loadConfig(); - appLoader.orderPlugins.map(plugin => { + assert.deepEqual(appLoader.orderPlugins.map(plugin => { return plugin.name; - }).should.eql([ + }), [ 'onerror', 'session', 'i18n', @@ -237,7 +241,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { }); it('should throw recursive deps error', () => { - (function() { + assert.throws(function() { const baseDir = utils.getFilepath('apps/loader-plugin-dep-recursive'); const appLoader = new AppWorkerLoader({ baseDir, @@ -245,11 +249,11 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { logger, }); appLoader.loadConfig(); - }).should.throw('sequencify plugins has problem, missing: [], recursive: [a,b,c,a]'); + }, 'sequencify plugins has problem, missing: [], recursive: [a,b,c,a]'); }); it('should throw error when plugin dep not exists', function() { - (function() { + assert.throws(function() { const baseDir = utils.getFilepath('apps/loader-plugin-dep-missing'); const appLoader = new AppWorkerLoader({ baseDir, @@ -257,7 +261,7 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { logger, }); appLoader.loadConfig(); - }).should.throw('sequencify plugins has problem, missing: [a1], recursive: []\n\t>> Plugin [a1] is disabled or missed, but is required by [c]'); + }, 'sequencify plugins has problem, missing: [a1], recursive: []\n\t>> Plugin [a1] is disabled or missed, but is required by [c]'); }); it('should auto fill plugin infos', () => { @@ -273,8 +277,8 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { const keys1 = appLoader1.orderPlugins.map(plugin => { return plugin.name; }).join(','); - keys1.should.containEql('b,c,d1,f,e'); - should.not.exist(appLoader1.plugins.a1); + assert(keys1.includes('b,c,d1,f,e')); + assert(!appLoader1.plugins.a1); mm(process.env, 'NODE_ENV', 'development'); const appLoader2 = new AppWorkerLoader({ @@ -286,8 +290,8 @@ describe('test/lib/core/loader/load_plugin.test.js', () => { const keys2 = appLoader2.orderPlugins.map(plugin => { return plugin.name; }).join(','); - keys2.should.containEql('d1,a1,b,c,f,e'); - appLoader2.plugins.a1.should.eql({ + assert(keys2.includes('d1,a1,b,c,f,e')); + assert.deepEqual(appLoader2.plugins.a1, { enable: true, name: 'a1', dependencies: [ 'd1' ], diff --git a/test/lib/core/loader/load_service.test.js b/test/lib/core/loader/load_service.test.js index 3b9ad2df47..b4f6025b53 100644 --- a/test/lib/core/loader/load_service.test.js +++ b/test/lib/core/loader/load_service.test.js @@ -1,6 +1,6 @@ 'use strict'; -const should = require('should'); +const assert = require('assert'); const request = require('supertest'); const mm = require('egg-mock'); const utils = require('../../../utils'); @@ -13,18 +13,18 @@ describe('test/lib/core/loader/load_service.test.js', () => { it('should load app and plugin services', function* () { app = utils.app('apps/loader-plugin'); yield app.ready(); - should.exists(app.serviceClasses.foo); - should.exists(app.serviceClasses.foo2); - should.not.exists(app.serviceClasses.bar1); - should.exists(app.serviceClasses.bar2); - should.exists(app.serviceClasses.foo4); + assert(app.serviceClasses.foo); + assert(app.serviceClasses.foo2); + assert(!app.serviceClasses.bar1); + assert(app.serviceClasses.bar2); + assert(app.serviceClasses.foo4); const ctx = app.mockContext(); - should.exists(ctx.service.fooDir.foo5); - should.exists(ctx.service.foo); - should.exists(ctx.service.foo2); - should.exists(ctx.service.bar2); - should.exists(ctx.service.foo4); + assert(ctx.service.fooDir.foo5); + assert(ctx.service.foo); + assert(ctx.service.foo2); + assert(ctx.service.bar2); + assert(ctx.service.foo4); yield request(app.callback()) .get('/') @@ -38,8 +38,10 @@ describe('test/lib/core/loader/load_service.test.js', () => { it('should service support es6', function* () { app = utils.app('apps/services_loader_verify'); yield app.ready(); - app.serviceClasses.should.have.property('foo'); - app.serviceClasses.foo.should.have.properties('bar', 'bar1', 'aa'); + assert(Object.prototype.hasOwnProperty.call(app.serviceClasses, 'foo')); + assert( + [ 'bar' ].every(p => Object.prototype.hasOwnProperty.call(app.serviceClasses.foo, p)) + ); }); it('should support extend app.Service class', function* () { @@ -49,8 +51,8 @@ describe('test/lib/core/loader/load_service.test.js', () => { yield request(app.callback()) .get('/user') .expect(res => { - should.exists(res.body.user); - res.body.user.userId.should.equal('123mock'); + assert(res.body.user); + assert(res.body.user.userId === '123mock'); }) .expect(200); }); diff --git a/test/lib/core/logger.test.js b/test/lib/core/logger.test.js index 7c76e8abd5..1cee08fd24 100644 --- a/test/lib/core/logger.test.js +++ b/test/lib/core/logger.test.js @@ -1,6 +1,6 @@ 'use strict'; -const should = require('should'); +const assert = require('assert'); const path = require('path'); const fs = require('fs'); const mm = require('egg-mock'); @@ -23,11 +23,11 @@ describe('test/lib/core/logger.test.js', () => { yield app.ready(); // 生产环境默认 _level = info - app.logger.get('file').options.level.should.equal(Logger.INFO); + assert(app.logger.get('file').options.level === Logger.INFO); // stdout 默认 INFO - app.logger.get('console').options.level.should.equal(Logger.INFO); - app.coreLogger.get('file').options.level.should.equal(Logger.INFO); - app.coreLogger.get('console').options.level.should.equal(Logger.INFO); + assert(app.logger.get('console').options.level === Logger.INFO); + assert(app.coreLogger.get('file').options.level === Logger.INFO); + assert(app.coreLogger.get('console').options.level === Logger.INFO); }); it('should got right level on local env', function* () { @@ -36,10 +36,10 @@ describe('test/lib/core/logger.test.js', () => { app = utils.app('apps/mock-dev-app'); yield app.ready(); - app.logger.get('file').options.level.should.equal(Logger.INFO); - app.logger.get('console').options.level.should.equal(Logger.INFO); - app.coreLogger.get('file').options.level.should.equal(Logger.INFO); - app.coreLogger.get('console').options.level.should.equal(Logger.INFO); + assert(app.logger.get('file').options.level === Logger.INFO); + assert(app.logger.get('console').options.level === Logger.INFO); + assert(app.coreLogger.get('file').options.level === Logger.INFO); + assert(app.coreLogger.get('console').options.level === Logger.INFO); }); it('should set EGG_LOG level on local env', function* () { @@ -48,10 +48,10 @@ describe('test/lib/core/logger.test.js', () => { app = utils.app('apps/mock-dev-app'); yield app.ready(); - app.logger.get('file').options.level.should.equal(Logger.INFO); - app.logger.get('console').options.level.should.equal(Logger.ERROR); - app.coreLogger.get('file').options.level.should.equal(Logger.INFO); - app.coreLogger.get('console').options.level.should.equal(Logger.ERROR); + assert(app.logger.get('file').options.level === Logger.INFO); + assert(app.logger.get('console').options.level === Logger.ERROR); + assert(app.coreLogger.get('file').options.level === Logger.INFO); + assert(app.coreLogger.get('console').options.level === Logger.ERROR); return app.ready(); }); @@ -61,10 +61,10 @@ describe('test/lib/core/logger.test.js', () => { app = utils.app('apps/mock-dev-app'); yield app.ready(); - app.logger.get('file').options.level.should.equal(Logger.INFO); - app.logger.get('console').options.level.should.equal(Logger.WARN); - app.coreLogger.get('file').options.level.should.equal(Logger.INFO); - app.coreLogger.get('console').options.level.should.equal(Logger.WARN); + assert(app.logger.get('file').options.level === Logger.INFO); + assert(app.logger.get('console').options.level === Logger.WARN); + assert(app.coreLogger.get('file').options.level === Logger.INFO); + assert(app.coreLogger.get('console').options.level === Logger.WARN); return app.ready(); }); @@ -73,8 +73,8 @@ describe('test/lib/core/logger.test.js', () => { app = utils.app('apps/mock-dev-app'); yield app.ready(); - app.logger.get('file').options.level.should.equal(Logger.INFO); - app.logger.get('console').options.level.should.equal(Logger.ERROR); + assert(app.logger.get('file').options.level === Logger.INFO); + assert(app.logger.get('console').options.level === Logger.ERROR); return app.ready(); }); @@ -90,7 +90,9 @@ describe('test/lib/core/logger.test.js', () => { yield sleep(1000); - fs.readFileSync(logfile, 'utf8').should.containEql('nodejs.Error: mock nobuffer error\n'); + assert( + fs.readFileSync(logfile, 'utf8').includes('nodejs.Error: mock nobuffer error\n') + ); }); it('log buffer enable cache on non-local and non-unittest env', function* () { @@ -107,7 +109,7 @@ describe('test/lib/core/logger.test.js', () => { yield sleep(1000); - fs.readFileSync(logfile, 'utf8').should.containEql(''); + assert(fs.readFileSync(logfile, 'utf8').includes('')); }); it('output .json format log', function* () { @@ -122,8 +124,8 @@ describe('test/lib/core/logger.test.js', () => { yield sleep(1000); - fs.existsSync(logfile).should.be.true; - fs.readFileSync(logfile, 'utf8').should.containEql('"message":"json format"'); + assert(fs.existsSync(logfile)); + assert(fs.readFileSync(logfile, 'utf8').includes('"message":"json format"')); }); it('dont output to console after app ready', done => { @@ -164,10 +166,10 @@ describe('test/lib/core/logger.test.js', () => { // .debug() .coverage(false) .end(err => { - should.not.exists(err); + assert(!err); const content = fs.readFileSync(path.join(baseDir, 'logs/logger/common-error.log'), 'utf8'); - content.should.containEql('nodejs.Error: agent error'); - content.should.containEql('nodejs.Error: app error'); + assert(content.includes('nodejs.Error: agent error')); + assert(content.includes('nodejs.Error: app error')); done(); }); }); @@ -184,17 +186,17 @@ describe('test/lib/core/logger.test.js', () => { yield sleep(10); const content = fs.readFileSync(path.join(app.baseDir, 'logs/logger/common-error.log'), 'utf8'); - content.should.containEql('nodejs.Error: logger error'); - content.should.containEql('nodejs.Error: coreLogger error'); - content.should.containEql('nodejs.Error: errorLogger error'); - content.should.containEql('nodejs.Error: customLogger error'); + assert(content.includes('nodejs.Error: logger error')); + assert(content.includes('nodejs.Error: coreLogger error')); + assert(content.includes('nodejs.Error: errorLogger error')); + assert(content.includes('nodejs.Error: customLogger error')); }); it('agent\'s logger is same as coreLogger', function* () { app = utils.app('apps/logger'); yield app.ready(); - app.agent.logger.options.file.should.equal(app.agent.coreLogger.options.file); + assert(app.agent.logger.options.file === app.agent.coreLogger.options.file); }); describe('logger.level = DEBUG', () => { @@ -210,9 +212,10 @@ describe('test/lib/core/logger.test.js', () => { .get('/') .expect('ok') .end(err => { - should.not.exist(err); - fs.readFileSync(path.join(app.config.baseDir, 'logs/foo/foo-web.log'), 'utf8') - .should.containEql(' DEBUG '); + assert(!err); + assert( + fs.readFileSync(path.join(app.config.baseDir, 'logs/foo/foo-web.log'), 'utf8').includes(' DEBUG ') + ); done(); }); }); diff --git a/test/lib/core/messenger.test.js b/test/lib/core/messenger.test.js index 1139050cf9..1f93ba5ae7 100644 --- a/test/lib/core/messenger.test.js +++ b/test/lib/core/messenger.test.js @@ -150,10 +150,10 @@ describe('test/lib/core/messenger.test.js', () => { it('app should accept agent message', done => { setTimeout(() => { - count(app.stdout, 'agent2app').should.equal(2); - count(app.stdout, 'app2app').should.equal(4); - count(app.stdout, 'agent2agent').should.equal(1); - count(app.stdout, 'app2agent').should.equal(2); + assert(count(app.stdout, 'agent2app') === 2); + assert(count(app.stdout, 'app2app') === 4); + assert(count(app.stdout, 'agent2agent') === 1); + assert(count(app.stdout, 'app2agent') === 2); done(); }, 500); diff --git a/test/lib/core/router.test.js b/test/lib/core/router.test.js index cb4c01b80f..9b9bd23842 100644 --- a/test/lib/core/router.test.js +++ b/test/lib/core/router.test.js @@ -1,5 +1,7 @@ 'use strict'; +const assert = require('assert'); + const request = require('supertest'); const mm = require('egg-mock'); const utils = require('../../utils'); @@ -119,39 +121,48 @@ describe('test/lib/core/router.test.js', () => { describe('router.url', () => { it('should work', () => { - app.router.url('posts').should.equal('/posts'); - app.router.url('members').should.equal('/members'); - app.router.url('post', { id: 1 }).should.equal('/posts/1'); - app.router.url('member', { id: 1 }).should.equal('/members/1'); - app.router.url('new_post').should.equal('/posts/new'); - app.router.url('new_member').should.equal('/members/new'); - app.router.url('edit_post', { id: 1 }).should.equal('/posts/1/edit'); + assert(app.router.url('posts') === '/posts'); + assert(app.router.url('members') === '/members'); + assert(app.router.url('post', { id: 1 }) === '/posts/1'); + assert(app.router.url('member', { id: 1 }) === '/members/1'); + assert(app.router.url('new_post') === '/posts/new'); + assert(app.router.url('new_member') === '/members/new'); + assert(app.router.url('edit_post', { id: 1 }) === '/posts/1/edit'); }); it('should work with unknow params', () => { - app.router.url('posts', { name: 'foo', page: 2 }).should.equal('/posts?name=foo&page=2'); - app.router.url('posts', { name: 'foo&?', page: 2 }).should.equal('/posts?name=foo%26%3F&page=2'); - app.router.url('edit_post', { id: 10, page: 2 }).should.equal('/posts/10/edit?page=2'); - app.router.url('edit_post', { i: 2, id: 10 }).should.equal('/posts/10/edit?i=2'); - app.router.url('edit_post', { id: 10, page: 2, tags: [ 'chair', 'develop' ] }) - .should.equal('/posts/10/edit?page=2&tags=chair&tags=develop'); - app.router.url('edit_post', { id: [ 10 ], page: [ 2 ], tags: [ 'chair', 'develop' ] }) - .should.equal('/posts/10/edit?page=2&tags=chair&tags=develop'); - app.router.url('edit_post', { id: [ 10, 11 ], page: [ 2 ], tags: [ 'chair', 'develop' ] }) - .should.equal('/posts/10/edit?page=2&tags=chair&tags=develop'); + assert( + app.router.url('posts', { name: 'foo', page: 2 }) === '/posts?name=foo&page=2' + ); + assert( + app.router.url('posts', { name: 'foo&?', page: 2 }) === '/posts?name=foo%26%3F&page=2' + ); + assert( + app.router.url('edit_post', { id: 10, page: 2 }) === '/posts/10/edit?page=2' + ); + assert(app.router.url('edit_post', { i: 2, id: 10 }) === '/posts/10/edit?i=2'); + assert( + app.router.url('edit_post', { id: 10, page: 2, tags: [ 'chair', 'develop' ] }) === '/posts/10/edit?page=2&tags=chair&tags=develop' + ); + assert( + app.router.url('edit_post', { id: [ 10 ], page: [ 2 ], tags: [ 'chair', 'develop' ] }) === '/posts/10/edit?page=2&tags=chair&tags=develop' + ); + assert( + app.router.url('edit_post', { id: [ 10, 11 ], page: [ 2 ], tags: [ 'chair', 'develop' ] }) === '/posts/10/edit?page=2&tags=chair&tags=develop' + ); }); }); describe('router.pathFor', () => { it('should work', () => { - app.router.pathFor('posts').should.equal('/posts'); + assert(app.router.pathFor('posts') === '/posts'); }); }); describe('router.method', () => { it('router method include HEAD', () => { - app.router.methods.should.containEql('HEAD'); + assert(app.router.methods.includes('HEAD')); }); }); }); diff --git a/test/lib/core/singleton.test.js b/test/lib/core/singleton.test.js index 5fefc8ee8c..02c1927332 100644 --- a/test/lib/core/singleton.test.js +++ b/test/lib/core/singleton.test.js @@ -1,5 +1,7 @@ 'use strict'; +const assert = require('assert'); + const Singleton = require('../../../lib/core/singleton'); class DataService { @@ -33,9 +35,9 @@ describe('test/lib/core/singleton.test.js', () => { create, }); singleton.init(); - (app.dataService instanceof DataService).should.be.ok; - app.dataService.config.foo.should.equal('bar'); - (typeof app.dataService.createInstance).should.equal('function'); + assert(app.dataService instanceof DataService); + assert(app.dataService.config.foo === 'bar'); + assert(typeof app.dataService.createInstance === 'function'); }); it('should init with clients', () => { @@ -57,10 +59,10 @@ describe('test/lib/core/singleton.test.js', () => { create, }); singleton.init(); - (app.dataService instanceof Singleton).should.be.ok; - app.dataService.get('first').config.foo.should.equal('bar1'); - app.dataService.get('second').config.foo.should.equal('bar2'); - (typeof app.dataService.createInstance).should.equal('function'); + assert(app.dataService instanceof Singleton); + assert(app.dataService.get('first').config.foo === 'bar1'); + assert(app.dataService.get('second').config.foo === 'bar2'); + assert(typeof app.dataService.createInstance === 'function'); }); it('should client support default', () => { @@ -80,10 +82,10 @@ describe('test/lib/core/singleton.test.js', () => { create, }); singleton.init(); - (app.dataService instanceof DataService).should.be.ok; - app.dataService.config.foo.should.equal('bar'); - app.dataService.config.foo1.should.equal('bar1'); - (typeof app.dataService.createInstance).should.equal('function'); + assert(app.dataService instanceof DataService); + assert(app.dataService.config.foo === 'bar'); + assert(app.dataService.config.foo1 === 'bar1'); + assert(typeof app.dataService.createInstance === 'function'); }); it('should clients support default', () => { @@ -106,10 +108,10 @@ describe('test/lib/core/singleton.test.js', () => { create, }); singleton.init(); - (app.dataService instanceof Singleton).should.be.ok; - app.dataService.get('first').config.foo.should.equal('bar1'); - app.dataService.get('second').config.foo.should.equal('bar'); - (typeof app.dataService.createInstance).should.equal('function'); + assert(app.dataService instanceof Singleton); + assert(app.dataService.get('first').config.foo === 'bar1'); + assert(app.dataService.get('second').config.foo === 'bar'); + assert(typeof app.dataService.createInstance === 'function'); }); it('should createInstance without client/clients support default', () => { @@ -128,11 +130,11 @@ describe('test/lib/core/singleton.test.js', () => { create, }); singleton.init(); - app.dataService.should.equal(singleton); - (app.dataService instanceof Singleton).should.be.ok; + assert(app.dataService === singleton); + assert(app.dataService instanceof Singleton); app.dataService = app.dataService.createInstance({ foo1: 'bar1' }); - (app.dataService instanceof DataService).should.be.ok; - app.dataService.config.foo1.should.equal('bar1'); - app.dataService.config.foo.should.equal('bar'); + assert(app.dataService instanceof DataService); + assert(app.dataService.config.foo1 === 'bar1'); + assert(app.dataService.config.foo === 'bar'); }); }); diff --git a/test/lib/plugins/depd.test.js b/test/lib/plugins/depd.test.js index 2d39506c44..b5051b5d52 100644 --- a/test/lib/plugins/depd.test.js +++ b/test/lib/plugins/depd.test.js @@ -1,5 +1,7 @@ 'use strict'; +const assert = require('assert'); + const mm = require('egg-mock'); const utils = require('../../utils'); @@ -16,7 +18,7 @@ describe('test/lib/plugins/depd.test.js', () => { it('should use this.locals instead of this.state', () => { const ctx = app.mockContext(); ctx.locals.test = 'aaa'; - ctx.locals.should.eql(ctx.state); - ctx.locals.test.should.eql(ctx.state.test); + assert.deepEqual(ctx.locals, ctx.state); + assert.deepEqual(ctx.locals.test, ctx.state.test); }); }); diff --git a/test/lib/plugins/logrotator.test.js b/test/lib/plugins/logrotator.test.js index ce0e01ecc4..e94eb1cc8b 100644 --- a/test/lib/plugins/logrotator.test.js +++ b/test/lib/plugins/logrotator.test.js @@ -1,5 +1,7 @@ 'use strict'; +const assert = require('assert'); + const path = require('path'); const glob = require('glob'); const utils = require('../../utils'); @@ -17,9 +19,9 @@ describe('test/lib/plugins/logrotator.test.js', () => { const file = require.resolve('egg-logrotator/app/schedule/rotate_by_file.js'); yield app.runSchedule(file); const files = glob.sync(path.join(app.config.logger.dir, '*.log.*')); - files.length.should.above(0); + assert(files.length > 0); files.forEach(file => { - file.should.match(/\.log\.\d{4}-\d{2}-\d{2}$/); + assert(/\.log\.\d{4}-\d{2}-\d{2}$/.test(file)); }); }); }); diff --git a/test/lib/plugins/schedule.test.js b/test/lib/plugins/schedule.test.js index 360fe1d858..ed14c3d1c6 100644 --- a/test/lib/plugins/schedule.test.js +++ b/test/lib/plugins/schedule.test.js @@ -1,5 +1,6 @@ 'use strict'; +const assert = require('assert'); const path = require('path'); const fs = require('fs'); const utils = require('../../utils'); @@ -14,7 +15,9 @@ describe('test/lib/plugins/schedule.test.js', () => { yield sleep(5000); yield app.close(); const log = getLogContent('schedule'); - contains(log, 'cron').should.within(1, 2); + const count = contains(log, 'cron'); + assert(count >= 1); + assert(count <= 2); }); }); diff --git a/test/lib/plugins/session.test.js b/test/lib/plugins/session.test.js index ce546e1416..f38a683080 100644 --- a/test/lib/plugins/session.test.js +++ b/test/lib/plugins/session.test.js @@ -1,7 +1,7 @@ 'use strict'; +const assert = require('assert'); const request = require('supertest'); -const should = require('should'); const mm = require('egg-mock'); const utils = require('../../utils'); @@ -27,9 +27,9 @@ describe('test/lib/plugins/session.test.js', () => { }) .expect(200, (err, res) => { if (err) return done(err); - should.exist(res.headers['set-cookie']); + assert(res.headers['set-cookie']); const cookie = res.headers['set-cookie'].join(';'); - cookie.should.match(/EGG_SESS=[\w-]+/); + assert(/EGG_SESS=[\w-]+/.test(cookie)); // userId 不变,还是读取到上次的 session 值 app.mockContext({ @@ -45,7 +45,7 @@ describe('test/lib/plugins/session.test.js', () => { }) .expect(200, (err, res) => { if (err) return done(err); - should.not.exist(res.headers['set-cookie']); + assert(!res.headers['set-cookie']); // userId change, session still not change app.mockContext({ @@ -60,7 +60,7 @@ describe('test/lib/plugins/session.test.js', () => { uid: '2', }) .expect(res => { - should.not.exist(res.headers['set-cookie']); + assert(!res.headers['set-cookie']); }) .expect(200, err => { if (err) return done(err); diff --git a/test/lib/plugins/watcher.test.js b/test/lib/plugins/watcher.test.js index c943bbf6e3..d1bfe9c7dd 100644 --- a/test/lib/plugins/watcher.test.js +++ b/test/lib/plugins/watcher.test.js @@ -1,6 +1,6 @@ 'use strict'; -require('should'); +const assert = require('assert'); const mm = require('egg-mock'); const fs = require('fs'); const request = require('supertest'); @@ -42,7 +42,7 @@ describe('test/lib/plugins/watcher.test.js', () => { .expect(function(res) { const lastCount = count; count = parseInt(res.text); - count.should.greaterThan(lastCount); + assert(count > lastCount); }); fs.writeFileSync(file_path2, 'aaa'); @@ -54,7 +54,7 @@ describe('test/lib/plugins/watcher.test.js', () => { .expect(function(res) { const lastCount = count; count = parseInt(res.text); - count.should.greaterThan(lastCount); + assert(count > lastCount); }); }); @@ -74,7 +74,7 @@ describe('test/lib/plugins/watcher.test.js', () => { .expect(res => { const lastCount = count; count = parseInt(res.text); - count.should.greaterThan(lastCount); + assert(count > lastCount); }); }); @@ -94,7 +94,7 @@ describe('test/lib/plugins/watcher.test.js', () => { yield sleep(3000); const logPath = utils.getFilepath('apps/watcher-type-default/logs/watcher-type-default/egg-agent.log'); const content = fs.readFileSync(logPath, 'utf8'); - content.should.containEql('defaultEventSource watcher will NOT take effect'); + assert(content.includes('defaultEventSource watcher will NOT take effect')); }); }); }); diff --git a/test/mocha.opts b/test/mocha.opts deleted file mode 100644 index e3052016d3..0000000000 --- a/test/mocha.opts +++ /dev/null @@ -1 +0,0 @@ ---require should