-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjest.config.js
136 lines (128 loc) · 4.38 KB
/
jest.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { findLemmaById, findPosTags, toHTML } = require('./dist/__utils__');
const isId = (value) => Number.isFinite(parseInt(value, 10));
/** @type {import('jest-allure2-reporter').ReporterOptions} */
const allureConfig = {
executor: {
reportName: '@interslavic/utils',
},
testCase: {
ignored: (context) =>
context.testCase.status === 'passed' ||
context.testCase.status === 'skipped' ||
context.testCase.status === 'pending',
displayName: ({ testCase, value }) => {
const maybeId = testCase.title;
return isId(maybeId) ? findLemmaById(String(maybeId)) : value;
},
parameters: {
ID: ({ testCase }) => (isId(testCase.title) ? testCase.title : undefined),
},
statusDetails: ({ value }) => {
if (value?.message?.includes(').toMatchSnapshot(')) {
return {
message: 'Snapshot mismatch. Click to see the detailed comparison.',
trace: value?.message,
};
}
return value;
},
description: () => void 0,
descriptionHtml: ({ testCase, value = '' }) => {
const content =
testCase.status === 'failed' ? toHTML(testCase) + value : value;
return `\
<style>
figcaption { margin: 1em 0; font-style: italic; }
figure caption { font-style: italic; margin-bottom: 0.5em; text-align: left }
figure > table { margin-bottom: 0.75em }
figure th { background-color: #e4edfe }
figure th, figure td {
border: 1px solid #777;
padding: 0.5ch;
}
figure td > del {
background-color: #ffe7e6;
color: #9e0500;
display: block;
}
figure td > ins {
font-style: normal;
background-color: #eef9eb;
color: #125400;
display: block;
}
</style>
${content}
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
const testID = ${JSON.stringify(testCase.fullName)};
this.language = navigator.language;
this.page.url = window.location.href;
this.page.title = window.location.hostname + '(' + testID + ')';
this.page.identifier = window.location.hostname + '/allure/' + encodeURIComponent(testID);
};
(function() {
var d = document, s = d.createElement('script');
s.src = 'https://interslavic-allure.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>`;
},
labels: {
tag: ({ testCase, value }) => {
if (!isId(testCase.title)) {
return value;
}
const tags = Array.isArray(value) ? value : value ? [value] : [];
const expected = testCase.failureDetails.find((detail) => detail?.matcherResult?.expected);
const actual = testCase.failureDetails.find((detail) => detail?.matcherResult?.actual);
if (expected && actual) {
tags.push('update');
} else if (actual) {
tags.push('addition');
} else if (expected) {
tags.push('deletion');
}
tags.push(...findPosTags(testCase.title));
return tags;
},
},
},
testFile: {
ignored: false,
displayName: ({ filePath }) => {
return filePath.slice(1).join('/');
},
parameters: {
'Total tests': ({ testFile }) =>
testFile.numPassingTests +
testFile.numFailingTests +
testFile.numPendingTests,
},
status: ({ testFile, value }) => {
return testFile.numFailingTests > 0 ? 'failed' : value;
},
description: ({ testFile, value = '' }) => {
const {
numPassingTests: passed,
numFailingTests: failed,
numPendingTests: pending,
} = testFile;
const summary = `**${passed}** passed, **${failed}** failed, **${pending}** pending`;
return summary + '\n\n' + value;
},
},
};
/** @type {import('jest').Config} */
module.exports = {
collectCoverage: !!process.env.CI,
reporters: ['default', ['jest-allure2-reporter', allureConfig]],
testEnvironment: 'jest-allure2-reporter/environment-node',
transform: {
'\\.ts$': 'ts-jest',
},
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
};