Skip to content

Commit d1c87c0

Browse files
committed
feat(testing): enabled integration testing with cucumber
1 parent 7060d3b commit d1c87c0

File tree

9 files changed

+97
-4
lines changed

9 files changed

+97
-4
lines changed

.eslintrc.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ extends:
22
- '@form8ion'
33
- '@form8ion/mocha'
44
- '@form8ion/cucumber'
5+
6+
overrides:
7+
- files: example.js
8+
rules:
9+
import/no-extraneous-dependencies: off

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $ npm install @form8ion/remark-plugin-scaffolder --save-prod
3838
```javascript
3939
import {scaffold} from '@form8ion/remark-plugin-scaffolder';
4040

41-
scaffold();
41+
scaffold({projectRoot: process.cwd(), tests: {integration: true}});
4242
```
4343

4444
## Contributing

example.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
// #### Import
2+
// remark-usage-ignore-next
3+
import stubbedFs from 'mock-fs';
14
import {scaffold} from './lib/index.cjs';
25

3-
scaffold();
6+
// remark-usage-ignore-next
7+
stubbedFs();
8+
9+
// #### Execute
10+
11+
scaffold({projectRoot: process.cwd(), tests: {integration: true}});
12+
13+
// remark-usage-ignore-next
14+
stubbedFs.restore();

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"husky": "4.2.5",
6464
"lockfile-lint": "4.2.2",
6565
"mocha": "7.1.1",
66+
"mock-fs": "^4.11.0",
6667
"npm-run-all": "4.1.5",
6768
"nyc": "15.0.1",
6869
"remark-cli": "8.0.0",
@@ -73,5 +74,8 @@
7374
"rollup-plugin-auto-external": "2.0.0",
7475
"sinon": "9.0.2",
7576
"travis-lint": "1.0.0"
77+
},
78+
"dependencies": {
79+
"@form8ion/cucumber-scaffolder": "^1.1.0"
7680
}
7781
}

src/scaffold-test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1+
import any from '@travi/any';
2+
import {assert} from 'chai';
3+
import sinon from 'sinon';
4+
import * as scaffoldTesting from './testing';
15
import scaffold from './scaffold';
26

37
suite('scaffold', () => {
8+
let sandbox;
9+
10+
setup(() => {
11+
sandbox = sinon.createSandbox();
12+
13+
sandbox.stub(scaffoldTesting, 'default');
14+
});
15+
16+
teardown(() => sandbox.restore());
17+
418
test('that the plugin is initialized', async () => {
5-
await scaffold();
19+
const projectRoot = any.string();
20+
const tests = any.simpleObject();
21+
const testingResults = any.simpleObject();
22+
scaffoldTesting.default.withArgs({projectRoot, tests}).resolves(testingResults);
23+
24+
assert.deepEqual(await scaffold({projectRoot, tests}), testingResults);
625
});
726
});

src/scaffold.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
export default function () {
1+
import scaffoldTesting from './testing';
22

3+
export default function ({projectRoot, tests}) {
4+
return scaffoldTesting({projectRoot, tests});
35
}

src/testing-test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as cucumberScaffolder from '@form8ion/cucumber-scaffolder';
2+
import sinon from 'sinon';
3+
import {assert} from 'chai';
4+
import any from '@travi/any';
5+
import scaffoldTesting from './testing';
6+
7+
suite('testing', () => {
8+
let sandbox;
9+
const projectRoot = any.string();
10+
11+
setup(() => {
12+
sandbox = sinon.createSandbox();
13+
14+
sandbox.stub(cucumberScaffolder, 'scaffold');
15+
});
16+
17+
teardown(() => sandbox.restore());
18+
19+
test('that a canary cucumber test is created when the project will be integration tested', async () => {
20+
const cucumberResults = any.simpleObject();
21+
cucumberScaffolder.scaffold
22+
.withArgs({projectRoot})
23+
.returns(cucumberResults);
24+
25+
assert.deepEqual(await scaffoldTesting({projectRoot, tests: {integration: true}}), cucumberResults);
26+
});
27+
28+
test('that no canary test is created when the project will not be integration tested', async () => {
29+
assert.deepEqual(await scaffoldTesting({projectRoot, tests: {integration: false}}), {});
30+
assert.notCalled(cucumberScaffolder.scaffold);
31+
});
32+
});

src/testing.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {scaffold as scaffoldCucumber} from '@form8ion/cucumber-scaffolder';
2+
3+
export default async function ({projectRoot, tests}) {
4+
if (tests.integration) {
5+
return scaffoldCucumber({projectRoot});
6+
}
7+
8+
return {};
9+
}

0 commit comments

Comments
 (0)