Skip to content

Commit e5d11f1

Browse files
committed
enable meta and body_parser
1 parent 9200306 commit e5d11f1

File tree

51 files changed

+158
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+158
-172
lines changed

.github/workflows/nodejs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ jobs:
1212
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
1313
with:
1414
os: 'ubuntu-latest, macos-latest, windows-latest'
15-
version: '18.19.0, 18, 20, 22'
15+
version: '18.19.0, 18, 20, 22, 23'
1616
secrets:
1717
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

test/app/middleware/body_parser.test.js test/app/middleware/body_parser.test.ts

+21-25
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
const assert = require('assert');
2-
const querystring = require('querystring');
3-
const utils = require('../../utils');
4-
5-
describe('test/app/middleware/body_parser.test.js', () => {
6-
let app;
7-
let app1;
8-
let csrf;
9-
let cookies;
10-
before(done => {
11-
app = utils.app('apps/body_parser_testapp');
12-
app.ready(() => {
13-
app.httpRequest()
14-
.get('/test/body_parser/user')
15-
.expect(200, (err, res) => {
16-
assert(!err);
17-
csrf = res.body.csrf || '';
18-
cookies = res.headers['set-cookie'].join(';');
19-
assert(csrf);
20-
done();
21-
});
22-
});
1+
import { strict as assert } from 'node:assert';
2+
import querystring from 'node:querystring';
3+
import { createApp, MockApplication } from '../../utils.js';
4+
5+
describe('test/app/middleware/body_parser.test.ts', () => {
6+
let app: MockApplication;
7+
let app1: MockApplication;
8+
let csrf: string;
9+
let cookies: string;
10+
before(async () => {
11+
app = createApp('apps/body_parser_testapp');
12+
await app.ready();
13+
const res = await app.httpRequest()
14+
.get('/test/body_parser/user')
15+
.expect(200);
16+
csrf = res.body.csrf || '';
17+
cookies = (res.headers['set-cookie'] as any).join(';');
18+
assert(csrf);
2319
});
2420

2521
after(() => app.close());
@@ -109,7 +105,7 @@ describe('test/app/middleware/body_parser.test.js', () => {
109105
});
110106

111107
it('should disable body parser', async () => {
112-
app1 = utils.app('apps/body_parser_testapp_disable');
108+
app1 = createApp('apps/body_parser_testapp_disable');
113109
await app1.ready();
114110

115111
await app1.httpRequest()
@@ -119,7 +115,7 @@ describe('test/app/middleware/body_parser.test.js', () => {
119115
});
120116

121117
it('should body parser support ignore', async () => {
122-
app1 = utils.app('apps/body_parser_testapp_ignore');
118+
app1 = createApp('apps/body_parser_testapp_ignore');
123119
await app1.ready();
124120

125121
await app1.httpRequest()
@@ -135,7 +131,7 @@ describe('test/app/middleware/body_parser.test.js', () => {
135131
});
136132

137133
it('should body parser support match', async () => {
138-
app1 = utils.app('apps/body_parser_testapp_match');
134+
app1 = createApp('apps/body_parser_testapp_match');
139135
await app1.ready();
140136

141137
await app1.httpRequest()

test/app/middleware/meta.test.js test/app/middleware/meta.test.ts

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
const assert = require('assert');
2-
const mm = require('egg-mock');
3-
const fs = require('fs/promises');
4-
const utils = require('../../utils');
1+
import { strict as assert } from 'node:assert';
2+
import fs from 'node:fs/promises';
3+
import { scheduler } from 'node:timers/promises';
4+
import { createApp, MockApplication, restore, cluster } from '../../utils.js';
55

6-
describe('test/app/middleware/meta.test.js', () => {
7-
afterEach(mm.restore);
6+
describe('test/app/middleware/meta.test.ts', () => {
7+
afterEach(restore);
8+
9+
let app: MockApplication;
810

911
describe('default config', () => {
10-
let app;
1112
before(() => {
12-
app = utils.app('apps/middlewares');
13+
app = createApp('apps/middlewares');
1314
return app.ready();
1415
});
1516
after(() => app.close());
@@ -23,9 +24,8 @@ describe('test/app/middleware/meta.test.js', () => {
2324
});
2425

2526
describe('config.logger.enablePerformanceTimer = true', () => {
26-
let app;
2727
before(() => {
28-
app = utils.app('apps/middlewares-meta-enablePerformanceTimer');
28+
app = createApp('apps/middlewares-meta-enablePerformanceTimer');
2929
return app.ready();
3030
});
3131
after(() => app.close());
@@ -41,9 +41,8 @@ describe('test/app/middleware/meta.test.js', () => {
4141
});
4242

4343
describe('meta.logging = true', () => {
44-
let app;
4544
before(() => {
46-
app = utils.app('apps/meta-logging-app');
45+
app = createApp('apps/meta-logging-app');
4746
return app.ready();
4847
});
4948
after(() => app.close());
@@ -54,16 +53,18 @@ describe('test/app/middleware/meta.test.js', () => {
5453
.expect('X-Readtime', /\d+/)
5554
.expect('hello world')
5655
.expect(200);
57-
if (process.platform === 'win32') await utils.sleep(2000);
56+
if (process.platform === 'win32') {
57+
await scheduler.wait(2000);
58+
}
5859
const content = (await fs.readFile(app.coreLogger.options.file, 'utf8')).split('\n').slice(-2, -1)[0];
59-
assert(content.includes('[meta] request started, host: '));
60+
assert.match(content, /\[meta] request started, host: /);
6061
});
6162
});
6263

6364
describe('cluster start', () => {
64-
let app;
65+
let app: MockApplication;
6566
before(() => {
66-
app = utils.cluster('apps/middlewares');
67+
app = cluster('apps/middlewares');
6768
return app.ready();
6869
});
6970
after(() => app.close());

test/fixtures/apps/app-locals-getter/app/router.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
module.exports = app => {
4-
app.get('/test', function* () {
4+
app.get('/test', function () {
55
this.app.locals.foo = 'bar';
66
this.locals.abc = '123';
77
this.body = {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
module.exports = app => {
4-
app.get('/', function* () {
4+
app.get('/', function () {
55
this.body = this.app.serverEmit;
66
});
77
};
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
module.exports = app => {
4-
app.get('/', function* () {
4+
app.get('/', function () {
55
this.body = 'done';
66
});
77
};
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = app => {
2-
app.get('/', function* () {
2+
app.get('/', function () {
33
this.body = this.app.serverEmit;
44
});
55
};

test/fixtures/apps/app-throw/app/router.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

33
module.exports = app => {
4-
app.get('/throw', function* () {
4+
app.get('/throw', function () {
55
this.body = 'foo';
66
setTimeout(() => {
77
a.b = c;
88
}, 1);
99
});
1010

11-
app.get('/throw-error-setter', function* () {
11+
app.get('/throw-error-setter', function () {
1212
this.body = 'foo';
1313
setTimeout(() => {
1414
const err = new Error('abc');
@@ -20,21 +20,21 @@ module.exports = app => {
2020
}, 1);
2121
});
2222

23-
app.get('/throw-unhandledRejection', function* () {
23+
app.get('/throw-unhandledRejection', function () {
2424
this.body = 'foo';
2525
new Promise((resolve, reject) => {
2626
reject(new Error('foo reject error'));
2727
});
2828
});
2929

30-
app.get('/throw-unhandledRejection-string', function* () {
30+
app.get('/throw-unhandledRejection-string', function () {
3131
this.body = 'foo';
3232
new Promise((resolve, reject) => {
3333
reject('foo reject string error');
3434
});
3535
});
3636

37-
app.get('/throw-unhandledRejection-obj', function* () {
37+
app.get('/throw-unhandledRejection-obj', function () {
3838
this.body = 'foo';
3939
new Promise((resolve, reject) => {
4040
const err = {
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
module.exports = app => {
2-
app.get('/test/body_parser/user', function* () {
2+
app.get('/test/body_parser/user', function () {
33
this.body = {
44
url: this.url,
55
csrf: this.csrf
66
};
77
});
88

9-
app.post('/test/body_parser/user', function* () {
9+
app.post('/test/body_parser/user', function () {
1010
this.logger.info('request body %s', this.request.body);
1111
this.body = this.request.body;
1212
});
1313

14-
app.post('/test/body_parser/foo.json', function* () {
14+
app.post('/test/body_parser/foo.json', function () {
1515
this.body = this.request.body;
1616
});
17-
app.post('/test/body_parser/form.json', function* () {
17+
app.post('/test/body_parser/form.json', function () {
1818
this.body = this.request.body;
1919
});
2020
};
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
module.exports = app => {
2-
app.get('/test/body_parser/user', function* () {
2+
app.get('/test/body_parser/user', function () {
33
this.body = {
44
url: this.url,
55
csrf: this.csrf
66
};
77
});
88

9-
app.post('/test/body_parser/user', function* () {
9+
app.post('/test/body_parser/user', function () {
1010
this.body = this.request.body;
1111
});
1212

13-
app.post('/test/body_parser/foo.json', function* () {
13+
app.post('/test/body_parser/foo.json', function () {
1414
this.body = this.request.body;
1515
});
16-
app.post('/test/body_parser/form.json', function* () {
16+
app.post('/test/body_parser/form.json', function () {
1717
this.body = this.request.body;
1818
});
1919
};
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
module.exports = app => {
2-
app.get('/test/body_parser/user', function* () {
2+
app.get('/test/body_parser/user', function () {
33
this.body = {
44
url: this.url,
55
csrf: this.csrf
66
};
77
});
88

9-
app.post('/test/body_parser/user', function* () {
9+
app.post('/test/body_parser/user', function () {
1010
this.body = this.request.body;
1111
});
1212

13-
app.post('/test/body_parser/foo.json', function* () {
13+
app.post('/test/body_parser/foo.json', function () {
1414
this.body = this.request.body;
1515
});
16-
app.post('/test/body_parser/form.json', function* () {
16+
app.post('/test/body_parser/form.json', function () {
1717
this.body = this.request.body;
1818
});
1919
};
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
module.exports = app => {
2-
app.get('/test/body_parser/user', function* () {
2+
app.get('/test/body_parser/user', function () {
33
this.body = {
44
url: this.url,
55
csrf: this.csrf
66
};
77
});
88

9-
app.post('/test/body_parser/user', function* () {
9+
app.post('/test/body_parser/user', function () {
1010
this.body = this.request.body;
1111
});
1212

13-
app.post('/test/body_parser/foo.json', function* () {
13+
app.post('/test/body_parser/foo.json', function () {
1414
this.body = this.request.body;
1515
});
16-
app.post('/test/body_parser/form.json', function* () {
16+
app.post('/test/body_parser/form.json', function () {
1717
this.body = this.request.body;
1818
});
1919
};

test/fixtures/apps/csrf-disable/app/controller/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
exports.user = function* () {
3+
exports.user = function () {
44
this.body = {
55
url: this.url,
66
name: this.request.body.name,

test/fixtures/apps/csrf-enable/app/controller/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
exports.user = function* () {
3+
exports.user = function () {
44
this.body = {
55
url: this.url,
66
name: this.query.name,

test/fixtures/apps/csrf-ignore/app/controller/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
exports.user = function* () {
3+
exports.user = function () {
44
this.body = {
55
url: this.url,
66
name: this.request.body.name,

test/fixtures/apps/custom-context-getlogger/app/controller/home.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
module.exports = function* () {
3+
module.exports = function () {
44
const logger = this.getLogger('foo');
55
logger.info('hello');
66
this.body = 'work, logger: ' + (logger ? 'exists' : 'not exists');

test/fixtures/apps/custom-framework-demo/app/controller/home.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function* () {
1+
module.exports = function () {
22
this.body = {
33
workerTitle: process.title
44
};

test/fixtures/apps/custom-framework-demo/app/controller/ip.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
module.exports = function* () {
3+
module.exports = function () {
44
if (this.query.set_ip) {
55
this.ip = this.query.set_ip;
66
}

test/fixtures/apps/demo/app/controller/home.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function* () {
1+
module.exports = function () {
22
this.body = {
33
workerTitle: process.title
44
};

test/fixtures/apps/demo/app/controller/ip.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
module.exports = function* () {
3+
module.exports = function () {
44
if (this.query.set_ip) {
55
this.ip = this.query.set_ip;
66
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

33
module.exports = app => {
4-
app.get('/foo.js', function* () {
4+
app.get('/foo.js', function () {
55
this.body = 'foo.js';
66
});
77

8-
app.get('/foo', function* () {
8+
app.get('/foo', function () {
99
this.body = 'foo';
1010
});
1111
};

0 commit comments

Comments
 (0)