This repository has been archived by the owner on Oct 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
66 lines (61 loc) · 1.58 KB
/
test.js
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
let test = require('tape')
let plugin = require('./index') // note package.json "main" points to dist
let mock = require('./mock')
test('env', t=> {
t.plan(1)
t.ok(plugin, 'exists')
})
test('isBase64Encoded', t=> {
t.plan(1)
let {Key, config, defaults} = mock
let result = plugin(Key, defaults)
t.ok(result, 'got result')
console.log(result)
})
test('returns {body, headers}', t=> {
t.plan(2)
let Key = 'static/foo.mjs'
let src = `
import foo from '/bar'
let baz = 6
`
let result = plugin(Key, {
headers: {'content-type':'text/javascript;charset=utf8'},
body: src
})
t.ok(result.headers, 'has headers')
t.ok(result.body, 'has body')
console.log(result)
})
test('adds staging prefix when Key starts with "staging"', t=> {
t.plan(1)
process.env.NODE_ENV = 'staging'
let Key = 'staging/foo.mjs'
let src = `
import foo from '/bar'
let baz = 6
`
let result = plugin(Key, {
headers: {'content-type':'text/javascript;charset=utf8'},
body: src
})
let snapshot = "import foo from '/staging"
t.ok(result.body.startsWith(snapshot), 'prepended staging')
console.log(result)
})
test('adds production prefix when Key starts with "production"', t=> {
t.plan(1)
process.env.NODE_ENV = 'production'
let Key = 'production/foo.mjs'
let src = `
import foo from '/bar'
let baz = 6
`
let result = plugin(Key, {
headers: {'content-type':'text/javascript;charset=utf8'},
body: src
})
let snapshot = "import foo from '/production"
t.ok(result.body.startsWith(snapshot), 'prepended production')
console.log(result)
})