-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.js
124 lines (103 loc) · 3.13 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const spawn = require('child_process').spawn
const which = require('npm-which')
const test = require('tape')
const path = require('path')
const fs = require('fs')
const vm = require('vm')
test('ify-loader', function (t) {
const wpack = which.sync('webpack', { cwd: __dirname })
const input = path.join(__dirname, 'fixtures', 'basic', 'index.js')
const output = path.join(__dirname, 'fixtures', 'basic', 'bundle.js')
const pkg = path.join(__dirname, 'fixtures', 'basic', 'package.json')
t.plan(1)
try {
fs.unlinkSync(output)
} catch (e) {}
spawn(wpack, [
input,
output,
'--module-bind', 'js=' + path.resolve(__dirname)
], {
stdio: ['pipe', 'pipe', 2]
}).once('exit', function () {
const result = fs.readFileSync(output, { encoding: 'utf8' })
fs.unlinkSync(output)
vm.runInNewContext(result, {
console: {
log: function (src) {
const expected = fs.readFileSync(pkg, { encoding: 'utf8' })
t.equal(src, expected, 'processed brfs from package.json')
}
}
})
})
})
test('relative transforms', function (t) {
const wpack = which.sync('webpack', { cwd: __dirname })
const input = path.join(__dirname, 'fixtures', 'relative', 'index.js')
const output = path.join(__dirname, 'fixtures', 'relative', 'bundle.js')
t.plan(2)
try {
fs.unlinkSync(output)
} catch (e) {}
spawn(wpack, [
input,
output,
'--module-bind', 'js=' + path.resolve(__dirname)
], {
stdio: ['pipe', 'pipe', 2]
}).once('exit', function (code) {
t.doesNotThrow(function () {
fs.statSync(output)
}, 'bundle.js was created')
fs.unlinkSync(output)
t.ok(!code, 'exit code was 0')
})
})
test('error handling', function (t) {
const wpack = which.sync('webpack', { cwd: __dirname })
const input = path.join(__dirname, 'fixtures', 'errors', 'index.js')
const output = path.join(__dirname, 'fixtures', 'errors', 'bundle.js')
t.plan(1)
spawn(wpack, [
input,
output,
'--module-bind', 'js=' + path.resolve(__dirname)
], {
stdio: ['pipe', 'pipe', 2]
}).once('exit', function (code) {
try {
fs.unlinkSync(output)
} catch (e) {}
t.equal(code, 2, 'exit code was 2')
})
})
test('glsl-transform', function (t) {
const wpack = which.sync('webpack', { cwd: __dirname })
const output = path.join(__dirname, 'fixtures', 'glsl', 'bundle.js')
const config = path.join(__dirname, 'fixtures', 'glsl', 'webpack.config.js')
const fixture = path.join(__dirname, 'fixtures', 'glsl', 'output.txt')
t.plan(1)
try {
fs.unlinkSync(output)
} catch (e) {}
spawn(wpack, [
'--module-bind', 'js=' + path.resolve(__dirname),
'--config',
config
], {
cwd: path.join(__dirname, 'fixtures', 'glsl'),
stdio: ['pipe', 'pipe', 2]
}).once('exit', function () {
const result = fs.readFileSync(output, { encoding: 'utf8' })
fs.unlinkSync(output)
vm.runInNewContext(result, {
console: {
log: function (shader) {
const expected = fs.readFileSync(fixture, { encoding: 'utf8' })
t.equal(shader + '\n', expected, 'processed brfs from package.json')
}
}
})
})
})