index.d.ts 2.0 KB

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