/
fs-serve.spec.ts
73 lines (60 loc) · 2.28 KB
/
fs-serve.spec.ts
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
import { isBuild } from '../../testUtils'
const json = require('../safe.json')
const stringified = JSON.stringify(json)
describe('main', () => {
beforeAll(async () => {
// viteTestUrl is globally injected in scripts/jestPerTestSetup.ts
await page.goto(viteTestUrl + '/src/')
})
if (!isBuild) {
test('default import', async () => {
expect(await page.textContent('.full')).toBe(stringified)
})
test('named import', async () => {
expect(await page.textContent('.named')).toBe(json.msg)
})
test('safe fetch', async () => {
expect(await page.textContent('.safe-fetch')).toMatch('KEY=safe')
expect(await page.textContent('.safe-fetch-status')).toBe('200')
})
test('safe fetch with special characters', async () => {
expect(
await page.textContent('.safe-fetch-subdir-special-characters')
).toMatch('KEY=safe')
expect(
await page.textContent('.safe-fetch-subdir-special-characters-status')
).toBe('200')
})
test('unsafe fetch', async () => {
expect(await page.textContent('.unsafe-fetch')).toMatch('403 Restricted')
expect(await page.textContent('.unsafe-fetch-status')).toBe('403')
})
test('safe fs fetch', async () => {
expect(await page.textContent('.safe-fs-fetch')).toBe(stringified)
expect(await page.textContent('.safe-fs-fetch-status')).toBe('200')
})
test('safe fs fetch with special characters', async () => {
expect(await page.textContent('.safe-fs-fetch-special-characters')).toBe(
stringified
)
expect(await page.textContent('.safe-fs-fetch-status')).toBe('200')
})
test('unsafe fs fetch', async () => {
expect(await page.textContent('.unsafe-fs-fetch')).toBe('')
expect(await page.textContent('.unsafe-fs-fetch-status')).toBe('403')
})
test('nested entry', async () => {
expect(await page.textContent('.nested-entry')).toBe('foobar')
})
test('nested entry', async () => {
expect(await page.textContent('.nested-entry')).toBe('foobar')
})
test('denied', async () => {
expect(await page.textContent('.unsafe-dotenv')).toBe('404')
})
} else {
test('dummy test to make jest happy', async () => {
// Your test suite must contain at least one test.
})
}
})