Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore committed Oct 26, 2016
1 parent 5dafb58 commit 9eff052
Show file tree
Hide file tree
Showing 7 changed files with 409 additions and 434 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: node_js
node_js:
- '4'
- '6'
- '7'
install:
- npm i npminstall && npminstall
script:
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ environment:
matrix:
- nodejs_version: '4'
- nodejs_version: '6'
- nodejs_version: '7'

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"estraverse": "^4.1.1",
"formstream": "^1.0.0",
"glob": "^7.1.1",
"ko-sleep": "^1.0.2",
"koa": "^1.2.4",
"koa-router": "^5.4.0",
"merge-descriptors": "^1.0.1",
Expand Down Expand Up @@ -117,6 +118,6 @@
"node": ">= 4.0.0"
},
"ci": {
"version": "4, 6"
"version": "4, 6, 7"
}
}
131 changes: 60 additions & 71 deletions test/app/extend/context.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const should = require('should');
const fs = require('fs');
const path = require('path');
const mm = require('egg-mock');
Expand All @@ -22,98 +21,88 @@ describe('test/app/extend/context.test.js', () => {
let app;
afterEach(() => app.close());

it('env=local: level => debug', done => {
it('env=local: level => debug', function* () {
mm.env('local');
mm(process.env, 'EGG_LOG', 'none');
app = utils.app('apps/demo');
yield app.ready();
const logdir = app.config.logger.dir;

request(app.callback())
yield request(app.callback())
.get('/logger?message=foo')
.expect('logger', err => {
should.not.exists(err);

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');

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');

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');
done();
});
});
.expect('logger');

it('env=unittest: level => info', done => {
mm.env('unittest');
app = utils.app('apps/demo');
app.ready(() => {
const logdir = app.config.logger.dir;

app.mockContext({
userId: '123123',
tracer: {
traceId: '456456',
},
});

request(app.callback())
.get('/logger?message=foo')
.expect('logger', err => {
should.not.exists(err);
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');

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\.]+\/456456\/\d+ms GET \/logger\?message=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');

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');
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');
});

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');
it('env=unittest: level => info', function* () {
mm.env('unittest');
app = utils.app('apps/demo');
yield app.ready();
const logdir = app.config.logger.dir;

done();
});
app.mockContext({
userId: '123123',
tracer: {
traceId: '456456',
},
});

yield request(app.callback())
.get('/logger?message=foo')
.expect('logger');

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\.]+\/456456\/\d+ms GET \/logger\?message=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');

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');
});

it('env=prod: level => info', done => {
it('env=prod: level => info', function* () {
mm.env('unittest');
app = utils.app('apps/demo');
yield app.ready();
const logdir = app.config.logger.dir;

request(app.callback())
yield request(app.callback())
.get('/logger?message=foo')
.expect('logger', err => {
should.not.exists(err);

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');
.expect('logger');

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');
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');

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');
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');

done();
});
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');
});
});

Expand Down
Loading

0 comments on commit 9eff052

Please sign in to comment.