(isDev: boolean = false, isDeploy: boolean)
| 559 | } |
| 560 | |
| 561 | const runTests = (isDev: boolean = false, isDeploy: boolean) => { |
| 562 | navigateTest(isDev) |
| 563 | |
| 564 | it('should respond with 405 for POST to static page', async () => { |
| 565 | const res = await fetchViaHTTP(next.url, '/', undefined, { |
| 566 | method: 'POST', |
| 567 | }) |
| 568 | expect(res.status).toBe(405) |
| 569 | |
| 570 | if (!isDeploy) { |
| 571 | expect(await res.text()).toContain('Method Not Allowed') |
| 572 | } |
| 573 | }) |
| 574 | |
| 575 | it('should SSR normal page correctly', async () => { |
| 576 | const html = await renderViaHTTP(next.url, '/') |
| 577 | expect(html).toMatch(/hello.*?world/) |
| 578 | }) |
| 579 | |
| 580 | it('should SSR incremental page correctly', async () => { |
| 581 | const html = await renderViaHTTP(next.url, '/blog/post-1') |
| 582 | |
| 583 | const $ = cheerio.load(html) |
| 584 | expect(JSON.parse($('#__NEXT_DATA__').text()).isFallback).toBe(false) |
| 585 | expect(html).toMatch(/Post:.*?post-1/) |
| 586 | }) |
| 587 | |
| 588 | it('should SSR blocking path correctly (blocking)', async () => { |
| 589 | const html = await renderViaHTTP( |
| 590 | next.url, |
| 591 | '/blocking-fallback/random-path' |
| 592 | ) |
| 593 | const $ = cheerio.load(html) |
| 594 | expect(JSON.parse($('#__NEXT_DATA__').text()).isFallback).toBe(false) |
| 595 | expect($('p').text()).toBe('Post: random-path') |
| 596 | }) |
| 597 | |
| 598 | it('should SSR blocking path correctly (pre-rendered)', async () => { |
| 599 | const html = await renderViaHTTP(next.url, '/blocking-fallback-some/a') |
| 600 | const $ = cheerio.load(html) |
| 601 | expect(JSON.parse($('#__NEXT_DATA__').text()).isFallback).toBe(false) |
| 602 | expect($('p').text()).toBe('Post: a') |
| 603 | }) |
| 604 | |
| 605 | it('should have gsp in __NEXT_DATA__', async () => { |
| 606 | const html = await renderViaHTTP(next.url, '/') |
| 607 | const $ = cheerio.load(html) |
| 608 | expect(JSON.parse($('#__NEXT_DATA__').text()).gsp).toBe(true) |
| 609 | }) |
| 610 | |
| 611 | it('should not have gsp in __NEXT_DATA__ for non-GSP page', async () => { |
| 612 | const html = await renderViaHTTP(next.url, '/normal') |
| 613 | const $ = cheerio.load(html) |
| 614 | expect('gsp' in JSON.parse($('#__NEXT_DATA__').text())).toBe(false) |
| 615 | }) |
| 616 | |
| 617 | it('should not supply query values to params or useRouter non-dynamic page SSR', async () => { |
| 618 | const html = await renderViaHTTP(next.url, '/something?hello=world') |
no test coverage detected