-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathJestRandomSequencer.js
More file actions
26 lines (22 loc) · 909 Bytes
/
JestRandomSequencer.js
File metadata and controls
26 lines (22 loc) · 909 Bytes
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
/* eslint-disable @typescript-eslint/no-var-requires */
const Sequencer = require('@jest/test-sequencer').default;
// https://stackoverflow.com/a/12646864
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
// eslint-disable-next-line no-param-reassign
[array[i], array[j]] = [array[j], array[i]];
}
}
// This randomizes test files, not be confused with [Ability to run tests within a file in a random order](https://github.com/facebook/jest/issues/4386)
// https://github.com/facebook/jest/issues/6194#issuecomment-582428526
class JestRandomSequencer extends Sequencer {
// eslint-disable-next-line class-methods-use-this
sort(tests) {
// https://stackoverflow.com/a/18650169
// tests.sort(() => Math.random() - 0.5);
shuffleArray(tests);
return tests;
}
}
module.exports = JestRandomSequencer;