Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80538 views
1
var parser = require('../');
2
var test = require('tap').test;
3
var fs = require('fs');
4
var path = require('path');
5
var xtend = require('xtend');
6
7
var files = {
8
abc: path.join(__dirname, '/expose/lib/abc.js'),
9
xyz: path.join(__dirname, '/expose/lib/xyz.js'),
10
foo: path.join(__dirname, '/expose/foo.js'),
11
bar: path.join(__dirname, '/expose/bar.js'),
12
main: path.join(__dirname, '/expose/main.js')
13
};
14
15
var sources = Object.keys(files).reduce(function (acc, file) {
16
acc[file] = fs.readFileSync(files[file], 'utf8');
17
return acc;
18
}, {});
19
20
var cache = {};
21
cache[files.abc] = {
22
source: sources.abc,
23
deps: {}
24
};
25
cache[files.xyz] = {
26
source: sources.xyz,
27
deps: {'../foo': files.foo}
28
};
29
cache[files.foo] = {
30
source: sources.foo,
31
deps: {'./lib/abc': files.abc}
32
};
33
cache[files.bar] = {
34
source: sources.bar,
35
deps: {xyz: files.xyz}
36
};
37
cache[files.main] = {
38
source: sources.main,
39
deps: {
40
abc: files.abc,
41
xyz: files.xyz,
42
'./bar': files.bar
43
}
44
};
45
46
test('preserves expose and entry with partial cache', function(t) {
47
t.plan(1);
48
49
var partialCache = xtend(cache);
50
delete partialCache[files.bar];
51
52
var p = parser({ cache: partialCache });
53
p.write({ id: 'abc', file: files.abc, expose: 'abc' });
54
p.write({ id: 'xyz', file: files.xyz, expose: 'xyz' });
55
p.end({ id: 'main', file: files.main, entry: true });
56
57
var rows = [];
58
p.on('data', function (row) { rows.push(row); });
59
p.on('end', function () {
60
t.same(rows.sort(cmp), [
61
{
62
id: files.bar,
63
file: files.bar,
64
source: sources.bar,
65
deps: {xyz: files.xyz}
66
},
67
{
68
file: files.foo,
69
id: files.foo,
70
source: sources.foo,
71
deps: {'./lib/abc': files.abc}
72
},
73
{
74
id: 'abc',
75
file: files.abc,
76
source: sources.abc,
77
deps: {},
78
entry: true,
79
expose: 'abc'
80
},
81
{
82
id: 'main',
83
file: files.main,
84
source: sources.main,
85
deps: {
86
'./bar': files.bar,
87
abc: files.abc,
88
xyz: files.xyz
89
},
90
entry: true
91
},
92
{
93
id: 'xyz',
94
file: files.xyz,
95
source: sources.xyz,
96
deps: {'../foo': files.foo},
97
entry: true,
98
expose: 'xyz'
99
}
100
].sort(cmp));
101
});
102
});
103
104
function cmp (a, b) { return a.id < b.id ? -1 : 1 }
105
106