cache_partial_expose.js
2.66 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
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
var parser = require('../');
var test = require('tap').test;
var fs = require('fs');
var path = require('path');
var xtend = require('xtend');
var files = {
abc: path.join(__dirname, '/expose/lib/abc.js'),
xyz: path.join(__dirname, '/expose/lib/xyz.js'),
foo: path.join(__dirname, '/expose/foo.js'),
bar: path.join(__dirname, '/expose/bar.js'),
main: path.join(__dirname, '/expose/main.js')
};
var sources = Object.keys(files).reduce(function (acc, file) {
acc[file] = fs.readFileSync(files[file], 'utf8');
return acc;
}, {});
var cache = {};
cache[files.abc] = {
source: sources.abc,
deps: {}
};
cache[files.xyz] = {
source: sources.xyz,
deps: {'../foo': files.foo}
};
cache[files.foo] = {
source: sources.foo,
deps: {'./lib/abc': files.abc}
};
cache[files.bar] = {
source: sources.bar,
deps: {xyz: files.xyz}
};
cache[files.main] = {
source: sources.main,
deps: {
abc: files.abc,
xyz: files.xyz,
'./bar': files.bar
}
};
test('preserves expose and entry with partial cache', function(t) {
t.plan(1);
var partialCache = xtend(cache);
delete partialCache[files.bar];
var p = parser({ cache: partialCache });
p.write({ id: 'abc', file: files.abc, expose: 'abc' });
p.write({ id: 'xyz', file: files.xyz, expose: 'xyz' });
p.end({ id: 'main', file: files.main, entry: true });
var rows = [];
p.on('data', function (row) { rows.push(row); });
p.on('end', function () {
t.same(rows.sort(cmp), [
{
id: files.bar,
file: files.bar,
source: sources.bar,
deps: {xyz: files.xyz}
},
{
file: files.foo,
id: files.foo,
source: sources.foo,
deps: {'./lib/abc': files.abc}
},
{
id: 'abc',
file: files.abc,
source: sources.abc,
deps: {},
entry: true,
expose: 'abc'
},
{
id: 'main',
file: files.main,
source: sources.main,
deps: {
'./bar': files.bar,
abc: files.abc,
xyz: files.xyz
},
entry: true
},
{
id: 'xyz',
file: files.xyz,
source: sources.xyz,
deps: {'../foo': files.foo},
entry: true,
expose: 'xyz'
}
].sort(cmp));
});
});
function cmp (a, b) { return a.id < b.id ? -1 : 1 }