Skip to content

Commit 3849b7b

Browse files
committed
feat(script): generated the script file
1 parent 2a94b15 commit 3849b7b

File tree

6 files changed

+48
-11
lines changed

6 files changed

+48
-11
lines changed

src/canary-test.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/scaffolder-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {promises as fs} from 'fs';
2+
3+
import any from '@travi/any';
4+
import sinon from 'sinon';
5+
import {assert} from 'chai';
6+
7+
import scaffold from './scaffolder';
8+
9+
suite('scaffold script', () => {
10+
let sandbox;
11+
12+
setup(() => {
13+
sandbox = sinon.createSandbox();
14+
15+
sandbox.stub(fs, 'writeFile');
16+
});
17+
18+
teardown(() => sandbox.restore());
19+
20+
test('that the script is scaffolded', async () => {
21+
const projectRoot = any.string();
22+
23+
await scaffold({projectRoot});
24+
25+
assert.calledWith(fs.writeFile, `${projectRoot}/script.js`, 'export async function script(octokit, repository) {}');
26+
});
27+
});

src/scaffolder.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
export default function () {
2-
return undefined;
1+
import {promises as fs} from 'fs';
2+
3+
export default function ({projectRoot}) {
4+
return fs.writeFile(`${projectRoot}/script.js`, 'export async function script(octokit, repository) {}');
35
}

test/integration/features/scaffolder.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Feature: Scaffolder
22

33
Scenario: Scaffold
44
When the project is scaffolded
5+
Then the script file is bootstrapped

test/integration/features/step_definitions/common-steps.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import {dirname, resolve} from 'node:path';
22
import {fileURLToPath} from 'node:url';
33

4-
import {After, When} from '@cucumber/cucumber';
4+
import {After, Before, When} from '@cucumber/cucumber';
55
import stubbedFs from 'mock-fs';
66

77
const __dirname = dirname(fileURLToPath(import.meta.url));
88
const stubbedNodeModules = stubbedFs.load(resolve(__dirname, '..', '..', '..', '..', 'node_modules'));
99

10+
Before(function () {
11+
this.projectRoot = process.cwd();
12+
})
13+
1014
After(function () {
1115
stubbedFs.restore();
1216
});
@@ -19,5 +23,5 @@ When('the project is scaffolded', async function () {
1923
node_modules: stubbedNodeModules
2024
});
2125

22-
await scaffold({projectRoot: process.cwd()});
26+
await scaffold({projectRoot: this.projectRoot});
2327
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {promises as fs} from 'fs';
2+
3+
import {Then} from '@cucumber/cucumber';
4+
import {assert} from 'chai';
5+
6+
Then('the script file is bootstrapped', async function () {
7+
const scriptContent = await fs.readFile(`${this.projectRoot}/script.js`, 'utf-8');
8+
9+
assert.equal(scriptContent, `export async function script(octokit, repository) {}`);
10+
});

0 commit comments

Comments
 (0)