cache_expose.js
1.29 KB
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
var parser = require('../');
var test = require('tap').test;
var path = require('path');
var files = {
foo: path.join(__dirname, '/files/foo.js'),
bar: path.join(__dirname, '/files/bar.js')
};
var sources = {
foo: 'notreal foo',
bar: 'notreal bar'
};
var cache = {};
cache[files.foo] = {
source: sources.foo,
deps: { './bar': files.bar }
};
cache[files.bar] = {
source: sources.bar,
deps: {}
};
test('cache preserves expose and entry', function (t) {
t.plan(1);
var p = parser({ cache: cache });
p.write({ id: files.bar, expose: 'bar2', entry: false });
p.end({ id: 'foo', file: files.foo, entry: true, expose: 'foo2' });
var rows = [];
p.on('data', function (row) { rows.push(row) });
p.on('end', function () {
t.same(rows.sort(cmp), [
{
id: 'foo',
expose: 'foo2',
entry: true,
file: files.foo,
source: sources.foo,
deps: { './bar': files.bar }
},
{
id: files.bar,
expose: 'bar2',
file: files.bar,
source: sources.bar,
deps: {}
}
].sort(cmp));
});
});
function cmp (a, b) { return a.id < b.id ? -1 : 1 }