Files
directus/tests/blackbox/setup/customSequencer.js
Pascal Jufer 15b91dee34 Blackbox tests restructuring (#18122)
Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
Co-authored-by: ian <licitdev@gmail.com>
Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
2023-04-11 18:28:37 +02:00

55 lines
1.5 KiB
JavaScript

const Sequencer = require('@jest/test-sequencer').default;
const findIndex = require('lodash').findIndex;
const sequentialTestsList = require('./sequentialTests.js').list;
class CustomSequencer extends Sequencer {
async sort(tests) {
let sortedTests = Array.from(tests);
if (sortedTests.length > 1) {
// If specified, only run these tests sequentially
if (sequentialTestsList.only.length > 0) {
let onlyTests = [];
for (let sequentialTest of sequentialTestsList.only) {
const testIndex = findIndex(sortedTests, (test) => {
return String(test.path).endsWith(sequentialTest.testFilePath);
});
if (testIndex !== -1) {
onlyTests.push(sortedTests[testIndex]);
}
}
sortedTests = onlyTests;
} else {
for (let sequentialTest of sequentialTestsList.before.slice().reverse()) {
const testIndex = findIndex(sortedTests, (test) => {
return String(test.path).endsWith(sequentialTest.testFilePath);
});
if (testIndex !== -1) {
sortedTests.unshift(sortedTests.splice(testIndex, 1)[0]);
}
}
for (let sequentialTest of sequentialTestsList.after) {
const testIndex = findIndex(sortedTests, (test) => {
return String(test.path).endsWith(sequentialTest.testFilePath);
});
if (testIndex !== -1) {
sortedTests.push(sortedTests.splice(testIndex, 1)[0]);
}
}
}
}
process.env.totalTestsCount = String(sortedTests.length);
return sortedTests;
}
}
module.exports = CustomSequencer;