-
Notifications
You must be signed in to change notification settings - Fork 23
/
bundle_test.js
169 lines (148 loc) · 4.21 KB
/
bundle_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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
var assert = require("assert"),
path = require("path"),
bundle = require("../lib/graph/make_graph_with_bundles"),
findbundle = require("../lib/loader/find_bundle"),
logging = require("../lib/logger"),
comparify = require("comparify");
describe("find bundle", function () {
var fakeLoader = {
baseURL: path.join(__dirname, "bundle")
};
it("with given names", function () {
fakeLoader["bundle"] = ["app_a", "app_b"];
var bundles = findbundle(fakeLoader);
assert.deepEqual(["app_a", "app_b"], bundles);
});
it("with a glob string", function () {
fakeLoader["bundle"] = "app_*";
var bundles = findbundle(fakeLoader);
assert.deepEqual([
'app_a',
'app_b',
'app_c',
'app_d'
], bundles);
});
it("wildcard with extension", function() {
fakeLoader["bundle"] = ["pages/*.component"];
var bundles = findbundle(fakeLoader);
assert.deepEqual([
'pages/cart.component',
], bundles);
});
it("the steal convention trailing slash", function() {
fakeLoader["bundle"] = ["pages/**/"];
var bundles = findbundle(fakeLoader);
assert.deepEqual([
'pages/home/home',
'pages/restaurant/list/list'
], bundles);
});
it("trailing slash and wildcard extension", function() {
fakeLoader["bundle"] = ["pages/**/", "pages/**/*.component"];
var bundles = findbundle(fakeLoader);
assert.deepEqual([
'pages/home/home',
'pages/restaurant/list/list',
'pages/cart.component',
'pages/order/history.component'
], bundles);
});
});
describe("bundle", function () {
beforeEach(function () {
logging.setup({quiet: true});
});
it("should work", function (done) {
bundle({
config: __dirname + "/bundle/stealconfig.js",
main: "bundle",
logLevel: 3
}).then(function (data) {
var graphCompare = require('./bundle/bundle_graph');
comparify(data.graph, graphCompare, true);
done();
}).catch(function (e) {
done(e)
});
});
it("works with globs", function (done) {
bundle({
config: __dirname + "/bundle/stealconfig.js",
main: "bundle",
logLevel: 3,
bundle: "app_*"
}).then(function (data) {
var graphCompare = require('./bundle/bundle_graph');
comparify(data.graph, graphCompare, true);
done();
}).catch(function (e) {
done(e)
});
});
it("localSteal run in 'build' platform", function (done) {
var system = {
config: __dirname + "/live_reload/package.json!npm"
};
var options = {
quiet: true
};
bundle(system, options).then(function (data) {
assert.equal('build', data.loader.getPlatform());
done();
}).catch(function (e) {
done(e)
});
});
describe("npm", function () {
it("with bundle array", function (done) {
bundle({
config: __dirname + "/npm-bundle/package.json!npm",
bundle: [
"npm-bundle/components/component-1/",
"npm-bundle/components/component-2/"
]
}).then(function (data) {
var modules = Object.keys(data.graph);
assert.ok(~modules.indexOf("npm-bundle@0.0.1#components/component-1/component-1"));
assert.ok(~modules.indexOf("npm-bundle@0.0.1#components/component-2/component-2"));
done();
}).catch(function (e) {
done(e)
});
});
it("with globs in bundle array", function (done) {
bundle({
config: __dirname + "/npm-bundle/package.json!npm",
bundle: [
"npm-bundle/sites/**/*"
]
}).then(function (data) {
var modules = Object.keys(data.graph);
assert.ok(~modules.indexOf("npm-bundle@0.0.1#sites/site-1"));
assert.ok(~modules.indexOf("npm-bundle@0.0.1#sites/site-2"));
done();
}).catch(function (e) {
done(e)
});
});
it("with negative glob patterns", function (done) {
bundle({
config: __dirname + "/npm-bundle/package.json!npm",
bundle: [
"npm-bundle/components/**/*",
"!npm-bundle/components/**/*-test.js"
]
}).then(function (data) {
var modules = Object.keys(data.graph);
assert.ok(~modules.indexOf("npm-bundle@0.0.1#components/component-1/component-1"));
assert.ok(~modules.indexOf("npm-bundle@0.0.1#components/component-2/component-2"));
assert.ok(~modules.indexOf("npm-bundle@0.0.1#components/component-3/component-3"));
assert.ok(!~modules.indexOf("npm-bundle@0.0.1#components/component-3/component-3-test"));
done();
}).catch(function (e) {
done(e)
});
})
});
});