(isDev: boolean)
| 55 | const pagesDir = join(appDir, '.next/server/pages') |
| 56 | |
| 57 | function runTests(isDev: boolean) { |
| 58 | if (!isDev) { |
| 59 | it('should output paths correctly', async () => { |
| 60 | for (const path of prerenderedPaths) { |
| 61 | for (const mode of modePaths) { |
| 62 | console.log('checking output', { path, mode }) |
| 63 | expect(fs.existsSync(join(pagesDir, mode, path + '.html'))).toBe(true) |
| 64 | expect(fs.existsSync(join(pagesDir, mode, path + '.json'))).toBe(true) |
| 65 | } |
| 66 | } |
| 67 | }) |
| 68 | |
| 69 | it('should handle non-prerendered paths correctly', async () => { |
| 70 | const prerenderedPaths = [ |
| 71 | '%2Fanother-post%2F', |
| 72 | '+another-post+', |
| 73 | '%3Fanother-post%3F', |
| 74 | '&another-post&', |
| 75 | '商業日語商業日語', |
| 76 | ] |
| 77 | |
| 78 | const urlPaths = [ |
| 79 | '%2Fanother-post%2F', |
| 80 | '%2Banother-post%2B', |
| 81 | '%3Fanother-post%3F', |
| 82 | '%26another-post%26', |
| 83 | encodeURIComponent('商業日語商業日語'), |
| 84 | ] |
| 85 | |
| 86 | for (const mode of modePaths) { |
| 87 | for (let i = 0; i < urlPaths.length; i++) { |
| 88 | const testSlug = urlPaths[i] |
| 89 | const path = prerenderedPaths[i] |
| 90 | |
| 91 | const res = await fetchViaHTTP( |
| 92 | appPort, |
| 93 | `/_next/data/${buildId}/${mode}/${testSlug}.json` |
| 94 | ) |
| 95 | |
| 96 | if (mode === 'fallback-false') { |
| 97 | expect(res.status).toBe(404) |
| 98 | } else { |
| 99 | expect(res.status).toBe(200) |
| 100 | |
| 101 | const { pageProps: props } = await res.json() |
| 102 | |
| 103 | expect(props.params).toEqual({ |
| 104 | slug: decodeURIComponent(testSlug), |
| 105 | }) |
| 106 | |
| 107 | if (!isDev) { |
| 108 | // we don't block on writing incremental data to the |
| 109 | // disk so use check |
| 110 | await check( |
| 111 | () => fs.existsSync(join(pagesDir, mode, path + '.html')), |
| 112 | true |
| 113 | ) |
| 114 | await check( |
no test coverage detected