@kiwicom/eslint-config
Version:
Eslint configuration describing rules for JS used at Kiwi.com.
131 lines (113 loc) • 2.81 kB
JavaScript
"use strict";
require('@babel/register'); // to be able to use non-transpiled '@kiwicom/monorepo-utils' here
var _require = require('create-jest-runner'),
pass = _require.pass,
fail = _require.fail,
skip = _require.skip;
var CLIEngine = require('eslint').CLIEngine;
var isCI = require('is-ci');
var _require2 = require('@kiwicom/monorepo-utils'),
Git = _require2.Git;
var formatter = require('./stylish');
var PERFORM_FIXES = isCI === false;
var cliEngine = new CLIEngine({
fix: PERFORM_FIXES,
reportUnusedDisableDirectives: true
});
var changedFiles = Git.getChangesToTest();
module.exports = function (_ref) {
var testPath = _ref.testPath,
extraOptions = _ref.extraOptions;
var start = Date.now();
if (cliEngine.isPathIgnored(testPath)) {
return skip({
start: start,
end: start,
test: {
path: testPath
}
});
}
if (extraOptions.runAll === false) {
var normalizedPath = testPath.replace(process.cwd(), '').replace(/^\//, '');
if (changedFiles.includes(normalizedPath) === false) {
return skip({
start: start,
end: start,
test: {
path: testPath
}
});
}
}
var report = cliEngine.executeOnFiles([testPath]);
if (PERFORM_FIXES) {
CLIEngine.outputFixes(report);
}
var end = Date.now();
var result = report.results[0];
if (result.errorCount === 0 && result.warningCount > 0) {
return passWithWarning({
start: start,
end: end,
test: {
path: testPath,
warningMessage: formatter(report.results)
}
});
} else if (result.errorCount > 0) {
return fail({
start: start,
end: end,
test: {
path: testPath,
errorMessage: formatter(report.results)
}
});
}
return pass({
start: start,
end: end,
test: {
path: testPath
}
});
};
function passWithWarning(_ref2) {
var start = _ref2.start,
end = _ref2.end,
test = _ref2.test;
return {
console: null,
failureMessage: test.warningMessage,
numFailingTests: 0,
numPassingTests: 1,
numPendingTests: 0,
numTodoTests: 0,
perfStats: {
end: new Date(start).getTime(),
start: new Date(end).getTime()
},
skipped: false,
snapshot: {
added: 0,
fileDeleted: false,
matched: 0,
unchecked: 0,
unmatched: 0,
updated: 0
},
sourceMaps: {},
testExecError: null,
testFilePath: test.path,
testResults: [{
ancestorTitles: [],
duration: end - start,
failureMessages: [test.warningMessage],
fullName: test.path,
numPassingAsserts: test.warningMessage ? 1 : 0,
status: test.warningMessage ? 'failed' : 'passed',
title: ''
}]
};
}