Repository navigation
Expand file tree
/
Copy pathstatic-assets.js
More file actions
101 lines (92 loc) · 3.39 KB
/
Copy pathstatic-assets.js
File metadata and controls
101 lines (92 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import nock from 'nock'
import { expect, jest } from '@jest/globals'
import { get } from '../helpers/supertest.js'
import { checkCachingHeaders } from '../helpers/caching-headers.js'
describe('archived enterprise static assets', () => {
// Sometimes static assets are proxied. The URL for the static asset
// might not indicate it's based on archived enterprise version.
jest.setTimeout(60 * 1000)
beforeAll(async () => {
// The first page load takes a long time so let's get it out of the way in
// advance to call out that problem specifically rather than misleadingly
// attributing it to the first test
// await get('/')
const sampleCSS = '/* nice CSS */'
nock('https://github.github.com')
.get('/help-docs-archived-enterprise-versions/2.21/_next/static/foo.css')
.reply(200, sampleCSS, {
'content-type': 'text/css',
'content-length': sampleCSS.length,
})
nock('https://github.github.com')
.get('/help-docs-archived-enterprise-versions/2.21/_next/static/only-on-proxy.css')
.reply(200, sampleCSS, {
'content-type': 'text/css',
'content-length': sampleCSS.length,
})
nock('https://github.github.com')
.get('/help-docs-archived-enterprise-versions/2.3/_next/static/only-on-2.3.css')
.reply(200, sampleCSS, {
'content-type': 'text/css',
'content-length': sampleCSS.length,
})
nock('https://github.github.com')
.get('/help-docs-archived-enterprise-versions/2.3/_next/static/fourofour.css')
.reply(404, 'Not found', {
'content-type': 'text/plain',
})
nock('https://github.github.com')
.get('/help-docs-archived-enterprise-versions/2.3/assets/images/site/logo.png')
.reply(404, 'Not found', {
'content-type': 'text/plain',
})
})
afterAll(() => nock.cleanAll())
it('should proxy if the static asset is prefixed', async () => {
const res = await get('/enterprise/2.21/_next/static/foo.css', {
headers: {
Referrer: '/enterprise/2.21',
},
})
expect(res.statusCode).toBe(200)
checkCachingHeaders(res, true, 60)
})
it('should proxy if the Referrer header indicates so', async () => {
const res = await get('/_next/static/only-on-proxy.css', {
headers: {
Referrer: '/enterprise/2.21',
},
})
expect(res.statusCode).toBe(200)
checkCachingHeaders(res, true, 60)
})
it('should proxy if the Referrer header indicates so', async () => {
const res = await get('/_next/static/only-on-2.3.css', {
headers: {
Referrer: '/en/enterprise-server@2.3/some/page',
},
})
expect(res.statusCode).toBe(200)
checkCachingHeaders(res, true, 60)
})
it('might still 404 even with the right referrer', async () => {
const res = await get('/_next/static/fourofour.css', {
headers: {
Referrer: '/en/enterprise-server@2.3/some/page',
},
})
expect(res.statusCode).toBe(404)
checkCachingHeaders(res, true, 60)
})
it('404 on the proxy but actually present here', async () => {
const res = await get('/assets/images/site/logo.png', {
headers: {
Referrer: '/en/enterprise-server@2.3/some/page',
},
})
// It tried to go via the proxy, but it wasn't there, but then it
// tried "our disk" and it's eventually there.
expect(res.statusCode).toBe(200)
checkCachingHeaders(res, true, 60)
})
})