remove packages to get npm audit to pass (#11)
* remove packages to get `npm audit` to pass * fix grunt.config.init() call lost in split up * remove integration tests, they don't work and nobody is running them * fix upload_to_s3 task after refactor
This commit is contained in:
@ -1,220 +0,0 @@
|
||||
/**
|
||||
* ESJS reporter for running and collecting mocha test results.
|
||||
*
|
||||
* @param {Runner} runner
|
||||
* @api public
|
||||
*/
|
||||
module.exports = JenkinsReporter;
|
||||
|
||||
var Base = require('mocha/lib/reporters/base');
|
||||
var _ = require('lodash');
|
||||
var chalk = require('chalk');
|
||||
var makeJUnitXml = require('./make_j_unit_xml');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var inspect = require('util').inspect;
|
||||
|
||||
var log = (function() {
|
||||
var locked = _.bind(process.stdout.write, process.stdout);
|
||||
return function(str) {
|
||||
if (typeof str !== 'string') {
|
||||
str = inspect(str);
|
||||
}
|
||||
locked(str);
|
||||
};
|
||||
})();
|
||||
|
||||
var integration = _.find(process.argv, function(arg) {
|
||||
return arg.indexOf('test/integration') > -1;
|
||||
});
|
||||
var unit = _.find(process.argv, function(arg) {
|
||||
return arg.indexOf('test/unit') > -1;
|
||||
});
|
||||
var output;
|
||||
|
||||
if (unit) {
|
||||
output = path.join(__dirname, '../junit-node-unit.xml');
|
||||
} else if (integration) {
|
||||
output = path.join(__dirname, '../junit-node-integration.xml');
|
||||
} else {
|
||||
throw new Error('unable to detect unit or integration tests');
|
||||
}
|
||||
|
||||
function JenkinsReporter(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var stats = this.stats;
|
||||
var rootSuite = {
|
||||
results: [],
|
||||
suites: [],
|
||||
};
|
||||
|
||||
var stack = [rootSuite];
|
||||
|
||||
function indt() {
|
||||
return new Array(stack.length + 1).join(' ');
|
||||
}
|
||||
|
||||
runner.on('suite', function(suite) {
|
||||
if (suite.root) {
|
||||
return;
|
||||
}
|
||||
|
||||
// suite
|
||||
suite = {
|
||||
name: suite.fullTitle(),
|
||||
results: [],
|
||||
start: Date.now(),
|
||||
stdout: '',
|
||||
stderr: '',
|
||||
};
|
||||
|
||||
// append to the previous stack leader
|
||||
if (!stack[0].suites) {
|
||||
stack[0].suites = [];
|
||||
}
|
||||
stack[0].suites.push(suite);
|
||||
|
||||
// push the suite onto the top of the stack
|
||||
stack.unshift(suite);
|
||||
});
|
||||
|
||||
runner.on('suite end', function(suite) {
|
||||
if (suite.root) {
|
||||
return;
|
||||
}
|
||||
stack[0].time = Date.now() - stack[0].start;
|
||||
stack.shift();
|
||||
});
|
||||
|
||||
runner.on('fail', function(test) {
|
||||
if (test.type === 'hook') {
|
||||
runner.emit('test end', test);
|
||||
}
|
||||
});
|
||||
|
||||
runner.on('test end', function(test) {
|
||||
if (test.state === 'passed') {
|
||||
log(chalk.green('.'));
|
||||
} else if (test.pending) {
|
||||
log(chalk.grey('.'));
|
||||
return;
|
||||
} else {
|
||||
log(chalk.red('x'));
|
||||
}
|
||||
|
||||
var errMsg = void 0;
|
||||
|
||||
if (test.err) {
|
||||
errMsg = test.err.stack || test.err.toString();
|
||||
|
||||
// FF / Opera do not add the message
|
||||
if (!~errMsg.indexOf(test.err.message)) {
|
||||
errMsg = test.err.message + '\n' + errMsg;
|
||||
}
|
||||
|
||||
// <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
|
||||
// check for the result of the stringifying.
|
||||
if (errMsg === '[object Error]') {
|
||||
errMsg = test.err.message;
|
||||
}
|
||||
|
||||
// Safari doesn't give you a stack. Let's at least provide a source line.
|
||||
if (
|
||||
!test.err.stack &&
|
||||
test.err.sourceURL &&
|
||||
test.err.line !== undefined
|
||||
) {
|
||||
errMsg += '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
|
||||
}
|
||||
|
||||
console.error(
|
||||
_.map(errMsg.split('\n'), function(line) {
|
||||
return indt() + ' ' + line;
|
||||
}).join('\n')
|
||||
);
|
||||
}
|
||||
|
||||
if (stack[0]) {
|
||||
stack[0].results.push({
|
||||
name: test.title,
|
||||
time: test.duration,
|
||||
pass: test.state === 'passed',
|
||||
test: test,
|
||||
stdout: stack[0].stdout,
|
||||
stderr: stack[0].stderr,
|
||||
});
|
||||
stack[0].stdout = stack[0].stderr = '';
|
||||
}
|
||||
});
|
||||
|
||||
runner.on('hook end', function(hook) {
|
||||
if (
|
||||
hook.title.indexOf('"after each"') > -1 &&
|
||||
stack[0] &&
|
||||
stack[0].results.length
|
||||
) {
|
||||
var result = _.last(stack[0].results);
|
||||
result.stdout += stack[0].stdout;
|
||||
result.stderr += stack[0].stderr;
|
||||
stack[0].stdout = stack[0].stderr = '';
|
||||
}
|
||||
});
|
||||
|
||||
runner.on('end', function() {
|
||||
restoreStdio();
|
||||
var xml = makeJUnitXml('node ' + process.version, {
|
||||
stats: stats,
|
||||
suites: _.map(rootSuite.suites, function removeElements(suite) {
|
||||
var s = {
|
||||
name: suite.name,
|
||||
start: suite.start,
|
||||
time: suite.time || 0,
|
||||
results: suite.results,
|
||||
stdout: suite.stdout,
|
||||
stderr: suite.stderr,
|
||||
};
|
||||
|
||||
if (suite.suites) {
|
||||
s.suites = _.map(suite.suites, removeElements);
|
||||
}
|
||||
return s;
|
||||
}),
|
||||
});
|
||||
|
||||
fs.writeFileSync(output, xml, 'utf8');
|
||||
|
||||
console.log(
|
||||
'\n' +
|
||||
[
|
||||
'tests complete in ' +
|
||||
Math.round(stats.duration / 10) / 100 +
|
||||
' seconds',
|
||||
' fail: ' + chalk.red(stats.failures),
|
||||
' pass: ' + chalk.green(stats.passes),
|
||||
' pending: ' + chalk.grey(stats.pending),
|
||||
].join('\n')
|
||||
);
|
||||
});
|
||||
|
||||
// overload the write methods on stdout and stderr
|
||||
['stdout', 'stderr'].forEach(function(name) {
|
||||
var obj = process[name];
|
||||
var orig = obj.write;
|
||||
obj.write = function(chunk) {
|
||||
if (stack[0]) {
|
||||
stack[0][name] = (stack[0][name] || '') + chunk;
|
||||
}
|
||||
|
||||
// orig.apply(obj, arguments);
|
||||
};
|
||||
obj.__restore = function() {
|
||||
this.write = orig;
|
||||
};
|
||||
});
|
||||
|
||||
function restoreStdio() {
|
||||
process.stdout.__restore();
|
||||
process.stderr.__restore();
|
||||
}
|
||||
}
|
||||
@ -1,110 +0,0 @@
|
||||
/**
|
||||
* The JUnit xml output desired by Jenkins essentially looks like this:
|
||||
*
|
||||
* testsuites:
|
||||
* - testsuite: (name, timestamp, hostname, tests, failures, errors, time)
|
||||
* - testcase: (error or failure, name, classname, time)
|
||||
*
|
||||
* Full XSD avaliable [here](http://windyroad.com.au/dl/Open%20Source/JUnit.xsd)
|
||||
*
|
||||
* from
|
||||
*
|
||||
* {
|
||||
* stats: {
|
||||
*
|
||||
* }
|
||||
* suite: [
|
||||
* {
|
||||
* name:
|
||||
* results: []
|
||||
* suites: [] // optional
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
module.exports = makeJUnitXml;
|
||||
|
||||
var testXml = require('xmlbuilder');
|
||||
var suites = testXml.create('testsuites');
|
||||
var suiteCount = 0;
|
||||
var moment = require('moment');
|
||||
var _ = require('lodash');
|
||||
var chalk = require('chalk');
|
||||
|
||||
function makeJUnitXml(runnerName, testDetails) {
|
||||
_.each(testDetails.suites, function serializeSuite(suiteInfo) {
|
||||
var suite = suites.ele('testsuite', {
|
||||
package: 'elasticsearch-js',
|
||||
id: suiteCount++,
|
||||
name: suiteInfo.name,
|
||||
timestamp: moment(suiteInfo.start).toJSON(),
|
||||
hostname: 'localhost',
|
||||
tests: (suiteInfo.results && suiteInfo.results.length) || 0,
|
||||
failures: _.filter(suiteInfo.results, { pass: false }).length,
|
||||
errors: 0,
|
||||
time: suiteInfo.time / 1000,
|
||||
});
|
||||
|
||||
_.each(suiteInfo.results, function(testInfo) {
|
||||
var section;
|
||||
var integration = false;
|
||||
|
||||
if (suiteInfo.name.match(/\/.*\.yaml$/)) {
|
||||
section = suiteInfo.name
|
||||
.split('/')
|
||||
.slice(0, -1)
|
||||
.join('/')
|
||||
.replace(/\./g, '/');
|
||||
} else {
|
||||
section = suiteInfo.name.replace(/\./g, ',');
|
||||
}
|
||||
|
||||
if (section.indexOf('integration ') === 0) {
|
||||
section = section.replace(/^integration /, '');
|
||||
integration = true;
|
||||
}
|
||||
|
||||
var testcase = suite.ele('testcase', {
|
||||
name: testInfo.name,
|
||||
time: (testInfo.time || 0) / 1000,
|
||||
classname:
|
||||
runnerName + (integration ? ' - integration' : '') + '.' + section,
|
||||
});
|
||||
|
||||
if (testInfo.errMsg) {
|
||||
testcase.ele('failure', {
|
||||
message: testInfo.errMsg,
|
||||
type: 'AssertError',
|
||||
});
|
||||
} else if (!testInfo.pass) {
|
||||
testcase.ele('error', {
|
||||
message: 'Unknown Error',
|
||||
type: 'TestError',
|
||||
});
|
||||
}
|
||||
|
||||
giveOutput(testcase, testInfo);
|
||||
});
|
||||
|
||||
if (suiteInfo.suites) {
|
||||
_.each(suiteInfo.suites, serializeSuite);
|
||||
}
|
||||
|
||||
giveOutput(suite, suiteInfo);
|
||||
});
|
||||
|
||||
return suites.toString({ pretty: true });
|
||||
}
|
||||
|
||||
function giveOutput(el, info) {
|
||||
var out = info.stdout.trim();
|
||||
var err = info.stderr.trim();
|
||||
|
||||
if (out) {
|
||||
el.ele('system-out', {}).cdata(chalk.stripColor(out));
|
||||
}
|
||||
|
||||
if (err) {
|
||||
el.ele('system-err', {}).cdata(chalk.stripColor(err));
|
||||
}
|
||||
}
|
||||
@ -1,137 +0,0 @@
|
||||
/* eslint-disable import/no-unresolved */
|
||||
var express = require('express');
|
||||
var http = require('http');
|
||||
var fs = require('fs');
|
||||
var _ = require('lodash');
|
||||
var async = require('async');
|
||||
var root = require('path').join(__dirname, '../..');
|
||||
var browserify = require('browserify');
|
||||
var pkg = require(root + '/package.json');
|
||||
var unitSpecDir = root + '/test/unit/specs';
|
||||
var browserBuildsDir = root + '/test/unit/browser_builds';
|
||||
|
||||
var testFiles = {};
|
||||
|
||||
testFiles.unit = _(fs.readdirSync(unitSpecDir))
|
||||
.difference([
|
||||
'file_logger.js',
|
||||
'http_connector.js',
|
||||
'stdio_logger.js',
|
||||
'console_logger.js',
|
||||
'stream_logger.js',
|
||||
'tracer_logger.js',
|
||||
'transport_with_server.js',
|
||||
])
|
||||
.map(function(file) {
|
||||
return unitSpecDir + '/' + file;
|
||||
})
|
||||
.value();
|
||||
|
||||
testFiles.build = fs
|
||||
.readdirSync(browserBuildsDir)
|
||||
.map(function(file) {
|
||||
if (file.substr(-3) === '.js') {
|
||||
return browserBuildsDir + '/' + file;
|
||||
}
|
||||
|
||||
return null;
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
// generic aliasify instance
|
||||
var aliasify = require('aliasify').configure({
|
||||
aliases: pkg.browser,
|
||||
excludeExtensions: 'json',
|
||||
// verbose: false,
|
||||
configDir: root,
|
||||
});
|
||||
|
||||
// queue for bundle requests, two at a time
|
||||
var bundleQueue = async.queue(function(task, done) {
|
||||
task(done);
|
||||
}, 2);
|
||||
|
||||
// create a route that bundles a file list, based on the patterns defined in testFiles
|
||||
function bundleTests(name) {
|
||||
return function(req, res, next) {
|
||||
bundleQueue.push(function(_cb) {
|
||||
var done = function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
_cb(err);
|
||||
};
|
||||
|
||||
res.set('Content-Type', 'application/javascript');
|
||||
|
||||
var b = browserify(testFiles[name], {
|
||||
insertGlobals: true,
|
||||
});
|
||||
b.transform(aliasify);
|
||||
var str = b.bundle();
|
||||
|
||||
str.pipe(res);
|
||||
str.once('end', done);
|
||||
str.once('error', done);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// create a route that just rends a specific file (like a symlink or something)
|
||||
function sendFile(file) {
|
||||
return function(req, res) {
|
||||
res.sendfile(file);
|
||||
};
|
||||
}
|
||||
|
||||
var app = express();
|
||||
|
||||
app
|
||||
.use(app.router)
|
||||
// runners
|
||||
.get('/unit.html', sendFile(root + '/test/browser_unit_tests.html'))
|
||||
.get('/builds.html', sendFile(root + '/test/browser_build_unit_tests.html'))
|
||||
|
||||
// support
|
||||
.get('/expect.js', sendFile(root + '/node_modules/expect.js/index.js'))
|
||||
.get('/mocha.css', sendFile(root + '/node_modules/mocha/mocha.css'))
|
||||
.get('/mocha.js', sendFile(root + '/node_modules/mocha/mocha.js'))
|
||||
.get(
|
||||
'/screencast-reporter.css',
|
||||
sendFile(
|
||||
root + '/node_modules/mocha-screencast-reporter/screencast-reporter.css'
|
||||
)
|
||||
)
|
||||
.get(
|
||||
'/screencast-reporter.js',
|
||||
sendFile(
|
||||
root + '/node_modules/mocha-screencast-reporter/screencast-reporter.js'
|
||||
)
|
||||
)
|
||||
|
||||
// libs
|
||||
.get('/angular.js', sendFile(root + '/bower_components/angular/angular.js'))
|
||||
.get(
|
||||
'/angular-mocks.js',
|
||||
sendFile(root + '/bower_components/angular-mocks/angular-mocks.js')
|
||||
)
|
||||
.get('/jquery.js', sendFile(root + '/node_modules/jquery/dist/jquery.js'))
|
||||
|
||||
// builds
|
||||
.get('/elasticsearch.js', sendFile(root + '/dist/elasticsearch.js'))
|
||||
.get(
|
||||
'/elasticsearch.angular.js',
|
||||
sendFile(root + '/dist/elasticsearch.angular.js')
|
||||
)
|
||||
.get(
|
||||
'/elasticsearch.jquery.js',
|
||||
sendFile(root + '/dist/elasticsearch.jquery.js')
|
||||
)
|
||||
|
||||
// bundles
|
||||
.get('/unit_tests.js', bundleTests('unit'))
|
||||
.get('/build_tests.js', bundleTests('build'));
|
||||
|
||||
http.createServer(app).listen(8000, function() {
|
||||
console.log('listening on port 8000');
|
||||
});
|
||||
@ -1,8 +0,0 @@
|
||||
// I know this is horrible
|
||||
// I just don't want the keys searchable on github
|
||||
module.exports = JSON.parse(
|
||||
new Buffer(
|
||||
'eyJ1c2VyIjoiZWxhc3RpY3NlYXJjaC1qcyIsImtleSI6IjI0ZjQ5ZTA3LWQ4MmYtNDA2Ny04NTRlLWQ4MTVlYmQxNWU0NiJ9',
|
||||
'base64'
|
||||
).toString('utf8')
|
||||
);
|
||||
Reference in New Issue
Block a user