-
Notifications
You must be signed in to change notification settings - Fork 20
/
mina-runtime-plugin.js
74 lines (67 loc) · 2.03 KB
/
mina-runtime-plugin.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
67
68
69
70
71
72
73
74
import path from 'path'
import test from 'ava'
import MinaRuntimePlugin from '@tinajs/mina-runtime-webpack-plugin'
import compiler from './helpers/compiler'
const resolveRelative = path.resolve.bind(null, __dirname)
test('use MinaRuntimePlugin', async t => {
const { compile, mfs } = compiler({
context: resolveRelative('fixtures/basic'),
entry: {
'app.js': './app.mina',
'page.js': './page.mina',
},
output: {
filename: '[name]',
globalObject: 'wx',
},
plugins: [new MinaRuntimePlugin()],
optimization: {
splitChunks: {
chunks: 'all',
name: 'common.js',
minChunks: 2,
minSize: 0,
},
runtimeChunk: {
name: 'runtime.js',
},
},
})
await compile()
const expectedStartsWith = `;require('./runtime.js');require('./common.js');(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push(`
const expectedRuntimeIncludes = `polyfill('parseInt', parseInt)`
t.true(mfs.existsSync('/runtime.js'))
t.true(
mfs.readFileSync('/runtime.js', 'utf8').includes(expectedRuntimeIncludes)
)
t.true(mfs.existsSync('/common.js'))
t.true(
mfs.readFileSync('/common.js', 'utf8').includes("console.log('\\u2665')")
)
t.true(
mfs
.readFileSync('/common.js', 'utf8')
.includes("console.log('\\ud83d\\udc95')")
)
t.true(mfs.readFileSync('/app.js', 'utf8').startsWith(expectedStartsWith))
t.true(mfs.readFileSync('/page.js', 'utf8').startsWith(expectedStartsWith))
t.true(mfs.readFileSync('/app.js', 'utf8').includes('Hello from App!'))
t.true(mfs.readFileSync('/page.js', 'utf8').includes('Hello from Page!'))
t.false(
mfs.readFileSync('/app.js', 'utf8').includes("console.log('\\u2665')")
)
t.false(
mfs
.readFileSync('/app.js', 'utf8')
.includes("console.log('\\ud83d\\udc95')")
)
t.false(
mfs.readFileSync('/page.js', 'utf8').includes("console.log('\\u2665')")
)
t.false(
mfs
.readFileSync('/page.js', 'utf8')
.includes("console.log('\\ud83d\\udc95')")
)
t.pass()
})