-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
142 lines (112 loc) · 4.07 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'use strict';
var calculateCacheKeyForTree = require('./index');
var cacheKeyForStableTree = calculateCacheKeyForTree.cacheKeyForStableTree;
var chai = require('chai');
var expect = chai.expect;
describe('calculateCacheKeyForTree', function() {
it('should return same value for same input', function() {
var addon = {
root: 'hoy',
pkg: { name: 'foo', dependencies: { bar: '1.2.3' } }
};
var first = calculateCacheKeyForTree('app', addon);
var second = calculateCacheKeyForTree('app', addon);
expect(first).to.equal(second);
});
it('should return same value for different instances but same package.json content', function() {
var firstAddon = {
name: 'derp',
root: 'hoy',
pkg: { name: 'foo', dependencies: { bar: '2.0.1' } }
};
var secondAddon = {
name: 'derp',
root: 'hoy',
pkg: { name: 'foo', dependencies: { bar: '2.0.1' } }
};
var first = calculateCacheKeyForTree('app', firstAddon);
var second = calculateCacheKeyForTree('app', secondAddon);
expect(first).to.equal(second);
});
it('should return different value for addons with custom non-underscored keys in package.json', function() {
var firstAddon = {
name: 'huzzah',
root: 'hoy',
pkg: { name: 'foo', specialThing: 'quux', dependencies: { bar: '2.0.1' } }
};
var secondAddon = {
name: 'huzzah',
root: 'hoy',
pkg: { name: 'foo', specialThing: 'qux', dependencies: { bar: '2.0.1' } }
};
var first = calculateCacheKeyForTree('app', firstAddon);
var second = calculateCacheKeyForTree('app', secondAddon);
expect(first).to.not.equal(second);
});
it('should return different value for different addons', function() {
var firstAddon = {
name: 'derp',
root: 'hoy',
pkg: { name: 'baz', dependencies: { bar: '2.0.1' } }
};
var secondAddon = {
name: 'huzzah',
root: 'hoy',
pkg: { name: 'foo', dependencies: { bar: '1.2.3' } }
};
var first = calculateCacheKeyForTree('app', firstAddon);
var second = calculateCacheKeyForTree('app', secondAddon);
expect(first).to.not.equal(second);
});
it('should not return same value for same addon with different tree type', function() {
var addon = {
root: 'hoy',
pkg: { name: 'foo', dependencies: { bar: '1.2.3' } }
};
var first = calculateCacheKeyForTree('addon', addon);
var second = calculateCacheKeyForTree('app', addon);
expect(first).not.to.equal(second);
});
it('should allow additional custom values to be passed', function() {
var addon = {
root: 'hoy',
pkg: { name: 'foo', dependencies: { bar: '1.2.3' } }
};
var first = calculateCacheKeyForTree('addon', addon);
var second = calculateCacheKeyForTree('addon', addon, ['foo']);
expect(first).not.to.equal(second);
});
it('cache key parts are stable sorted', function() {
var addon = {
root: 'hoy',
pkg: { name: 'foo', dependencies: { bar: '1.2.3' } }
};
var first = calculateCacheKeyForTree('addon', addon, [ { foo: 'bar', baz: 'derp' }]);
var second = calculateCacheKeyForTree('addon', addon, [ { baz: 'derp', foo: 'bar' }]);
expect(first).to.equal(second);
});
});
describe('cacheKeyForStableTree', function() {
it('should pass the tree type to calculateCacheKeyForTree', function() {
let addon = {
cacheKeyForTree: cacheKeyForStableTree
};
let firstKey = addon.cacheKeyForTree('foo');
let secondKey = addon.cacheKeyForTree('bar');
let thirdKey = addon.cacheKeyForTree('foo');
expect(firstKey).not.to.equal(secondKey);
expect(firstKey).to.equal(thirdKey);
});
it('should use the context as the addon argument to calculateCacheKeyForTree', function() {
let addon = {
name: 'derp',
root: 'hoy',
pkg: { name: 'baz', dependencies: { bar: '2.0.1' } },
cacheKeyForTree: cacheKeyForStableTree
};
let firstKey = addon.cacheKeyForTree('foo');
addon.name = 'herp';
let secondKey = addon.cacheKeyForTree('foo');
expect(firstKey).not.to.equal(secondKey);
});
});