-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.ts
55 lines (45 loc) · 1.49 KB
/
report.ts
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
import path from "path";
import {promises as fs} from "fs";
/**
* Moves test results to a destination directory with optional renaming
*
* @param {string} testTag Tag name of the report generated.
* @returns Promise<string> Path where the folder was moved to
*/
export async function moveTestReport(testTag: string): Promise<string> {
const SOURCE_FOLDER = 'test-results';
const destinationDir = '/var/shared/rocket-e2e-reports';
// Validate source folder exists
try {
await fs.access(SOURCE_FOLDER);
} catch (error) {
throw new Error(`Source folder '${SOURCE_FOLDER}' does not exist`);
}
// Ensure destination directory exists
try {
await fs.access(destinationDir);
} catch (error) {
throw new Error(`Destination directory '${destinationDir}' does not exist`);
}
const newTestReportPath = path.join(destinationDir, testTag);
try {
await fs.rename(SOURCE_FOLDER, newTestReportPath);
return newTestReportPath;
} catch (error) {
throw new Error(`Failed to move folder: ${error.message}`);
}
}
(async (): Promise<void> => {
try {
const tag = process.env.npm_config_tag;
//If tag is not provided, then the report shouldn't be moved or renamed.
if(! tag) {
process.exit(1);
}
await moveTestReport(tag);
} catch (err) {
console.error(`Failed to execute the script: ${err.message}`);
process.exit(1);
}
process.exit(0);
})();