Skip to content

Commit 7b17bf9

Browse files
committed
feat(canary): remove when other test files exist
1 parent e98afd9 commit 7b17bf9

File tree

13 files changed

+190
-3
lines changed

13 files changed

+190
-3
lines changed

package-lock.json

Lines changed: 44 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"dependencies": {
6060
"@form8ion/config-file": "^1.0.1",
6161
"@form8ion/core": "^4.0.0",
62-
"filedirname": "^3.0.0"
62+
"filedirname": "^3.0.0",
63+
"tinyglobby": "^0.2.11"
6364
},
6465
"devDependencies": {
6566
"@cucumber/cucumber": "11.2.0",

src/canary/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export {default as scaffold} from './scaffolder.js';
22
export {default as test} from './tester.js';
3+
export {default as lift} from './lifter.js';
34
export {default as remove} from './remover.js';

src/canary/lifter-test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
});

src/canary/lifter.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {glob} from 'tinyglobby';
2+
3+
import canaryExists from './tester.js';
4+
import removeCanary from './remover.js';
5+
6+
async function otherTestFilesExist(projectRoot) {
7+
const otherTestFiles = await glob(['src/**/*-test.js', '!src/canary-test.js'], {cwd: projectRoot});
8+
9+
return 0 < otherTestFiles.length;
10+
}
11+
12+
export default async function ({projectRoot}) {
13+
if (await canaryExists({projectRoot}) && await otherTestFilesExist(projectRoot)) {
14+
await removeCanary({projectRoot});
15+
}
16+
}

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export {default as scaffold} from './scaffolder.js';
2+
export {default as lift} from './lifter.js';
23
export {default as test} from './tester.js';
34
export {default as remove} from './remover.js';

src/lifter-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import any from '@travi/any';
2+
import * as td from 'testdouble';
3+
4+
suite('lifter', () => {
5+
let lift, liftCanary;
6+
7+
setup(async () => {
8+
({lift: liftCanary} = await td.replaceEsm('./canary/index.js'));
9+
10+
({default: lift} = (await import('./lifter.js')));
11+
});
12+
13+
teardown(() => td.reset());
14+
15+
test('that the mocha details are lifted', async () => {
16+
const projectRoot = any.string();
17+
18+
await lift({projectRoot});
19+
20+
td.verify(liftCanary({projectRoot}));
21+
});
22+
});

src/lifter.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {lift as liftCanary} from './canary/index.js';
2+
3+
export default async function ({projectRoot}) {
4+
await liftCanary({projectRoot});
5+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Feature: Lift Mocha
2+
3+
Scenario: canary test without other tests yet
4+
Given a mocharc file exists
5+
And the canary test still exists
6+
When the project is lifted
7+
Then the canary test is not removed
8+
9+
Scenario: other mocha tests exist, but canary test still exists
10+
Given a mocharc file exists
11+
And other mocha tests exist
12+
And the canary test still exists
13+
When the project is lifted
14+
Then the canary test is removed
15+
16+
Scenario: other mocha tests exist, but canary test no longer exists
17+
Given a mocharc file exists
18+
And other mocha tests exist
19+
When the project is lifted
20+
Then the canary test is removed

test/integration/features/scaffold.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ Feature: scaffold
44
When the project is scaffolded
55
Then the testing framework is configured
66
And dependencies are defined
7+
And the filename pattern is reported
78
And a canary test exists to ensure the framework configuration works

0 commit comments

Comments
 (0)