index.d.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. import type { AggregatedResult } from '@jest/test-result';
  8. import type { Test } from 'jest-runner';
  9. import type { Context } from 'jest-runtime';
  10. declare type Cache = {
  11. [key: string]: [0 | 1, number];
  12. };
  13. /**
  14. * The TestSequencer will ultimately decide which tests should run first.
  15. * It is responsible for storing and reading from a local cache
  16. * map that stores context information for a given test, such as how long it
  17. * took to run during the last run and if it has failed or not.
  18. * Such information is used on:
  19. * TestSequencer.sort(tests: Array<Test>)
  20. * to sort the order of the provided tests.
  21. *
  22. * After the results are collected,
  23. * TestSequencer.cacheResults(tests: Array<Test>, results: AggregatedResult)
  24. * is called to store/update this information on the cache map.
  25. */
  26. export default class TestSequencer {
  27. private _cache;
  28. _getCachePath(context: Context): string;
  29. _getCache(test: Test): Cache;
  30. /**
  31. * Sorting tests is very important because it has a great impact on the
  32. * user-perceived responsiveness and speed of the test run.
  33. *
  34. * If such information is on cache, tests are sorted based on:
  35. * -> Has it failed during the last run ?
  36. * Since it's important to provide the most expected feedback as quickly
  37. * as possible.
  38. * -> How long it took to run ?
  39. * Because running long tests first is an effort to minimize worker idle
  40. * time at the end of a long test run.
  41. * And if that information is not available they are sorted based on file size
  42. * since big test files usually take longer to complete.
  43. *
  44. * Note that a possible improvement would be to analyse other information
  45. * from the file other than its size.
  46. *
  47. */
  48. sort(tests: Array<Test>): Array<Test>;
  49. allFailedTests(tests: Array<Test>): Array<Test>;
  50. cacheResults(tests: Array<Test>, results: AggregatedResult): void;
  51. }
  52. export {};