|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const request = require('supertest'); |
| 4 | +const helper = require('./helper'); |
| 5 | +const config = require('./fixtures/simple-config/webpack.config'); |
| 6 | + |
| 7 | +describe('Before And After options', () => { |
| 8 | + let server; |
| 9 | + let req; |
| 10 | + |
| 11 | + beforeAll((done) => { |
| 12 | + server = helper.start( |
| 13 | + config, |
| 14 | + { |
| 15 | + before: (app, server, compiler) => { |
| 16 | + if (!app) { |
| 17 | + throw new Error('app is not defined'); |
| 18 | + } |
| 19 | + |
| 20 | + if (!server) { |
| 21 | + throw new Error('server is not defined'); |
| 22 | + } |
| 23 | + |
| 24 | + if (!compiler) { |
| 25 | + throw new Error('compiler is not defined'); |
| 26 | + } |
| 27 | + |
| 28 | + app.get('/before/some/path', (req, res) => { |
| 29 | + res.send('before'); |
| 30 | + }); |
| 31 | + }, |
| 32 | + after: (app, server, compiler) => { |
| 33 | + if (!app) { |
| 34 | + throw new Error('app is not defined'); |
| 35 | + } |
| 36 | + |
| 37 | + if (!server) { |
| 38 | + throw new Error('server is not defined'); |
| 39 | + } |
| 40 | + |
| 41 | + if (!compiler) { |
| 42 | + throw new Error('compiler is not defined'); |
| 43 | + } |
| 44 | + |
| 45 | + app.get('/after/some/path', (req, res) => { |
| 46 | + res.send('after'); |
| 47 | + }); |
| 48 | + }, |
| 49 | + }, |
| 50 | + done |
| 51 | + ); |
| 52 | + req = request(server.app); |
| 53 | + }); |
| 54 | + |
| 55 | + afterAll(helper.close); |
| 56 | + |
| 57 | + it('should handle before route', () => { |
| 58 | + return req |
| 59 | + .get('/before/some/path') |
| 60 | + .expect('Content-Type', 'text/html; charset=utf-8') |
| 61 | + .expect(200) |
| 62 | + .then((response) => { |
| 63 | + expect(response.text).toBe('before'); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should handle after route', () => { |
| 68 | + return req |
| 69 | + .get('/after/some/path') |
| 70 | + .expect('Content-Type', 'text/html; charset=utf-8') |
| 71 | + .expect(200) |
| 72 | + .then((response) => { |
| 73 | + expect(response.text).toBe('after'); |
| 74 | + }); |
| 75 | + }); |
| 76 | +}); |
0 commit comments