UNPKG

9.79 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 'os/mit/td/ape-applet-0.0.61+af-applet-editview;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 '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 // All together now:
55 'core+3.12.0+yui,widget-base;gallery+2013.09.04-21-56+pathogen-encoder,bitly;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 // lang
65 'core+3.12.0+lang/autocomplete-list_en': [
66 'http://yui.yahooapis.com/3.12.0/autocomplete-list/lang/autocomplete-list_en.js'
67 ],
68 // lang bundle bug where a language tag was required
69 'core+3.12.0+lang/autocomplete-list': [
70 'http://yui.yahooapis.com/3.12.0/autocomplete-list/lang/autocomplete-list.js'
71 ]
72 },
73 css: {
74 // Core css:
75 'core+3.12.0+cssreset': [
76 'http://yui.yahooapis.com/3.12.0/build/cssreset/cssreset-min'
77 ],
78
79 // Skin css:
80 'core+3.12.0+skin-sam-datatable-base': [
81 'http://yui.yahooapis.com/3.12.0/build/datatable-base/assets/skins/sam/datatable-base.css'
82 ],
83 'core+3.12.0+skin-night-datatable-base': [
84 'http://yui.yahooapis.com/3.12.0/build/datatable-base/assets/skins/night/datatable-base.css'
85 ],
86
87 // App css:
88 'os/mit/td/stencil-0.1.111+stencil-theme-001': [
89 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-theme-001/stencil-theme-001'
90 ],
91 'os/mit/td/stencil-0.1.111+stencil-css': [
92 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-css/stencil-css'
93 ],
94
95 // Path css
96 'os/mit/td/stencil-0.1.111/stencil-css/stencil-css': [
97 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-css/stencil-css'
98 ],
99
100 // Multiple versions of the same group type:
101 'core+3.12.0+cssreset;core+3.12.0-beta-1+cssgrids': [
102 'http://yui.yahooapis.com/3.12.0/build/cssreset/cssreset',
103 'http://yui.yahooapis.com/3.12.0-beta-1/build/cssgrids/cssgrids'
104 ],
105 'core+3.12.0+skin-sam-datatable-base;core+3.12.0-beta-1+skin-night-datatable-base': [
106 'http://yui.yahooapis.com/3.12.0/build/datatable-base/assets/skins/sam/datatable-base.css',
107 'http://yui.yahooapis.com/3.12.0-beta-1/build/datatable-base/assets/skins/night/datatable-base.css'
108 ],
109 'os/mit/td/stencil-0.1.111+stencil-theme-001;os/mit/td/stencil-0.1.112+stencil-css': [
110 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-theme-001/stencil-theme-001',
111 'http://l.yimg.com/os/mit/td/stencil-0.1.112/stencil-css/stencil-css'
112 ],
113
114 // More than one module in each group:
115 'core+3.12.0+cssreset,cssgrids': [
116 'http://yui.yahooapis.com/3.12.0/build/cssreset/cssreset',
117 'http://yui.yahooapis.com/3.12.0/build/cssgrids/cssgrids'
118 ],
119 'core+3.12.0+skin-sam-datatable-base,skin-night-datatable-base': [
120 'http://yui.yahooapis.com/3.12.0/build/datatable-base/assets/skins/sam/datatable-base.css',
121 'http://yui.yahooapis.com/3.12.0/build/datatable-base/assets/skins/night/datatable-base.css'
122 ],
123 'os/mit/td/stencil-0.1.111+stencil-theme-001,stencil-css': [
124 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-theme-001/stencil-theme-001',
125 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-css/stencil-css'
126 ],
127 'os/mit/td/stencil-0.1.111/stencil-theme-001/stencil-theme-001;os/mit/td/stencil-0.1.111/stencil-css/stencil-css': [
128 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-theme-001/stencil-theme-001',
129 'http://l.yimg.com/os/mit/td/stencil-0.1.111/stencil-css/stencil-css'
130 ],
131
132 // All together now:
133 'core+3.12.0+cssreset,skin-sam-console,cssgrids;os/mit/td/stencil-0.1.111+stencil-theme-001;os/mit/td/stencil-0.1.111/stencil-css/stencil-css': [
134 'http://yui.yahooapis.com/3.12.0/build/cssreset/cssreset',
135 'http://yui.yahooapis.com/3.12.0/build/console/assets/skins/sam/console.css',
136 'http://yui.yahooapis.com/3.12.0/build/cssgrids/cssgrids',
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 },
142
143 jobs = [],
144
145 successes = [],
146 failures = [];
147
148
149['js', 'css'].forEach(function (type) {
150 var fragments = FRAGMENTS[type],
151 filters = FILTER[type];
152
153 filters.forEach(function (f) {
154 // `filter` will be an empty string when we want to test the case
155 // where it defaults to 'min'; otherwise, it will be '.raw',
156 // '.debug', or '.min'.
157 var filter = f ? '.' + f : '',
158 fragment;
159
160 for (fragment in fragments) {
161 if (fragments.hasOwnProperty(fragment)) {
162 jobs.push((function (fragment, filter) {
163 return function (callback) {
164 var base = comboBase + '/combo/cc/p',
165 combo = base + '/' + fragment + filter + '.' + type,
166 options = lib.url.parse(combo);
167
168 options.agent = false;
169
170 lib.http.get(options, function (res) {
171 if (res.statusCode === 200 && res.headers['cache-control']) {
172 console.log('✔', combo);
173 successes.push(combo);
174 return callback();
175 } else {
176 console.log('✘', combo);
177 failures.push(combo);
178 return callback('Invalid status code or incorrectly set headers');
179 }
180 }).on('error', function (err) {
181 console.log('✘', combo);
182 failures.push(combo);
183 return callback(err);
184 });
185 };
186 }(fragment, filter)));
187 }
188 }
189 });
190});
191
192lib.async.series(jobs, function () {
193 console.log('Done testing with ' + successes.length + ' successes and ' + failures.length + ' failures');
194 if (failures.length) {
195 console.log(JSON.stringify(failures, null, 4));
196 }
197});