| 53 | |
| 54 | describe('Color logs', () => { |
| 55 | const createColorTest = (status, color, done) => { |
| 56 | return async () => { |
| 57 | const customOutput = (log: string) => { |
| 58 | if (color === 'cyan') { |
| 59 | expect(log.split(' ')[1]).toMatch(cyan(bold(status).toString())) |
| 60 | } else if (color === 'red') { |
| 61 | expect(log.split(' ')[1]).toMatch(red(bold(status).toString())) |
| 62 | } else if (color === 'magenta') { |
| 63 | expect(log.split(' ')[1]).toMatch(magenta(bold(status).toString())) |
| 64 | } |
| 65 | done() |
| 66 | } |
| 67 | |
| 68 | const app = new App() |
| 69 | |
| 70 | app.use(logger({ output: { callback: customOutput, color: true } })) |
| 71 | app.get('/', (_, res) => res.status(status).send('')) |
| 72 | |
| 73 | const server = app.listen() |
| 74 | |
| 75 | await makeFetch(server)('/').expect(status) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | it('should color 2xx cyan', (done) => { |
| 80 | createColorTest(200, 'cyan', done)() |