({ addAfterStart }: { addAfterStart?: boolean })
| 18 | const indexPage = 'pages/index.tsx' |
| 19 | |
| 20 | function runTests({ addAfterStart }: { addAfterStart?: boolean }) { |
| 21 | beforeAll(async () => { |
| 22 | let tsConfigContent = await fs.readFile( |
| 23 | join(__dirname, 'app/tsconfig.json'), |
| 24 | 'utf8' |
| 25 | ) |
| 26 | |
| 27 | next = await createNext({ |
| 28 | files: { |
| 29 | components: new FileRef(join(__dirname, 'app/components')), |
| 30 | pages: new FileRef(join(__dirname, 'app/pages')), |
| 31 | lib: new FileRef(join(__dirname, 'app/lib')), |
| 32 | ...(addAfterStart |
| 33 | ? {} |
| 34 | : { |
| 35 | [tsConfigFile]: tsConfigContent, |
| 36 | }), |
| 37 | }, |
| 38 | dependencies: { |
| 39 | typescript: 'latest', |
| 40 | '@types/react': 'latest', |
| 41 | '@types/node': 'latest', |
| 42 | }, |
| 43 | }) |
| 44 | |
| 45 | if (addAfterStart) { |
| 46 | await next.patchFile(tsConfigFile, tsConfigContent) |
| 47 | } |
| 48 | }) |
| 49 | afterAll(() => next.destroy()) |
| 50 | |
| 51 | it('should load with initial paths config correctly', async () => { |
| 52 | const html = await renderViaHTTP(next.url, '/') |
| 53 | const $ = cheerio.load(html) |
| 54 | expect(html).toContain('first button') |
| 55 | expect(html).toContain('second button') |
| 56 | expect($('#first-data').text()).toContain( |
| 57 | JSON.stringify({ |
| 58 | hello: 'world', |
| 59 | }) |
| 60 | ) |
| 61 | }) |
| 62 | |
| 63 | it('should recover from module not found when paths is updated', async () => { |
| 64 | const indexContent = await next.readFile(indexPage) |
| 65 | const tsconfigContent = await next.readFile(tsConfigFile) |
| 66 | const parsedTsConfig = JSON.parse(tsconfigContent) |
| 67 | |
| 68 | const browser = await webdriver(next.url, '/') |
| 69 | |
| 70 | try { |
| 71 | const html = await browser.eval('document.documentElement.innerHTML') |
| 72 | expect(html).toContain('first button') |
| 73 | expect(html).toContain('second button') |
| 74 | expect(html).toContain('id="first-data"') |
| 75 | expect(html).not.toContain('id="second-data"') |
| 76 | |
| 77 | await next.patchFile( |
no test coverage detected