Skip to content

Commit c5bada9

Browse files
authored
Scheduler follow-up
* Write synchronously and ignore errors * Change filename * Fix integration test
1 parent d742672 commit c5bada9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/scheduler.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ const path = require('path');
33
const writeFileAtomic = require('write-file-atomic');
44
const isCi = require('./is-ci');
55

6-
const FILE_NAME_FAILING_TEST = 'failing-test.json';
6+
const FILENAME = 'failing-tests.json';
77

88
module.exports.storeFailedTestFiles = (runStatus, cacheDir) => {
99
if (isCi || !cacheDir) {
1010
return;
1111
}
1212

13-
writeFileAtomic(path.join(cacheDir, FILE_NAME_FAILING_TEST), JSON.stringify(runStatus.getFailedTestFiles()));
13+
try {
14+
writeFileAtomic.sync(path.join(cacheDir, FILENAME), JSON.stringify(runStatus.getFailedTestFiles()));
15+
} catch {}
1416
};
1517

1618
// Order test-files, so that files with failing tests come first
@@ -19,7 +21,7 @@ module.exports.failingTestsFirst = (selectedFiles, cacheDir, cacheEnabled) => {
1921
return selectedFiles;
2022
}
2123

22-
const filePath = path.join(cacheDir, FILE_NAME_FAILING_TEST);
24+
const filePath = path.join(cacheDir, FILENAME);
2325
let failedTestFiles;
2426
try {
2527
failedTestFiles = JSON.parse(fs.readFileSync(filePath));

test-tap/api.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ for (const opt of opts) {
542542
t.end();
543543
});
544544

545-
test('caching is enabled by default - workerThreads: {opt.workerThreads}', t => {
545+
test(`caching is enabled by default - workerThreads: ${opt.workerThreads}`, t => {
546546
del.sync(path.join(__dirname, 'fixture/caching/node_modules'));
547547

548548
const api = apiCreator({
@@ -556,7 +556,12 @@ for (const opt of opts) {
556556
const files = fs.readdirSync(path.join(__dirname, 'fixture/caching/node_modules/.cache/ava'));
557557
t.is(files.filter(x => x.endsWith('.js')).length, 1);
558558
t.is(files.filter(x => x.endsWith('.map')).length, 1);
559-
t.is(files.length, 2);
559+
if (files.length === 3) {
560+
// This file may be written locally, but not in CI.
561+
t.is(files.filter(x => x.startsWith('failing-tests.json')).length, 1);
562+
} else {
563+
t.is(files.length, 2);
564+
}
560565
});
561566
});
562567

0 commit comments

Comments
 (0)