mirror of
https://github.com/directus/directus.git
synced 2026-01-14 17:07:56 -05:00
* Fix remaining blackbox test issues * Temporary activation of blackbox tests (sqlite) * Enable hanging-process reporter for now * Revert "Enable hanging-process reporter for now" This reverts commitce490ba229. * Fix hanging by cleaning up sequential list Also prevent this issue in future by logging invalid files in list * Switch remaining tests to `getPort` To get random, available ports * Revert "Temporary activation of blackbox tests (sqlite)" This reverts commita8687a095a.
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import { findIndex } from 'lodash-es';
|
|
import fs from 'node:fs/promises';
|
|
import { BaseSequencer, type WorkspaceSpec } from 'vitest/node';
|
|
import { sequentialTestsList } from './sequential-tests';
|
|
|
|
export default class CustomSequencer extends BaseSequencer {
|
|
override async sort(files: WorkspaceSpec[]) {
|
|
if (files.length > 1) {
|
|
const list = sequentialTestsList[files[0]![0].config.name as 'db' | 'common'];
|
|
|
|
// If specified, only run these tests sequentially
|
|
if (list.only.length > 0) {
|
|
const onlyTests = [];
|
|
|
|
for (const sequentialTest of list.only) {
|
|
const testIndex = findIndex(files, ([_, testFile]) => {
|
|
return testFile.endsWith(sequentialTest);
|
|
});
|
|
|
|
if (testIndex !== -1) {
|
|
const test = files[testIndex];
|
|
|
|
if (test) {
|
|
onlyTests.push(test);
|
|
}
|
|
} else {
|
|
throw new Error(`Non-existent test file "${sequentialTest}" in "only" list`);
|
|
}
|
|
}
|
|
|
|
files = onlyTests;
|
|
} else {
|
|
for (const sequentialTest of list.before.slice().reverse()) {
|
|
const testIndex = findIndex(files, ([_, testFile]) => {
|
|
return testFile.endsWith(sequentialTest);
|
|
});
|
|
|
|
if (testIndex !== -1) {
|
|
const test = files.splice(testIndex, 1)[0];
|
|
|
|
if (test) {
|
|
files.unshift(test);
|
|
}
|
|
} else {
|
|
throw new Error(`Non-existent test file "${sequentialTest}" in "before" list`);
|
|
}
|
|
}
|
|
|
|
for (const sequentialTest of list.after) {
|
|
const testIndex = findIndex(files, ([_, testFile]) => {
|
|
return testFile.endsWith(sequentialTest);
|
|
});
|
|
|
|
if (testIndex !== -1) {
|
|
const test = files.splice(testIndex, 1)[0];
|
|
|
|
if (test) {
|
|
files.push(test);
|
|
}
|
|
} else {
|
|
throw new Error(`Non-existent test file "${sequentialTest}" in "after" list`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Expose sequencer data to setup & tests
|
|
await fs.writeFile('sequencer-data.json', JSON.stringify({ totalTestsCount: files.length }));
|
|
|
|
return files;
|
|
}
|
|
}
|