-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathscheduler.js
66 lines (53 loc) · 1.36 KB
/
scheduler.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
import fs from 'node:fs';
import path from 'node:path';
import writeFileAtomic from 'write-file-atomic';
import isCi from './is-ci.js';
const FILENAME = 'failing-tests.json';
const scheduler = {
storeFailedTestFiles(runStatus, cacheDir) {
if (isCi || !cacheDir) {
return;
}
const filename = path.join(cacheDir, FILENAME);
// Given that we're writing to a cache directory, consider this file
// temporary.
const temporaryFiles = [filename];
try {
writeFileAtomic.sync(filename, JSON.stringify(runStatus.getFailedTestFiles()), {
tmpfileCreated(tmpfile) {
temporaryFiles.push(tmpfile);
},
});
} catch {}
return {
changedFiles: [],
temporaryFiles,
};
},
// Order test-files, so that files with failing tests come first
failingTestsFirst(selectedFiles, cacheDir, cacheEnabled) {
if (isCi || cacheEnabled === false) {
return selectedFiles;
}
const filePath = path.join(cacheDir, FILENAME);
let failedTestFiles;
try {
failedTestFiles = JSON.parse(fs.readFileSync(filePath));
} catch {
return selectedFiles;
}
return [...selectedFiles].sort((f, s) => {
if (failedTestFiles.includes(f) && failedTestFiles.includes(s)) {
return 0;
}
if (failedTestFiles.includes(f)) {
return -1;
}
if (failedTestFiles.includes(s)) {
return 1;
}
return 0;
});
},
};
export default scheduler;