test: use httpbingo for ua (#12227)

* test: use httpbingo for ua

* fix: lazy require maintainer

* test: extend timeout
This commit is contained in:
Tony 2023-04-04 03:14:16 +09:00 committed by GitHub
parent 952b0b7115
commit 1373acf94c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 8 deletions

View File

@ -1,11 +1,11 @@
const Router = require('@koa/router');
const router = new Router();
const maintainer = require('./maintainer');
router.get('/routes/:name?', (ctx) => {
const result = {};
let counter = 0;
const maintainer = require('./maintainer');
Object.keys(maintainer).forEach((i) => {
const path = i;
const top = path.split('/')[1];

View File

@ -27,7 +27,7 @@ for (const dir in maintainerPath) {
throw Error(`No maintainer in "${dir}".`);
}
for (const author of Object.values(routes)) {
if (typeof author === 'string') {
if (!Array.isArray(author)) {
throw Error(`Maintainers' name should be an array in "${dir}".`);
}
// check for [], [''] or ['Someone', '']

View File

@ -98,7 +98,7 @@ describe('router', () => {
},
message: 'request returned 1 route',
});
});
}, 30000);
it(`/api/routes`, async () => {
const response = await request.get('/api/routes');
expect(response.status).toBe(200);

View File

@ -26,15 +26,15 @@ describe('rand-user-agent', () => {
});
it('should match ua configurated', async () => {
const response1 = await got('https://www.whatsmyua.info/api/v1/ua');
expect(response1.data[0].ua.rawUa).toBe(config.ua);
const response1 = await got('https://httpbingo.org/user-agent');
expect(response1.data['user-agent']).toBe(config.ua);
const response2 = await got('https://www.whatsmyua.info/api/v1/ua', {
const response2 = await got('https://httpbingo.org/user-agent', {
headers: {
'user-agent': mobileUa,
},
});
expect(response2.data[0].ua.rawUa).toBe(mobileUa);
expect(response2.data[0].ua.rawUa).not.toBe(config.ua);
expect(response2.data['user-agent']).toBe(mobileUa);
expect(response2.data['user-agent']).not.toBe(config.ua);
});
});