Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# octoherd-script

form8ion plugin to manage script projects for octoherd
[form8ion](https://github.com/form8ion) plugin to manage script projects for
[octoherd](https://github.com/octoherd)

<!--status-badges start -->

Expand Down
7 changes: 0 additions & 7 deletions src/canary-test.js

This file was deleted.

28 changes: 28 additions & 0 deletions src/scaffolder-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {promises as fs} from 'fs';

import any from '@travi/any';
import sinon from 'sinon';
import {assert} from 'chai';

import scaffold from './scaffolder';

suite('scaffold script', () => {
let sandbox;

setup(() => {
sandbox = sinon.createSandbox();

sandbox.stub(fs, 'writeFile');
});

teardown(() => sandbox.restore());

test('that the script is scaffolded', async () => {
const projectRoot = any.string();

const {tags} = await scaffold({projectRoot});

assert.calledWith(fs.writeFile, `${projectRoot}/index.js`, 'export async function script(octokit, repository) {}');
assert.deepEqual(tags, ['octoherd-script']);
});
});
8 changes: 6 additions & 2 deletions src/scaffolder.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export default function () {
return undefined;
import {promises as fs} from 'fs';

export default async function ({projectRoot}) {
await fs.writeFile(`${projectRoot}/index.js`, 'export async function script(octokit, repository) {}');

return {tags: ['octoherd-script']};
}
2 changes: 2 additions & 0 deletions test/integration/features/scaffolder.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ Feature: Scaffolder

Scenario: Scaffold
When the project is scaffolded
Then the script file is bootstrapped
And project metadata is generated
8 changes: 6 additions & 2 deletions test/integration/features/step_definitions/common-steps.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import {dirname, resolve} from 'node:path';
import {fileURLToPath} from 'node:url';

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

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

Before(function () {
this.projectRoot = process.cwd();
})

After(function () {
stubbedFs.restore();
});
Expand All @@ -19,5 +23,5 @@ When('the project is scaffolded', async function () {
node_modules: stubbedNodeModules
});

await scaffold({projectRoot: process.cwd()});
this.result = await scaffold({projectRoot: this.projectRoot});
});
8 changes: 8 additions & 0 deletions test/integration/features/step_definitions/metadata-steps.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {Then} from '@cucumber/cucumber';
import {assert} from 'chai';

Then('project metadata is generated', async function () {
const {tags} = this.result;

assert.deepEqual(tags, ['octoherd-script']);
});
10 changes: 10 additions & 0 deletions test/integration/features/step_definitions/script-steps.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {promises as fs} from 'fs';

import {Then} from '@cucumber/cucumber';
import {assert} from 'chai';

Then('the script file is bootstrapped', async function () {
const scriptContent = await fs.readFile(`${this.projectRoot}/index.js`, 'utf-8');

assert.equal(scriptContent, `export async function script(octokit, repository) {}`);
});