Use standard and prettier (#10)
* switch from custom eslint config to standard + prettier * fix new standard eslint violations * add editorconfig file * auto-fix all other violations * update lint yarn script * remove jshint comment
This commit is contained in:
@ -1,19 +1,18 @@
|
||||
|
||||
var sinon = require('sinon');
|
||||
|
||||
exports.make = function () {
|
||||
exports.make = function() {
|
||||
var log = [];
|
||||
afterEach(function () {
|
||||
var stub;
|
||||
while (stub = log.pop()) {
|
||||
afterEach(function() {
|
||||
for (const stub of log) {
|
||||
stub.restore();
|
||||
}
|
||||
log.length = 0;
|
||||
});
|
||||
var stubber = function () {
|
||||
var stubber = function() {
|
||||
log.push(sinon.stub.apply(sinon, arguments));
|
||||
};
|
||||
|
||||
stubber.autoRelease = function (item) {
|
||||
stubber.autoRelease = function(item) {
|
||||
log.push(item);
|
||||
};
|
||||
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
var _ = require('lodash');
|
||||
var expect = require('expect.js');
|
||||
module.exports = function expectSubObject(obj, subObj) {
|
||||
_.forOwn(subObj, function (val, prop) {
|
||||
_.forOwn(subObj, function(val, prop) {
|
||||
if (typeof obj[prop] === 'object') {
|
||||
// non-strict equals
|
||||
expect(obj[prop]).to.eql(val, 'Expected property' + prop + ' of object to equal ' + val);
|
||||
expect(obj[prop]).to.eql(
|
||||
val,
|
||||
'Expected property' + prop + ' of object to equal ' + val
|
||||
);
|
||||
} else {
|
||||
expect(obj).property(prop, val);
|
||||
}
|
||||
|
||||
@ -14,18 +14,22 @@ var fs = require('fs');
|
||||
var path = require('path');
|
||||
var inspect = require('util').inspect;
|
||||
|
||||
var log = (function () {
|
||||
var log = (function() {
|
||||
var locked = _.bind(process.stdout.write, process.stdout);
|
||||
return function (str) {
|
||||
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 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) {
|
||||
@ -40,21 +44,18 @@ function JenkinsReporter(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var stats = this.stats;
|
||||
var pass = 0;
|
||||
var pending = 0;
|
||||
var fail = 0;
|
||||
var rootSuite = {
|
||||
results: [],
|
||||
suites: []
|
||||
suites: [],
|
||||
};
|
||||
|
||||
var stack = [rootSuite];
|
||||
|
||||
function indt() {
|
||||
return (new Array(stack.length + 1)).join(' ');
|
||||
return new Array(stack.length + 1).join(' ');
|
||||
}
|
||||
|
||||
runner.on('suite', function (suite) {
|
||||
runner.on('suite', function(suite) {
|
||||
if (suite.root) {
|
||||
return;
|
||||
}
|
||||
@ -65,7 +66,7 @@ function JenkinsReporter(runner) {
|
||||
results: [],
|
||||
start: Date.now(),
|
||||
stdout: '',
|
||||
stderr: ''
|
||||
stderr: '',
|
||||
};
|
||||
|
||||
// append to the previous stack leader
|
||||
@ -78,7 +79,7 @@ function JenkinsReporter(runner) {
|
||||
stack.unshift(suite);
|
||||
});
|
||||
|
||||
runner.on('suite end', function (suite) {
|
||||
runner.on('suite end', function(suite) {
|
||||
if (suite.root) {
|
||||
return;
|
||||
}
|
||||
@ -86,22 +87,19 @@ function JenkinsReporter(runner) {
|
||||
stack.shift();
|
||||
});
|
||||
|
||||
runner.on('fail', function (test) {
|
||||
if ('hook' === test.type) {
|
||||
runner.on('fail', function(test) {
|
||||
if (test.type === 'hook') {
|
||||
runner.emit('test end', test);
|
||||
}
|
||||
});
|
||||
|
||||
runner.on('test end', function (test) {
|
||||
runner.on('test end', function(test) {
|
||||
if (test.state === 'passed') {
|
||||
pass++;
|
||||
log(chalk.green('.'));
|
||||
} else if (test.pending) {
|
||||
pending++;
|
||||
log(chalk.grey('.'));
|
||||
return;
|
||||
} else {
|
||||
fail++;
|
||||
log(chalk.red('x'));
|
||||
}
|
||||
|
||||
@ -117,18 +115,24 @@ function JenkinsReporter(runner) {
|
||||
|
||||
// <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
|
||||
// check for the result of the stringifying.
|
||||
if ('[object Error]' === errMsg) {
|
||||
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) {
|
||||
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'));
|
||||
console.error(
|
||||
_.map(errMsg.split('\n'), function(line) {
|
||||
return indt() + ' ' + line;
|
||||
}).join('\n')
|
||||
);
|
||||
}
|
||||
|
||||
if (stack[0]) {
|
||||
@ -138,14 +142,18 @@ function JenkinsReporter(runner) {
|
||||
pass: test.state === 'passed',
|
||||
test: test,
|
||||
stdout: stack[0].stdout,
|
||||
stderr: stack[0].stderr
|
||||
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) {
|
||||
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;
|
||||
@ -153,7 +161,7 @@ function JenkinsReporter(runner) {
|
||||
}
|
||||
});
|
||||
|
||||
runner.on('end', function () {
|
||||
runner.on('end', function() {
|
||||
restoreStdio();
|
||||
var xml = makeJUnitXml('node ' + process.version, {
|
||||
stats: stats,
|
||||
@ -164,38 +172,43 @@ function JenkinsReporter(runner) {
|
||||
time: suite.time || 0,
|
||||
results: suite.results,
|
||||
stdout: suite.stdout,
|
||||
stderr: suite.stderr
|
||||
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'));
|
||||
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) {
|
||||
['stdout', 'stderr'].forEach(function(name) {
|
||||
var obj = process[name];
|
||||
var orig = obj.write;
|
||||
obj.write = function (chunk) {
|
||||
obj.write = function(chunk) {
|
||||
if (stack[0]) {
|
||||
stack[0][name] = (stack[0][name] || '') + chunk;
|
||||
}
|
||||
|
||||
// orig.apply(obj, arguments);
|
||||
};
|
||||
obj.__restore = function () {
|
||||
obj.__restore = function() {
|
||||
this.write = orig;
|
||||
};
|
||||
});
|
||||
@ -204,5 +217,4 @@ function JenkinsReporter(runner) {
|
||||
process.stdout.__restore();
|
||||
process.stderr.__restore();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -33,7 +33,6 @@ var chalk = require('chalk');
|
||||
|
||||
function makeJUnitXml(runnerName, testDetails) {
|
||||
_.each(testDetails.suites, function serializeSuite(suiteInfo) {
|
||||
|
||||
var suite = suites.ele('testsuite', {
|
||||
package: 'elasticsearch-js',
|
||||
id: suiteCount++,
|
||||
@ -43,15 +42,19 @@ function makeJUnitXml(runnerName, testDetails) {
|
||||
tests: (suiteInfo.results && suiteInfo.results.length) || 0,
|
||||
failures: _.filter(suiteInfo.results, { pass: false }).length,
|
||||
errors: 0,
|
||||
time: suiteInfo.time / 1000
|
||||
time: suiteInfo.time / 1000,
|
||||
});
|
||||
|
||||
_.each(suiteInfo.results, function (testInfo) {
|
||||
_.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, '/');
|
||||
section = suiteInfo.name
|
||||
.split('/')
|
||||
.slice(0, -1)
|
||||
.join('/')
|
||||
.replace(/\./g, '/');
|
||||
} else {
|
||||
section = suiteInfo.name.replace(/\./g, ',');
|
||||
}
|
||||
@ -64,18 +67,19 @@ function makeJUnitXml(runnerName, testDetails) {
|
||||
var testcase = suite.ele('testcase', {
|
||||
name: testInfo.name,
|
||||
time: (testInfo.time || 0) / 1000,
|
||||
classname: runnerName + (integration ? ' - integration' : '') + '.' + section
|
||||
classname:
|
||||
runnerName + (integration ? ' - integration' : '') + '.' + section,
|
||||
});
|
||||
|
||||
if (testInfo.errMsg) {
|
||||
testcase.ele('failure', {
|
||||
message: testInfo.errMsg,
|
||||
type: 'AssertError'
|
||||
type: 'AssertError',
|
||||
});
|
||||
} else if (!testInfo.pass) {
|
||||
testcase.ele('error', {
|
||||
message: 'Unknown Error',
|
||||
type: 'TestError'
|
||||
type: 'TestError',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -20,20 +20,21 @@ testFiles.unit = _(fs.readdirSync(unitSpecDir))
|
||||
'console_logger.js',
|
||||
'stream_logger.js',
|
||||
'tracer_logger.js',
|
||||
'transport_with_server.js'
|
||||
'transport_with_server.js',
|
||||
])
|
||||
.map(function (file) {
|
||||
.map(function(file) {
|
||||
return unitSpecDir + '/' + file;
|
||||
})
|
||||
.value();
|
||||
|
||||
testFiles.build = fs.readdirSync(browserBuildsDir)
|
||||
.map(function (file) {
|
||||
testFiles.build = fs
|
||||
.readdirSync(browserBuildsDir)
|
||||
.map(function(file) {
|
||||
if (file.substr(-3) === '.js') {
|
||||
return browserBuildsDir + '/' + file;
|
||||
}
|
||||
|
||||
return null
|
||||
return null;
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
@ -42,27 +43,29 @@ var aliasify = require('aliasify').configure({
|
||||
aliases: pkg.browser,
|
||||
excludeExtensions: 'json',
|
||||
// verbose: false,
|
||||
configDir: root
|
||||
configDir: root,
|
||||
});
|
||||
|
||||
// queue for bundle requests, two at a time
|
||||
var bundleQueue = async.queue(function (task, done) {
|
||||
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); }
|
||||
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
|
||||
insertGlobals: true,
|
||||
});
|
||||
b.transform(aliasify);
|
||||
var str = b.bundle();
|
||||
@ -76,7 +79,7 @@ function bundleTests(name) {
|
||||
|
||||
// create a route that just rends a specific file (like a symlink or something)
|
||||
function sendFile(file) {
|
||||
return function (req, res) {
|
||||
return function(req, res) {
|
||||
res.sendfile(file);
|
||||
};
|
||||
}
|
||||
@ -93,25 +96,42 @@ app
|
||||
.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'))
|
||||
.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(
|
||||
'/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'))
|
||||
.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'))
|
||||
.get('/build_tests.js', bundleTests('build'));
|
||||
|
||||
;
|
||||
|
||||
http.createServer(app).listen(8000, function () {
|
||||
http.createServer(app).listen(8000, function() {
|
||||
console.log('listening on port 8000');
|
||||
});
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
// 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'));
|
||||
module.exports = JSON.parse(
|
||||
new Buffer(
|
||||
'eyJ1c2VyIjoiZWxhc3RpY3NlYXJjaC1qcyIsImtleSI6IjI0ZjQ5ZTA3LWQ4MmYtNDA2Ny04NTRlLWQ4MTVlYmQxNWU0NiJ9',
|
||||
'base64'
|
||||
).toString('utf8')
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user