Skip to content

Commit 7ba468f

Browse files
committed
feat(predicate): determine prettier existence based on config file
1 parent 51e5fc2 commit 7ba468f

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

src/index.js

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

src/tester.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {exists} from '@form8ion/config-file';
2+
3+
export default function test({_}) {
4+
return exists({name: 'prettier', _});
5+
}

src/tester.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {exists} from '@form8ion/config-file';
2+
3+
import {describe, it, vi, expect} from 'vitest';
4+
import {when} from 'vitest-when';
5+
import any from '@travi/any';
6+
7+
import prettierIsPresent from './tester.js';
8+
9+
vi.mock('@form8ion/config-file');
10+
11+
describe('predicate', () => {
12+
const dummyValueToSatisfySchema = any.simpleObject();
13+
14+
it('should return `true` when a config file is present', async () => {
15+
when(exists).calledWith({name: 'prettier', _: dummyValueToSatisfySchema}).thenResolve(true);
16+
17+
expect(await prettierIsPresent({_: dummyValueToSatisfySchema})).toBe(true);
18+
});
19+
20+
it('should return `false` when a config file is not present', async () => {
21+
when(exists).calledWith({name: 'prettier', _: dummyValueToSatisfySchema}).thenResolve(false);
22+
23+
expect(await prettierIsPresent({_: dummyValueToSatisfySchema})).toBe(false);
24+
});
25+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: prettier as form8ion plugin
2+
3+
Scenario: plugin conventions
4+
When the prettier plugin is compared to form8ion plugin conventions
5+
Then the public interface is compatible with the plugin schema
6+
And the output produced by the scaffolder is detectable by the predicate
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {validateOptions, optionsSchemas} from '@form8ion/core';
2+
3+
import {Then, When} from '@cucumber/cucumber';
4+
import assert from 'node:assert';
5+
6+
// eslint-disable-next-line import/no-extraneous-dependencies,import/no-unresolved
7+
import * as plugin from '@form8ion/prettier';
8+
9+
When('the prettier plugin is compared to form8ion plugin conventions', async function () {
10+
await plugin.scaffold({projectRoot: this.projectRoot});
11+
});
12+
13+
Then('the public interface is compatible with the plugin schema', async function () {
14+
validateOptions(optionsSchemas.form8ionPlugin, plugin);
15+
});
16+
17+
Then('the output produced by the scaffolder is detectable by the predicate', async function () {
18+
assert.equal(await plugin.test({projectRoot: this.projectRoot}), true);
19+
});

0 commit comments

Comments
 (0)