1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Add test for cache-control in development

This commit is contained in:
Tim Neutkens 2018-09-12 14:42:50 +02:00
parent 12c0c9fd40
commit 873ac5dba8

View file

@ -1,6 +1,8 @@
/* global describe, test, it, expect */ /* global describe, test, it, expect */
import cheerio from 'cheerio' import cheerio from 'cheerio'
import {BUILD_MANIFEST, REACT_LOADABLE_MANIFEST} from 'next/constants'
import { join } from 'path'
export default function ({ app }, suiteName, render, fetch, appPort) { export default function ({ app }, suiteName, render, fetch, appPort) {
async function get$ (path, query) { async function get$ (path, query) {
@ -164,6 +166,44 @@ export default function ({ app }, suiteName, render, fetch, appPort) {
// Sourcemaps are applied by react-error-overlay, so we can't check them on SSR. // Sourcemaps are applied by react-error-overlay, so we can't check them on SSR.
}) })
it('should set Cache-Control header', async () => {
const buildId = 'development'
// build dynamic page
await fetch('/dynamic/ssr')
const buildManifest = require(join('../.next', BUILD_MANIFEST))
console.log(buildManifest)
const reactLoadableManifest = require(join('../.next', REACT_LOADABLE_MANIFEST))
const resources = []
// test a regular page
resources.push(`/_next/static/${buildId}/pages/index.js`)
// test dynamic chunk
resources.push('/_next/' + reactLoadableManifest['../../components/hello1'][0].publicPath)
// test main.js runtime etc
for (const item of buildManifest.pages['/dynamic/ssr']) {
resources.push('/_next/' + item)
}
for (const item of buildManifest.devFiles) {
resources.push('/_next/' + item)
}
const responses = await Promise.all(resources.map((resource) => fetch(resource)))
responses.forEach((res) => {
try {
expect(res.headers.get('Cache-Control')).toBe('no-store, must-revalidate')
} catch (err) {
err.message = res.url + ' ' + err.message
throw err
}
})
})
test('asPath', async () => { test('asPath', async () => {
const $ = await get$('/nav/as-path', { aa: 10 }) const $ = await get$('/nav/as-path', { aa: 10 })
expect($('.as-path-content').text()).toBe('/nav/as-path?aa=10') expect($('.as-path-content').text()).toBe('/nav/as-path?aa=10')