-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
54 lines (47 loc) · 1.21 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
const path = require('path')
const test = require('ava')
const webpack = require('webpack')
const MemoryFS = require('memory-fs')
const fs = new MemoryFS()
const build = (entry, options = {}) => {
const config = {
mode: 'development',
entry,
output: {
path: path.resolve(__dirname),
filename: 'bundle.js'
},
module: {
rules: [
{
loader: path.resolve(__dirname, './index'),
options
}
]
}
}
const compiler = webpack(config)
compiler.outputFileSystem = fs
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err) reject(err)
const mod = stats.toJson().modules.find(m => m.name === entry).source
resolve(mod)
})
})
}
test('renders JSX', async t => {
const mod = await build('./examples/index.jsx', {})
t.snapshot(mod)
})
test('renders JSX with scope in front matter', async t => {
const mod = await build('./examples/scoped.jsx', {})
t.snapshot(mod)
})
test('renders with scope from loader options', async t => {
const mod = await build('./examples/options-scope.jsx', {
scope: `import * as scope from 'grid-styled'`
})
console.log('module', mod)
t.snapshot(mod)
})