({
withFetchesLogging,
withFullUrlFetches = false,
}: {
withFetchesLogging: boolean
withFullUrlFetches?: boolean
})
| 85 | files: __dirname, |
| 86 | }) |
| 87 | function runTests({ |
| 88 | withFetchesLogging, |
| 89 | withFullUrlFetches = false, |
| 90 | }: { |
| 91 | withFetchesLogging: boolean |
| 92 | withFullUrlFetches?: boolean |
| 93 | }) { |
| 94 | if (withFetchesLogging) { |
| 95 | it('should only log requests in development mode', async () => { |
| 96 | const outputIndex = next.cliOutput.length |
| 97 | await next.fetch('/default-cache') |
| 98 | |
| 99 | await retry(() => { |
| 100 | const logs = stripAnsi(next.cliOutput.slice(outputIndex)) |
| 101 | if (isNextDev) { |
| 102 | expect(logs).toContain('GET /default-cache 200') |
| 103 | } else { |
| 104 | expect(logs).not.toContain('GET /default-cache 200') |
| 105 | } |
| 106 | }) |
| 107 | }) |
| 108 | |
| 109 | if (isNextDev) { |
| 110 | it("should log 'skip' cache status with a reason when cache: 'no-cache' is used", async () => { |
| 111 | const outputIndex = next.cliOutput.length |
| 112 | await next.fetch('/default-cache') |
| 113 | |
| 114 | await retry(() => { |
| 115 | const logs = parseLogsFromCli(next.cliOutput.slice(outputIndex)) |
| 116 | |
| 117 | const logEntry = logs.find((log) => |
| 118 | log.url.includes('api/random?no-cache') |
| 119 | ) |
| 120 | |
| 121 | expect(logs.some((log) => log.url.includes('..'))).toBe( |
| 122 | !withFullUrlFetches |
| 123 | ) |
| 124 | |
| 125 | expect(logEntry?.cache).toBe('cache: no-cache') |
| 126 | }) |
| 127 | }) |
| 128 | |
| 129 | it("should log 'skip' cache status with a reason when revalidate: 0 is used", async () => { |
| 130 | const outputIndex = next.cliOutput.length |
| 131 | await next.fetch('/default-cache') |
| 132 | await retry(() => { |
| 133 | const logs = parseLogsFromCli(next.cliOutput.slice(outputIndex)) |
| 134 | |
| 135 | const logEntry = logs.find((log) => |
| 136 | log.url.includes('api/random?revalidate-0') |
| 137 | ) |
| 138 | |
| 139 | expect(logEntry?.cache).toBe('revalidate: 0') |
| 140 | }) |
| 141 | }) |
| 142 | |
| 143 | it("should log 'skip' cache status with a reason when the browser indicates caching should be ignored", async () => { |
| 144 | const outputIndex = next.cliOutput.length |
no test coverage detected