|
| 1 | +const test = require('@ava/test'); |
| 2 | +const exec = require('../helpers/exec'); |
| 3 | + |
| 4 | +const options = { |
| 5 | + // The scheduler only works when not in CI, so trick it into believing it is |
| 6 | + // not in CI even when it's being tested by AVA's CI. |
| 7 | + env: {AVA_FORCE_CI: 'not-ci'} |
| 8 | +}; |
| 9 | + |
| 10 | +function getTimestamps(stats) { |
| 11 | + return {passed: BigInt(stats.getLogs(stats.passed[0])), failed: BigInt(stats.getLogs(stats.failed[0]))}; |
| 12 | +} |
| 13 | + |
| 14 | +test.serial('failing tests come first', async t => { |
| 15 | + try { |
| 16 | + await exec.fixture(['1pass.js', '2fail.js'], options); |
| 17 | + } catch {} |
| 18 | + |
| 19 | + try { |
| 20 | + await exec.fixture(['-t', '--concurrency=1', '1pass.js', '2fail.js'], options); |
| 21 | + } catch (error) { |
| 22 | + const timestamps = getTimestamps(error.stats); |
| 23 | + t.true(timestamps.failed < timestamps.passed); |
| 24 | + } |
| 25 | +}); |
| 26 | + |
| 27 | +test.serial('scheduler disabled when cache empty', async t => { |
| 28 | + await exec.fixture(['reset-cache'], options); // `ava reset-cache` resets the cache but does not run tests. |
| 29 | + try { |
| 30 | + await exec.fixture(['-t', '--concurrency=1', '1pass.js', '2fail.js'], options); |
| 31 | + } catch (error) { |
| 32 | + const timestamps = getTimestamps(error.stats); |
| 33 | + t.true(timestamps.passed < timestamps.failed); |
| 34 | + } |
| 35 | +}); |
| 36 | + |
| 37 | +test.serial('scheduler disabled when cache disabled', async t => { |
| 38 | + try { |
| 39 | + await exec.fixture(['1pass.js', '2fail.js'], options); |
| 40 | + } catch {} |
| 41 | + |
| 42 | + try { |
| 43 | + await exec.fixture(['-t', '--concurrency=1', '--config', 'disabled-cache.cjs', '1pass.js', '2fail.js'], options); |
| 44 | + } catch (error) { |
| 45 | + const timestamps = getTimestamps(error.stats); |
| 46 | + t.true(timestamps.passed < timestamps.failed); |
| 47 | + } |
| 48 | +}); |
| 49 | + |
| 50 | +test.serial('scheduler disabled in CI', async t => { |
| 51 | + try { |
| 52 | + await exec.fixture(['1pass.js', '2fail.js'], {env: {AVA_FORCE_CI: 'ci'}}); |
| 53 | + } catch {} |
| 54 | + |
| 55 | + try { |
| 56 | + await exec.fixture(['-t', '--concurrency=1', '--config', 'disabled-cache.cjs', '1pass.js', '2fail.js'], options); |
| 57 | + } catch (error) { |
| 58 | + const timestamps = getTimestamps(error.stats); |
| 59 | + t.true(timestamps.passed < timestamps.failed); |
| 60 | + } |
| 61 | +}); |
0 commit comments