-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
72 lines (62 loc) · 1.72 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
const assert = require('assert');
const loader = require('./index.js');
const sample1 = `import { stuff } from 'module';
stuff();`;
loader.call({
async() {
return (err, newSource) => {
assert.equal(err, null);
assert(newSource.indexOf('[\'module\']') !== -1, 'could not find \'module\'');
}
},
cacheable: console.log.bind(console),
hot: true,
}, sample1);
const sample2 = `import { stuff } from '../relative/module';
stuff();`;
loader.call({
async() {
return (err, newSource) => {
assert.equal(err, null);
assert(newSource.indexOf('[\'../relative/module\']') !== -1, 'could not find \'../relative/module\'');
}
},
cacheable: console.log.bind(console),
hot: true,
}, sample2);
const sample3 = `noImports();`;
loader.call({
async() {
return (err, newSource) => {
assert.equal(err, null);
assert(newSource.indexOf('[]') !== -1);
}
},
cacheable: console.log.bind(console),
hot: true,
}, sample3);
const sample4 = `import { one, two, three } from 'first-module';
import { four, five, six } from 'second-module';`;
loader.call({
async() {
return (err, newSource) => {
assert.equal(err, null);
assert(newSource.indexOf('[\'first-module\', \'second-module\']') !== -1, 'could not find \'first-module\', \'second-module\'');
}
},
cacheable: console.log.bind(console),
hot: true,
}, sample4);
// TODO: handle require imports
const sample5 = `const { join } = require('path');
join(__dirname, '/thing');`;
loader.call({
async() {
return (err, newSource) => {
assert.equal(err, null);
assert(newSource.indexOf('[\'path\']') !== -1, 'could not find \'path\'');
}
},
cacheable: console.log.bind(console),
hot: true,
}, sample5);