diff --git a/packages/jest-cli/src/TestSequencer.js b/packages/jest-cli/src/TestSequencer.js index c910aabe003e..d19ae95f2f1c 100644 --- a/packages/jest-cli/src/TestSequencer.js +++ b/packages/jest-cli/src/TestSequencer.js @@ -69,8 +69,8 @@ export default class TestSequencer { // fastest results. sort(tests: Array): Array { const stats = {}; - const fileSize = test => - stats[test.path] || (stats[test.path] = fs.statSync(test.path).size); + const fileSize = ({path, context: {hasteFS}}) => + stats[path] || (stats[path] = hasteFS.getSize(path) || 0); const hasFailed = (cache, test) => cache[test.path] && cache[test.path][0] === FAIL; const time = (cache, test) => cache[test.path] && cache[test.path][1]; diff --git a/packages/jest-cli/src/__tests__/test_sequencer.test.js b/packages/jest-cli/src/__tests__/test_sequencer.test.js index cab3a8ce4218..6ee46df7577a 100644 --- a/packages/jest-cli/src/__tests__/test_sequencer.test.js +++ b/packages/jest-cli/src/__tests__/test_sequencer.test.js @@ -23,6 +23,9 @@ const context = { cacheDirectory: '/cache', name: 'test', }, + hasteFS: { + getSize: path => path.length, + }, }; const secondContext = { @@ -31,6 +34,9 @@ const secondContext = { cacheDirectory: '/cache2', name: 'test2', }, + hasteFS: { + getSize: path => path.length, + }, }; const toTests = paths => @@ -45,7 +51,6 @@ beforeEach(() => { fs.readFileSync = jest.fn(() => '{}'); fs.existsSync = () => true; - fs.statSync = jest.fn(filePath => ({size: filePath.length})); fs.writeFileSync = jest.fn(); });