From d98d7e712da33bf48188eaa3aefa6dfa244c204f Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Sat, 5 Jan 2019 14:40:30 +0100 Subject: [PATCH] use hasteFS.getSize in TestSequencer --- packages/jest-cli/src/TestSequencer.js | 4 ++-- packages/jest-cli/src/__tests__/test_sequencer.test.js | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) 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(); });