-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_test.ts
44 lines (42 loc) · 1.5 KB
/
mod_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { ConnInfo } from './dev_depts.ts';
import { describe, expect, it, makeFetch, run } from './dev_depts.ts';
import { logger } from './mod.ts';
describe('Basic tests', () => {
it('should write logs', async () => {
const callback = (line: string) => {
console.log(line);
expect(line).toEqual('[LOG] 127.0.0.1 GET / http');
};
const handler = (req: Request, connInfo: ConnInfo) => {
const res = new Response('hello world', { status: 200 });
logger({ transports: [{ callback }], ip: true })(req, res, connInfo);
return res;
};
(await makeFetch(handler)('/')).expectStatus(200);
});
it('should take multiple call backs', async () => {
const callback1 = (line: string) => {
expect(line).toEqual('[LOG] GET / http');
};
const callback2 = (line: string) => {
expect(line).toEqual('[LOG] GET / http');
};
const handler = (req: Request, connInfo: ConnInfo) => {
const res = new Response('hello world', { status: 200 });
logger({
transports: [{ callback: callback1 }, { callback: callback2 }],
})(req, res, connInfo);
return res;
};
(await makeFetch(handler)('/')).expectStatus(200);
});
it('should use default options if not supplied', async () => {
const handler = (req: Request, connInfo: ConnInfo) => {
const res = new Response('hello world', { status: 200 });
logger()(req, res, connInfo);
return res;
};
(await makeFetch(handler)('/')).expectStatus(200);
});
});
run();