| import { FileRef, nextTestSetup } from 'e2e-utils' |
| import { createRouterAct } from 'router-act' |
| import { createTimeController } from './test-utils' |
| import { join } from 'path' |
|
|
| describe('app dir - prefetching (custom staleTime)', () => { |
| const { next, isNextDev } = nextTestSetup({ |
| files: { |
| app: new FileRef(join(__dirname, 'app')), |
| }, |
| skipDeployment: true, |
| nextConfig: { |
| experimental: { |
| staleTimes: { |
| static: 30, |
| dynamic: 5, |
| }, |
| }, |
| }, |
| }) |
|
|
| if (isNextDev) { |
| it('should skip next dev for now', () => {}) |
| return |
| } |
|
|
| it('should not fetch again when a static page was prefetched when navigating to it twice', async () => { |
| let act: ReturnType<typeof createRouterAct> |
| const browser = await next.browser('/', { |
| beforePageLoad(page) { |
| act = createRouterAct(page) |
| }, |
| }) |
|
|
| |
| const link = await act( |
| async () => { |
| const reveal = await browser.elementByCss('#accordion-to-static-page') |
| await reveal.click() |
| return browser.elementByCss('#to-static-page') |
| }, |
| { includes: 'Static Page [prefetch-sentinel]' } |
| ) |
|
|
| |
| await act(async () => { |
| await link.click() |
| const staticPageText = await browser.elementByCss('#static-page').text() |
| expect(staticPageText).toBe('Static Page [prefetch-sentinel]') |
| }, 'no-requests') |
|
|
| |
| |
| |
| |
| const reveal = await browser.elementByCss('#accordion-to-home') |
| await reveal.click() |
| const homeLink = await browser.waitForElementByCss('#to-home') |
| await homeLink.click() |
| await browser.waitForElementByCss('#accordion-to-static-page') |
|
|
| |
| await browser.elementByCss('#accordion-to-static-page').click() |
| await browser.waitForElementByCss('#to-static-page') |
|
|
| |
| const staticPageText = await act(async () => { |
| await browser.elementByCss('#to-static-page').click() |
| return browser.elementByCss('#static-page').text() |
| }, 'no-requests') |
|
|
| expect(staticPageText).toBe('Static Page [prefetch-sentinel]') |
| }) |
|
|
| it('should fetch again when a static page was prefetched when navigating to it after the stale time has passed', async () => { |
| let act: ReturnType<typeof createRouterAct> |
| const timeController = createTimeController() |
| const browser = await next.browser('/', { |
| beforePageLoad(page) { |
| act = createRouterAct(page) |
| }, |
| }) |
|
|
| |
| await timeController.install(browser) |
|
|
| |
| let link = await act( |
| async () => { |
| const reveal = await browser.elementByCss('#accordion-to-static-page') |
| await reveal.click() |
| return browser.elementByCss('#to-static-page') |
| }, |
| { includes: 'Static Page [prefetch-sentinel]' } |
| ) |
|
|
| |
| await act(async () => { |
| await link.click() |
| await browser.waitForElementByCss('#static-page') |
| }, 'no-requests') |
|
|
| |
| const reveal = await browser.elementByCss('#accordion-to-home') |
| await reveal.click() |
| const homeLink = await browser.waitForElementByCss('#to-home') |
| await homeLink.click() |
| await browser.waitForElementByCss('#accordion-to-static-page') |
|
|
| |
| await timeController.advance(browser, 31000) |
|
|
| |
| link = await act( |
| async () => { |
| const reveal = await browser.elementByCss('#accordion-to-static-page') |
| await reveal.click() |
| return browser.elementByCss('#to-static-page') |
| }, |
| { includes: 'Static Page [prefetch-sentinel]' } |
| ) |
|
|
| |
| await act(async () => { |
| await link.click() |
| await browser.waitForElementByCss('#static-page') |
| }, 'no-requests') |
| }) |
|
|
| |
| it.skip('should not re-fetch cached data when navigating back to a route group', async () => { |
| let act: ReturnType<typeof createRouterAct> |
| |
| createTimeController() |
| const browser = await next.browser('/prefetch-auto-route-groups', { |
| beforePageLoad(page) { |
| act = createRouterAct(page) |
| }, |
| }) |
|
|
| |
| expect(await browser.elementById('count').text()).toBe('1') |
|
|
| |
| await act(async () => { |
| await browser |
| .elementByCss("[href='/prefetch-auto-route-groups/sub/foo']") |
| .click() |
| }) |
|
|
| |
| await act(async () => { |
| await browser.elementByCss("[href='/prefetch-auto-route-groups']").click() |
| |
| }, 'no-requests') |
|
|
| expect(await browser.elementById('count').text()).toBe('1') |
|
|
| |
| await act(async () => { |
| await browser |
| .elementByCss("[href='/prefetch-auto-route-groups/sub/bar']") |
| .click() |
| }) |
|
|
| |
| await act(async () => { |
| await browser.elementByCss("[href='/prefetch-auto-route-groups']").click() |
| }, 'no-requests') |
|
|
| |
| expect(await browser.elementById('count').text()).toBe('1') |
|
|
| |
| await browser.refresh() |
|
|
| |
| expect(await browser.elementById('count').text()).toBe('4') |
| }) |
|
|
| it('should fetch again when the initially visited static page is visited after the stale time has passed', async () => { |
| let act: ReturnType<typeof createRouterAct> |
| const timeController = createTimeController() |
| const browser = await next.browser('/static-page-no-prefetch', { |
| beforePageLoad(page) { |
| act = createRouterAct(page) |
| }, |
| }) |
|
|
| |
| await timeController.install(browser) |
|
|
| |
| await browser.waitForElementByCss('#static-page-no-prefetch') |
|
|
| |
| const homeLink = await act( |
| async () => { |
| const reveal = await browser.elementByCss('#accordion-to-home') |
| await reveal.click() |
| return browser.elementByCss('#to-home') |
| }, |
| { includes: 'Home Page [prefetch-sentinel]' } |
| ) |
|
|
| |
| await homeLink.click() |
| await browser.waitForElementByCss('#accordion-to-static-page') |
|
|
| |
| await timeController.advance(browser, 31000) |
|
|
| |
| const link = await act( |
| async () => { |
| const reveal = await browser.elementByCss( |
| '#accordion-to-static-page-no-prefetch' |
| ) |
| await reveal.click() |
| return browser.elementByCss('#to-static-page-no-prefetch') |
| }, |
| { includes: 'Static Page No Prefetch [prefetch-sentinel]' } |
| ) |
|
|
| |
| const staticPageText = await act(async () => { |
| await link.click() |
| return browser.elementByCss('#static-page-no-prefetch').text() |
| }, 'no-requests') |
| expect(staticPageText).toBe('Static Page No Prefetch [prefetch-sentinel]') |
| }) |
|
|
| it('should renew the stale time after refetching expired RSC data', async () => { |
| let act: ReturnType<typeof createRouterAct> |
| const timeController = createTimeController() |
| const browser = await next.browser('/', { |
| beforePageLoad(page) { |
| act = createRouterAct(page) |
| }, |
| }) |
|
|
| |
| await timeController.install(browser) |
|
|
| |
| let link = await act( |
| async () => { |
| const reveal = await browser.elementByCss('#accordion-to-static-page') |
| await reveal.click() |
| return browser.elementByCss('#to-static-page') |
| }, |
| { includes: 'Static Page [prefetch-sentinel]' } |
| ) |
|
|
| |
| await act(async () => { |
| await link.click() |
| await browser.waitForElementByCss('#static-page') |
| }, 'no-requests') |
|
|
| |
| |
| |
| |
| const reveal = await browser.elementByCss('#accordion-to-home') |
| await reveal.click() |
| const homeLink = await browser.waitForElementByCss('#to-home') |
| await homeLink.click() |
| await browser.waitForElementByCss('#accordion-to-static-page') |
|
|
| |
| await timeController.advance(browser, 31000) |
|
|
| |
| link = await act( |
| async () => { |
| const reveal = await browser.elementByCss('#accordion-to-static-page') |
| await reveal.click() |
| return browser.elementByCss('#to-static-page') |
| }, |
| { includes: 'Static Page [prefetch-sentinel]' } |
| ) |
|
|
| |
| await act(async () => { |
| await link.click() |
| await browser.waitForElementByCss('#static-page') |
| }, 'no-requests') |
|
|
| |
| |
| const reveal2 = await browser.elementByCss('#accordion-to-home') |
| await reveal2.click() |
| const homeLink2 = await browser.waitForElementByCss('#to-home') |
| await homeLink2.click() |
| await browser.waitForElementByCss('#accordion-to-static-page') |
|
|
| |
| await timeController.advance(browser, 20000) |
|
|
| |
| link = await act(async () => { |
| const reveal = await browser.elementByCss('#accordion-to-static-page') |
| await reveal.click() |
| return browser.elementByCss('#to-static-page') |
| }, 'no-requests') |
|
|
| |
| |
| const staticPageText = await act(async () => { |
| await link.click() |
| return browser.elementByCss('#static-page').text() |
| }, 'no-requests') |
| expect(staticPageText).toBe('Static Page [prefetch-sentinel]') |
| }) |
| }) |
|
|