UNPKG

11.8 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3// Sanity checks for pathogen-encoded combo urls!
4
5var args = process.argv.slice(2),
6
7 comboBase = args[0],
8
9 lib = {
10 http: require('http'),
11 url: require('url'),
12 async: require('async')
13 },
14
15 FILTER = {
16 js: ['', 'raw', 'min', 'debug'],
17 css: ['', 'raw', 'min']
18 },
19
20 FRAGMENTS = {
21 js: {
22 // Multiple versions of the same group type:
23 'core+3.12.0-beta-1+yui;core+3.12.0+yui': [
24 'http://yui.yahooapis.com/3.12.0-beta-1/build/yui/yui',
25 'http://yui.yahooapis.com/3.12.0/build/yui/yui'
26 ],
27 'gallery+2013.09.04-21-56+pathogen-encoder;gallery+2013.08.07-20-34+bitly': [
28 'http://yui.yahooapis.com/gallery-2013.09.04-21-56/build/gallery-pathogen-encoder/gallery-pathogen-encoder',
29 'http://yui.yahooapis.com/gallery-2013.08.07-20-34/build/gallery-bitly/gallery-bitly'
30 ],
31 's+os/mit/td/ape-applet-0.0.61+af-applet-editview;s+os/mit/td/td-applet-weather-0.0.95+td-applet-weather-appletmodel': [
32 'http://l.yimg.com/os/mit/td/ape-applet-0.0.61/af-applet-editview/af-applet-editview',
33 'http://l.yimg.com/os/mit/td/td-applet-weather-0.0.95/td-applet-weather-appletmodel/td-applet-weather-appletmodel'
34 ],
35
36 // More than one module in each group:
37 'core+3.12.0+yui,widget-base': [
38 'http://yui.yahooapis.com/3.12.0/build/yui/yui',
39 'http://yui.yahooapis.com/3.12.0/build/widget-base/widget-base'
40 ],
41 'gallery+2013.09.04-21-56+pathogen-encoder,bitly': [
42 'http://yui.yahooapis.com/gallery-2013.09.04-21-56/build/gallery-pathogen-encoder/gallery-pathogen-encoder',
43 'http://yui.yahooapis.com/gallery-2013.09.04-21-56/build/gallery-bitly/gallery-bitly'
44 ],
45 's+os/mit/td/ape-applet-0.0.61+af-applet-headerview,af-applet-editview': [
46 'http://l.yimg.com/os/mit/td/ape-applet-0.0.61/af-applet-headerview/af-applet-headerview',
47 'http://l.yimg.com/os/mit/td/ape-applet-0.0.61/af-applet-editview/af-applet-editview'
48 ],
49 'os/mit/td/ape-applet-0.0.61/af-applet-headerview/af-applet-headerview;os/mit/td/ape-applet-0.0.61/af-applet-editview/af-applet-editview': [
50 'http://l.yimg.com/os/mit/td/ape-applet-0.0.61/af-applet-headerview',
51 'http://l.yimg.com/os/mit/td/ape-applet-0.0.61/af-applet-editview'
52 ],
53
54 // Short groups
55 'c+3.12.0+yui,widget-base;g+2013.09.04-21-56+pathogen-encoder,bitly;s+os/mit/td/ape-applet-0.0.61+af-applet-headerview,af-applet-editview;os/mit/td/ape-applet-0.0.61+af-applet-editview/af-applet-editview': [
56 'http://yui.yahooapis.com/3.12.0/build/yui/yui',
57 'http://yui.yahooapis.com/3.12.0/build/widget-base/widget-base',
58 'http://yui.yahooapis.com/gallery-2013.09.04-21-56/build/gallery-pathogen-encoder/gallery-pathogen-encoder',
59 'http://yui.yahooapis.com/gallery-2013.09.04-21-56/build/gallery-bitly/gallery-bitly',
60 'http://l.yimg.com/os/mit/td/ape-applet-0.0.61/af-applet-headerview/af-applet-headerview',
61 'http://l.yimg.com/os/mit/td/ape-applet-0.0.61/af-applet-editview/af-applet-editview'
62 ],
63
64 // All together now:
65 'core+3.12.0+yui,widget-base;gallery+2013.09.04-21-56+pathogen-encoder,bitly;s+os/mit/td/ape-applet-0.0.61+af-applet-headerview,af-applet-editview;os/mit/td/ape-applet-0.0.61/af-applet-editview/af-applet-editview': [
66 'http://yui.yahooapis.com/3.12.0/build/yui/yui',
67 'http://yui.yahooapis.com/3.12.0/build/widget-base/widget-base',
68 'http://yui.yahooapis.com/gallery-2013.09.04-21-56/build/gallery-pathogen-encoder/gallery-pathogen-encoder',
69 'http://yui.yahooapis.com/gallery-2013.09.04-21-56/build/gallery-bitly/gallery-bitly',
70 'http://l.yimg.com/os/mit/td/ape-applet-0.0.61/af-applet-headerview/af-applet-headerview',
71 'http://l.yimg.com/os/mit/td/ape-applet-0.0.61/af-applet-editview/af-applet-editview'
72 ],
73 // lang
74 'core+3.12.0+lang/autocomplete-list_en': [
75 'http://yui.yahooapis.com/3.12.0/autocomplete-list/lang/autocomplete-list_en.js'
76 ],
77 // lang bundle bug where a language tag was required
78 'core+3.12.0+lang/autocomplete-list': [
79 'http://yui.yahooapis.com/3.12.0/autocomplete-list/lang/autocomplete-list.js'
80 ]
81 },
82 css: {
83 // Core css:
84 'core+3.12.0+cssreset': [
85 'http://yui.yahooapis.com/3.12.0/build/cssreset/cssreset-min'
86 ],
87
88 // Skin css:
89 'core+3.12.0+skin-sam-datatable-base': [
90 'http://yui.yahooapis.com/3.12.0/build/datatable-base/assets/skins/sam/datatable-base.css'
91 ],
92 'core+3.12.0+skin-night-datatable-base': [
93 'http://yui.yahooapis.com/3.12.0/build/datatable-base/assets/skins/night/datatable-base.css'
94 ],
95
96 // App css:
97 's+os/mit/td/stencil-0.1.111+stencil-theme-001': [
98 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-theme-001/stencil-theme-001'
99 ],
100 's+os/mit/td/stencil-0.1.111+stencil-css': [
101 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-css/stencil-css'
102 ],
103
104 // Path css
105 'os/mit/td/stencil-0.1.111/stencil-css/stencil-css': [
106 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-css/stencil-css'
107 ],
108
109 // Multiple versions of the same group type:
110 'core+3.12.0+cssreset;core+3.12.0-beta-1+cssgrids': [
111 'http://yui.yahooapis.com/3.12.0/build/cssreset/cssreset',
112 'http://yui.yahooapis.com/3.12.0-beta-1/build/cssgrids/cssgrids'
113 ],
114 'core+3.12.0+skin-sam-datatable-base;core+3.12.0-beta-1+skin-night-datatable-base': [
115 'http://yui.yahooapis.com/3.12.0/build/datatable-base/assets/skins/sam/datatable-base.css',
116 'http://yui.yahooapis.com/3.12.0-beta-1/build/datatable-base/assets/skins/night/datatable-base.css'
117 ],
118 's+os/mit/td/stencil-0.1.111+stencil-theme-001;s+os/mit/td/stencil-0.1.112+stencil-css': [
119 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-theme-001/stencil-theme-001',
120 'http://l.yimg.com/os/mit/td/stencil-0.1.112/stencil-css/stencil-css'
121 ],
122
123 // More than one module in each group:
124 'core+3.12.0+cssreset,cssgrids': [
125 'http://yui.yahooapis.com/3.12.0/build/cssreset/cssreset',
126 'http://yui.yahooapis.com/3.12.0/build/cssgrids/cssgrids'
127 ],
128 'core+3.12.0+skin-sam-datatable-base,skin-night-datatable-base': [
129 'http://yui.yahooapis.com/3.12.0/build/datatable-base/assets/skins/sam/datatable-base.css',
130 'http://yui.yahooapis.com/3.12.0/build/datatable-base/assets/skins/night/datatable-base.css'
131 ],
132 's+os/mit/td/stencil-0.1.111+stencil-theme-001,stencil-css': [
133 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-theme-001/stencil-theme-001',
134 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-css/stencil-css'
135 ],
136 'os/mit/td/stencil-0.1.111/stencil-theme-001/stencil-theme-001;os/mit/td/stencil-0.1.111/stencil-css/stencil-css': [
137 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-theme-001/stencil-theme-001',
138 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-css/stencil-css'
139 ],
140
141 // All together now:
142 'core+3.12.0+cssreset,skin-sam-console,cssgrids;s+os/mit/td/stencil-0.1.111+stencil-theme-001;os/mit/td/stencil-0.1.111/stencil-css/stencil-css': [
143 'http://yui.yahooapis.com/3.12.0/build/cssreset/cssreset',
144 'http://yui.yahooapis.com/3.12.0/build/console/assets/skins/sam/console.css',
145 'http://yui.yahooapis.com/3.12.0/build/cssgrids/cssgrids',
146 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-theme-001/stencil-theme-001',
147 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-css/stencil-css'
148 ]
149 }
150 },
151
152 jobs = [],
153
154 successes = [],
155 failures = [];
156
157
158['/cc/p', '/check/cc/p'].forEach(function (path) {
159 ['js', 'css'].forEach(function (type) {
160 var fragments = FRAGMENTS[type],
161 filters = FILTER[type];
162
163 filters.forEach(function (f) {
164 // `filter` will be an empty string when we want to test the case
165 // where it defaults to 'min'; otherwise, it will be '.raw',
166 // '.debug', or '.min'.
167 var filter = f ? '.' + f : '',
168 fragment;
169
170 for (fragment in fragments) {
171 if (fragments.hasOwnProperty(fragment)) {
172 jobs.push((function (path, fragment, filter) {
173 return function (callback) {
174 var base = comboBase + path,
175 combo = base + '/' + fragment + filter + '.' + type,
176 options = lib.url.parse(combo);
177
178 options.agent = false;
179
180 lib.http.get(options, function (res) {
181 if (res.statusCode === 200) {
182 console.log('✔', combo);
183 successes.push(combo);
184 return callback();
185 } else {
186 console.log('✘', combo);
187 failures.push(combo);
188 return callback('statusCode !== 200');
189 }
190 }).on('error', function (err) {
191 console.log('✘', combo);
192 failures.push(combo);
193 return callback(err);
194 });
195 };
196 }(path, fragment, filter)));
197 }
198 }
199 });
200 });
201});
202
203lib.async.series(jobs, function () {
204 console.log('Done testing with ' + successes.length + ' successes and ' + failures.length + ' failures');
205 if (failures.length) {
206 console.log(JSON.stringify(failures, null, 4));
207 }
208});
209
210var secureCombo = comboBase + '/cc/p/core+3.12.0+yui.js?secure=1';
211lib.http.get(secureCombo)
212 .on('response', function (res) {
213 var buffer = [];
214
215 if (!res.headers.expires || !res.headers['cache-control']) {
216 console.log('✘', 'Cache headers are not set correctly');
217 process.exit(1);
218 }
219
220 res.on('data', function (chunk) {
221 buffer.push(chunk);
222 });
223
224 res.on('end', function () {
225 var body = Buffer.concat(buffer).toString('utf8');
226 if (body.indexOf('https://yui-s') === -1) {
227 console.log('✘', 'Failed to include ssl assets');
228 process.exit(1);
229 } else {
230 console.log('✔', 'Successfully included ssl assets');
231 }
232
233 console.log(body);
234 });
235 }).on('error', function (err) {
236 console.log('✘', secureCombo);
237 console.log('There was an error making the request: ' + err.message);
238 process.exit(1);
239 });