|
| 1 | +import * as td from 'testdouble'; |
| 2 | +import any from '@travi/any'; |
| 3 | + |
| 4 | +suite('canary lifter', () => { |
| 5 | + let lift, removeCanary, canaryExists, glob; |
| 6 | + |
| 7 | + setup(async () => { |
| 8 | + ({glob} = await td.replaceEsm('tinyglobby')); |
| 9 | + ({default: removeCanary} = await td.replaceEsm('./remover.js')); |
| 10 | + ({default: canaryExists} = await td.replaceEsm('./tester.js')); |
| 11 | + |
| 12 | + ({default: lift} = (await import('./lifter.js'))); |
| 13 | + }); |
| 14 | + |
| 15 | + teardown(() => td.reset()); |
| 16 | + |
| 17 | + test('that the canary file is removed when other test files exist', async () => { |
| 18 | + const projectRoot = any.string(); |
| 19 | + td.when(canaryExists({projectRoot})).thenResolve(true); |
| 20 | + td.when(glob(['src/**/*-test.js', '!src/canary-test.js'], {cwd: projectRoot})).thenResolve(['other-test.js']); |
| 21 | + |
| 22 | + await lift({projectRoot}); |
| 23 | + |
| 24 | + td.verify(removeCanary({projectRoot})); |
| 25 | + }); |
| 26 | + |
| 27 | + test( |
| 28 | + 'that removing the canary file is not attempted when other test files exist but the canary is already removed', |
| 29 | + async () => { |
| 30 | + const projectRoot = any.string(); |
| 31 | + td.when(canaryExists({projectRoot})).thenResolve(false); |
| 32 | + |
| 33 | + await lift({projectRoot}); |
| 34 | + |
| 35 | + td.verify(removeCanary({projectRoot}), {times: 0}); |
| 36 | + } |
| 37 | + ); |
| 38 | + |
| 39 | + test('that the removing the canary file is not attempted when other test files do not exist', async () => { |
| 40 | + const projectRoot = any.string(); |
| 41 | + td.when(canaryExists({projectRoot})).thenResolve(true); |
| 42 | + td.when(glob(['src/**/*-test.js', '!src/canary-test.js'], {cwd: projectRoot})).thenResolve([]); |
| 43 | + |
| 44 | + await lift({projectRoot}); |
| 45 | + |
| 46 | + td.verify(removeCanary({projectRoot}), {times: 0}); |
| 47 | + }); |
| 48 | +}); |
0 commit comments