1 : /*
2 : Copyright (c) 2011, Yahoo! Inc.
3 : All rights reserved.
4 :
5 : Redistribution and use of this software in source and binary forms,
6 : with or without modification, are permitted provided that the following
7 : conditions are met:
8 :
9 : * Redistributions of source code must retain the above
10 : copyright notice, this list of conditions and the
11 : following disclaimer.
12 :
13 : * Redistributions in binary form must reproduce the above
14 : copyright notice, this list of conditions and the
15 : following disclaimer in the documentation and/or other
16 : materials provided with the distribution.
17 :
18 : * Neither the name of Yahoo! Inc. nor the names of its
19 : contributors may be used to endorse or promote products
20 : derived from this software without specific prior
21 : written permission of Yahoo! Inc.
22 :
23 : THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24 : IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 : TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26 : PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 : OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 : SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 : LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 : DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 : THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 : (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 : OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 : */
35 :
36 :
37 1 : module.exports = {
38 : Create: function(hub) {
39 1 : return {
40 : browserName: function(req) {
41 2 : return [req.headers['user-agent'], req.connection.remoteAddress].join('---');
42 : },
43 :
44 : makeSaneNames: function(browser) {
45 2 : var names = browser.split('---'),
46 : filename = names[0],
47 : ip = names[1],
48 : pkgname
49 : ;
50 :
51 : // Get rid of funny chars
52 2 : filename = filename.replace(/[\/;]/g, '');
53 2 : filename = filename.replace(/[^A-Za-z0-9-]/g, '_');
54 :
55 : // Make a Hudson happy package name
56 2 : pkgname = filename.replace(/\./g, '');
57 2 : pkgname = pkgname.replace(/_+/g, '.');
58 :
59 2 : return [ filename, pkgname ];
60 : },
61 :
62 : dumpFile: function(vars, dataKey, filename, component) {
63 1 : var baseOutputDir = hub.config.outputDir,
64 : path = require('path'),
65 : dir = path.join(baseOutputDir, (this.makeSaneNames(component))[0]);
66 1 : data = vars[dataKey],
67 : fullFile = path.join(dir, filename),
68 : fs = require('fs')
69 : ;
70 :
71 1 : hub.emit(hub.LOG, hub.INFO, "Dumping " + fullFile);
72 :
73 : // Any one of these can toss cookies!!!
74 1 : try {
75 : // This will complain if dir already exists
76 : // And we KNOW we can already make dirs here
77 1 : fs.mkdirSync(dir, 0777);
78 : } catch(e) {}
79 :
80 1 : try {
81 1 : var fd = fs.openSync(fullFile, 'w')
82 1 : fs.writeSync(fd, data, 0, 'utf8');
83 1 : fs.closeSync(fd)
84 1 : return [ fullFile, dir ];
85 : } catch(e) {
86 0 : hub.emit(hub.LOG, hub.ERROR, "Error dumping file: " + e);
87 : }
88 : },
89 : failedTests: function(filename) {
90 3 : var fs = require('fs'),
91 : file = fs.readFileSync(filename, 'utf8');
92 :
93 3 : return file.match(/failures="[1-9]/);
94 : }
95 : };
96 : }
97 : };
98 :
|