-
Notifications
You must be signed in to change notification settings - Fork 44
/
writer.js
89 lines (78 loc) · 2.95 KB
/
writer.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
const path = require('path-browserify');
const process = require('process');
const logger = require('./reporter/debug');
const { allurePropertiesToEnvVars } = require('./writer/readProperties');
const { shouldUseAfterSpec } = require('./writer/useAfterSpec');
const { alreadyRegisteredAfterSpec } = require('./writer/checkPluginsFile');
const { handleResults } = require('./writer/handleCypressResults');
const { writeResultFiles } = require('./writer/results');
function allureWriter(on, config) {
allurePropertiesToEnvVars(config.env);
if (!config.env.allureResultsPath) {
config.env.allureResultsPath = 'allure-results';
}
let allureMapping = null;
if (shouldUseAfterSpec(config)) {
logger.writer(
'allure should use "after:spec" for handling attachments'
);
if (
config.env.allureReuseAfterSpec ||
alreadyRegisteredAfterSpec(config)
) {
logger.writer(
'you already have "after:spec", allure plugin will listen to process'
);
// in case cypress "after:spec" event is already registered by user
// and we will register new callback - it will be overwritten
// as a workaround we will listen directly to process messages
// ( cypress uses it to trigger event for internal event emitter under the hood )
process.on('message', (message) => {
const [event, , args] = message.args;
if (!config.env.allure || event !== 'after:spec') {
return;
}
const [, results] = args;
logger.writer('got "after:spec" process message');
handleResults(allureMapping, results, config);
});
} else {
logger.writer('register "after:spec" event listener');
on('after:spec', (_, results) => {
if (!config.env.allure) {
return;
}
logger.writer('inside "after:spec" event');
handleResults(allureMapping, results, config);
});
}
}
on('task', {
writeAllureResults: ({
results,
files,
mapping,
clearSkipped,
isGlobal,
defineHistoryId
}) => {
const { resultsDir: relativeResultsDir, writer } = results;
const resultsDir = config.projectRoot
? path.join(config.projectRoot, relativeResultsDir)
: relativeResultsDir;
config.env.allureResultsPath = resultsDir;
allureMapping = mapping;
writeResultFiles({
resultsDir,
files,
clearSkipped,
writer,
allureMapping,
isGlobal,
defineHistoryId
});
return null;
}
});
}
module.exports = allureWriter;