UNPKG

2.79 kBJavaScriptView Raw
1require('@babel/register'); // to be able to use non-transpiled '@kiwicom/monorepo-utils' here
2
3
4var _require = require('create-jest-runner'),
5 pass = _require.pass,
6 fail = _require.fail,
7 skip = _require.skip;
8
9var CLIEngine = require('eslint').CLIEngine;
10
11var isCI = require('is-ci');
12
13var _require2 = require('@kiwicom/monorepo-utils'),
14 Git = _require2.Git;
15
16var formatter = require('./stylish');
17
18var PERFORM_FIXES = isCI === false;
19var cliEngine = new CLIEngine({
20 fix: PERFORM_FIXES,
21 reportUnusedDisableDirectives: true
22});
23var changedFiles = Git.getChangesToTest();
24
25module.exports = function (_ref) {
26 var testPath = _ref.testPath,
27 extraOptions = _ref.extraOptions;
28 var start = Date.now();
29
30 if (cliEngine.isPathIgnored(testPath)) {
31 return skip({
32 start: start,
33 end: start,
34 test: {
35 path: testPath
36 }
37 });
38 }
39
40 if (extraOptions.runAll === false) {
41 var normalizedPath = testPath.replace(process.cwd(), '').replace(/^\//, '');
42
43 if (changedFiles.includes(normalizedPath) === false) {
44 return skip({
45 start: start,
46 end: start,
47 test: {
48 path: testPath
49 }
50 });
51 }
52 }
53
54 var report = cliEngine.executeOnFiles([testPath]);
55
56 if (PERFORM_FIXES) {
57 CLIEngine.outputFixes(report);
58 }
59
60 var end = Date.now();
61 var result = report.results[0];
62
63 if (result.errorCount === 0 && result.warningCount > 0) {
64 return passWithWarning({
65 start: start,
66 end: end,
67 test: {
68 path: testPath,
69 warningMessage: formatter(report.results)
70 }
71 });
72 } else if (result.errorCount > 0) {
73 return fail({
74 start: start,
75 end: end,
76 test: {
77 path: testPath,
78 errorMessage: formatter(report.results)
79 }
80 });
81 }
82
83 return pass({
84 start: start,
85 end: end,
86 test: {
87 path: testPath
88 }
89 });
90};
91
92function passWithWarning(_ref2) {
93 var start = _ref2.start,
94 end = _ref2.end,
95 test = _ref2.test;
96 return {
97 console: null,
98 failureMessage: test.warningMessage,
99 numFailingTests: 0,
100 numPassingTests: 1,
101 numPendingTests: 0,
102 numTodoTests: 0,
103 perfStats: {
104 end: new Date(start).getTime(),
105 start: new Date(end).getTime()
106 },
107 skipped: false,
108 snapshot: {
109 added: 0,
110 fileDeleted: false,
111 matched: 0,
112 unchecked: 0,
113 unmatched: 0,
114 updated: 0
115 },
116 sourceMaps: {},
117 testExecError: null,
118 testFilePath: test.path,
119 testResults: [{
120 ancestorTitles: [],
121 duration: end - start,
122 failureMessages: [test.warningMessage],
123 fullName: test.path,
124 numPassingAsserts: test.warningMessage ? 1 : 0,
125 status: test.warningMessage ? 'failed' : 'passed',
126 title: ''
127 }]
128 };
129}
\No newline at end of file