Skip to content

Commit 293fd3d

Browse files
committed
feat(qualify): expose a qualify predicate to enable only using in the context of github workflows
1 parent e28fd5d commit 293fd3d

6 files changed

Lines changed: 55 additions & 9 deletions

File tree

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export {default as scaffold} from './scaffolder/index.js';
22
export * from './lifter/index.js';
3+
export {default as qualify} from './qualifier.js';

src/qualifier.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {test as workflowsConfigured} from '@form8ion/github-workflows-core';
2+
3+
export default function qualify({projectRoot}) {
4+
return workflowsConfigured({projectRoot});
5+
}

src/qualifier.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {test as workflowsConfigured} from '@form8ion/github-workflows-core';
2+
3+
import {describe, it, vi, expect} from 'vitest';
4+
import {when} from 'vitest-when';
5+
import any from '@travi/any';
6+
7+
import qualify from './qualifier.js';
8+
9+
vi.mock('@form8ion/github-workflows-core');
10+
11+
describe('qualifier', () => {
12+
it('should qualify the use of this plugin based on the workflows-core predicate', async () => {
13+
const projectRoot = any.simpleObject();
14+
const workflowsAreConfigured = any.boolean();
15+
when(workflowsConfigured).calledWith({projectRoot}).thenResolve(workflowsAreConfigured);
16+
17+
expect(await qualify({projectRoot})).toEqual(workflowsAreConfigured);
18+
});
19+
});
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
Feature: Verify Workflow
22

33
Scenario: new project
4+
Given the workflows directory exists
45
When the project is scaffolded
56
Then the verification workflow is created
67
And the jobs use "ubuntu-latest" as the runners
78
And the status badge is returned
89

10+
Scenario: new project without github workflows
11+
Given the workflows directory does not exist
12+
When the project is scaffolded
13+
Then the verification workflow is not created
14+
915
Scenario: new project with specific runner preference
10-
Given the project prefers to use the "foo" runner
16+
Given the workflows directory exists
17+
And the project prefers to use the "foo" runner
1118
When the project is scaffolded
1219
Then the verification workflow is created
1320
And the jobs use "foo" as the runners

test/integration/features/step_definitions/ci-steps.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
scaffoldCheckoutStep,
55
scaffoldDependencyInstallationStep,
66
scaffoldNodeSetupStep,
7-
scaffoldVerificationStep,
7+
scaffoldVerificationStep, workflowFileExists,
88
writeWorkflowFile
99
} from '@form8ion/github-workflows-core';
1010

@@ -20,6 +20,14 @@ Before(async function () {
2020
this.injectedJobs = [];
2121
});
2222

23+
Given('the workflows directory exists', async function () {
24+
await fs.mkdir(`${process.cwd()}/.github/workflows`, {recursive: true});
25+
});
26+
27+
Given('the workflows directory does not exist', async function () {
28+
return undefined;
29+
});
30+
2331
Given('a CI workflow exists', async function () {
2432
await fs.mkdir(`${process.cwd()}/.github/workflows`, {recursive: true});
2533

@@ -103,6 +111,10 @@ Then('the verification workflow is created', async function () {
103111
);
104112
});
105113

114+
Then('the verification workflow is not created', async function () {
115+
assert.isFalse(await workflowFileExists({projectRoot: this.projectRoot, name: ciWorkflowName}));
116+
});
117+
106118
Then('the workflow-result job exists', async function () {
107119
const {jobs} = await loadWorkflowFile({projectRoot: this.projectRoot, name: ciWorkflowName});
108120

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as td from 'testdouble';
99
const __dirname = dirname(fileURLToPath(import.meta.url)); // eslint-disable-line no-underscore-dangle
1010
const stubbedNodeModules = stubbedFs.load(resolve(__dirname, '..', '..', '..', '..', 'node_modules'));
1111

12-
let lift, test, scaffold;
12+
let lift, test, scaffold, qualify;
1313

1414
Before(async function () {
1515
this.existingBranches = any.listOf(any.word);
@@ -20,7 +20,7 @@ Before(async function () {
2020
this.jsCore = await td.replaceEsm('@form8ion/javascript-core');
2121

2222
// eslint-disable-next-line import/no-extraneous-dependencies,import/no-unresolved
23-
({lift, test, scaffold} = await import('@form8ion/github-actions-node-ci'));
23+
({lift, test, scaffold, qualify} = await import('@form8ion/github-actions-node-ci'));
2424

2525
stubbedFs({
2626
node_modules: stubbedNodeModules,
@@ -34,11 +34,13 @@ After(function () {
3434
});
3535

3636
When('the project is scaffolded', async function () {
37-
this.results = await scaffold({
38-
projectRoot: this.projectRoot,
39-
vcs: {owner: this.vcsOwner, name: this.vcsName},
40-
...this.preferredRunner && {runner: this.preferredRunner}
41-
});
37+
if (await qualify({projectRoot: this.projectRoot})) {
38+
this.results = await scaffold({
39+
projectRoot: this.projectRoot,
40+
vcs: {owner: this.vcsOwner, name: this.vcsName},
41+
...this.preferredRunner && {runner: this.preferredRunner}
42+
});
43+
}
4244
});
4345

4446
When('the project is lifted', async function () {

0 commit comments

Comments
 (0)