Skip to content

Commit

Permalink
Dev: ESLint run on largest files first [fix]
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Sep 2, 2023
1 parent f519704 commit f43f8e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions jest-eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
module.exports = {
testEnvironment: 'node',
runner: 'jest-runner-eslint',
testSequencer: '<rootDir>/test/support/eslintSequencer.js',
testMatch: ['<rootDir>/**/*.(js|cjs|mjs|jsx)'],
// Jest by default uses a number of workers equal to number of CPU cores minus 1.
// Github Actions runners provide 2 cores and running with 2 workers is faster than 1.
Expand Down
26 changes: 26 additions & 0 deletions test/support/eslintSequencer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* --------------------
* livepack
* Custom test sequencer for Jest ESLint
* ------------------*/

'use strict';

// Modules
const fs = require('fs'),
Sequencer = require('@jest/test-sequencer').default;

// Exports

// Custom sequencer to ensure the largest files are run first.
// `jest-runner-eslint` doesn't seem to sequence automatically.
// https://github.com/jest-community/jest-runner-eslint/issues/204
// TODO: Remove this workaround once above issue is fixed.

module.exports = class CustomSequencer extends Sequencer {
sort(tests) {
tests = super.sort(tests);
const testsWithFileSizes = tests.map(test => ({test, size: fs.statSync(test.path).size}));
testsWithFileSizes.sort((t1, t2) => (t1.size > t2.size ? -1 : t1.size < t2.size ? 1 : 0));
return testsWithFileSizes.map(({test}) => test);
}
};

0 comments on commit f43f8e6

Please sign in to comment.