|
1 |
| -const assert = require('assert'); |
2 |
| -const path = require('path'); |
3 |
| -const fs = require('fs'); |
| 1 | +const assert = require('node:assert'); |
| 2 | +const path = require('node:path'); |
| 3 | +const fs = require('node:fs'); |
4 | 4 | const mm = require('egg-mock');
|
5 | 5 | const Logger = require('egg-logger');
|
6 | 6 | const utils = require('../../utils');
|
7 | 7 |
|
8 | 8 | describe('test/lib/core/logger.test.js', () => {
|
9 | 9 | let app;
|
10 |
| - afterEach(mm.restore); |
11 |
| - afterEach(() => utils.sleep(5000).then(() => app.close())); |
| 10 | + afterEach(async () => { |
| 11 | + if (app) { |
| 12 | + await utils.sleep(5000); |
| 13 | + await app.close(); |
| 14 | + app = null; |
| 15 | + } |
| 16 | + await mm.restore(); |
| 17 | + }); |
12 | 18 |
|
13 | 19 | it('should got right default config on prod env', async () => {
|
14 | 20 | mm.env('prod');
|
@@ -100,12 +106,13 @@ describe('test/lib/core/logger.test.js', () => {
|
100 | 106 | const logfile = path.join(app.config.logger.dir, 'common-error.log');
|
101 | 107 | // app.config.logger.buffer.should.equal(false);
|
102 | 108 | ctx.logger.error(new Error('mock nobuffer error'));
|
103 |
| - |
104 | 109 | await utils.sleep(1000);
|
105 |
| - |
106 |
| - assert( |
107 |
| - fs.readFileSync(logfile, 'utf8').includes('nodejs.Error: mock nobuffer error\n') |
108 |
| - ); |
| 110 | + if (process.platform !== 'darwin') { |
| 111 | + // skip check on macOS |
| 112 | + assert( |
| 113 | + fs.readFileSync(logfile, 'utf8').includes('nodejs.Error: mock nobuffer error\n') |
| 114 | + ); |
| 115 | + } |
109 | 116 | });
|
110 | 117 |
|
111 | 118 | it('log buffer enable cache on non-local and non-unittest env', async () => {
|
@@ -253,4 +260,25 @@ describe('test/lib/core/logger.test.js', () => {
|
253 | 260 | });
|
254 | 261 | });
|
255 | 262 | });
|
| 263 | + |
| 264 | + describe('onelogger', () => { |
| 265 | + let app; |
| 266 | + before(() => { |
| 267 | + app = utils.app('apps/custom-logger'); |
| 268 | + return app.ready(); |
| 269 | + }); |
| 270 | + after(() => app.close()); |
| 271 | + |
| 272 | + it('should work with onelogger', async () => { |
| 273 | + await app.httpRequest() |
| 274 | + .get('/') |
| 275 | + .expect({ |
| 276 | + ok: true, |
| 277 | + }) |
| 278 | + .expect(200); |
| 279 | + await utils.sleep(1000); |
| 280 | + app.expectLog('[custom-logger-label] hello myLogger', 'myLogger'); |
| 281 | + app.expectLog('hello logger'); |
| 282 | + }); |
| 283 | + }); |
256 | 284 | });
|
0 commit comments