Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.

Commit

Permalink
refactor(husky): applied the husky enhancer in the list rather than s…
Browse files Browse the repository at this point in the history
…eparately
  • Loading branch information
travi committed Nov 29, 2021
1 parent 9ace0ed commit d539640
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
32 changes: 32 additions & 0 deletions src/enhancers/enhanced-enhancers-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as huskyLifter from '@form8ion/husky';

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

import {enhanceHuskyEnhancer} from './enhanced-enhancers';

suite('enhanced enhancers', () => {
let sandbox;

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

sandbox.stub(huskyLifter, 'lift');
});

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

test('that the package manager is passed to the husky enhancer', async () => {
const packageManager = any.word();
const results = any.simpleObject();
const projectRoot = any.string();
const huskyLiftResults = any.simpleObject();
huskyLifter.lift.withArgs({projectRoot, packageManager, results}).resolves(huskyLiftResults);

const enhancedHuskyEnhancer = enhanceHuskyEnhancer(packageManager);

assert.equal(await enhancedHuskyEnhancer.lift({results, projectRoot}), huskyLiftResults);
assert.equal(enhancedHuskyEnhancer.test, huskyLifter.test);
});
});
8 changes: 8 additions & 0 deletions src/enhancers/enhanced-enhancers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {lift as liftHusky, test as liftPredicate} from '@form8ion/husky';

export function enhanceHuskyEnhancer(packageManager) {
return {
test: liftPredicate,
lift: ({projectRoot, results}) => liftHusky({projectRoot, results, packageManager})
};
}
13 changes: 7 additions & 6 deletions src/lift-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as huskyLifter from '@form8ion/husky';
import * as eslint from '@form8ion/eslint';
import deepmerge from 'deepmerge';

Expand All @@ -8,6 +7,7 @@ import {assert} from 'chai';

import * as enhancers from './enhancers/apply';
import * as enginesEnhancer from './enhancers/engines';
import * as enhancedEnhancers from './enhancers/enhanced-enhancers';
import * as packageLifter from './package';
import * as packageManagerResolver from './package-manager';
import lift from './lift';
Expand All @@ -31,29 +31,31 @@ suite('lift', () => {
devDependencies,
packageManager: manager
};
const huskyLiftResults = {};

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

sandbox.stub(packageLifter, 'default');
sandbox.stub(eslint, 'lift');
sandbox.stub(packageManagerResolver, 'default');
sandbox.stub(huskyLifter, 'lift');
sandbox.stub(enhancers, 'default');
sandbox.stub(enhancedEnhancers, 'enhanceHuskyEnhancer');

huskyLifter.lift.withArgs({projectRoot, packageManager}).resolves(huskyLiftResults);
packageManagerResolver.default.withArgs({projectRoot, packageManager: manager}).resolves(packageManager);
});

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

test('that results specific to js projects are lifted', async () => {
const scope = any.word();
const enhancedHuskyEnhancer = () => undefined;
const eslintLiftResults = {...any.simpleObject(), devDependencies: any.listOf(any.word)};
const enhancerResults = any.simpleObject();
eslint.lift.withArgs({configs: eslintConfigs, projectRoot}).resolves(eslintLiftResults);
enhancers.default.withArgs({results, enhancers: [enginesEnhancer], projectRoot}).resolves(enhancerResults);
enhancedEnhancers.enhanceHuskyEnhancer.withArgs(packageManager).returns(enhancedHuskyEnhancer);
enhancers.default
.withArgs({results, enhancers: [enhancedHuskyEnhancer, enginesEnhancer], projectRoot})
.resolves(enhancerResults);

const liftResults = await lift({projectRoot, results, configs: {eslint: {scope}}});

Expand All @@ -62,7 +64,6 @@ suite('lift', () => {
packageLifter.default,
deepmerge.all([
{projectRoot, scripts, tags, dependencies, devDependencies, packageManager},
huskyLiftResults,
eslintLiftResults,
enhancerResults
])
Expand Down
10 changes: 6 additions & 4 deletions src/lift.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import deepmerge from 'deepmerge';
import {info} from '@travi/cli-messages';
import {lift as liftHusky} from '@form8ion/husky';
import {lift as liftEslint} from '@form8ion/eslint';

import applyEnhancers from './enhancers/apply';
import * as enginesEnhancer from './enhancers/engines';
import liftPackage from './package';
import resolvePackageManager from './package-manager';
import {enhanceHuskyEnhancer} from './enhancers/enhanced-enhancers';

export default async function ({projectRoot, results}) {
info('Lifting JavaScript-specific details');
Expand All @@ -15,15 +15,17 @@ export default async function ({projectRoot, results}) {

const packageManager = await resolvePackageManager({projectRoot, packageManager: manager});

const huskyResults = await liftHusky({projectRoot, packageManager});
const eslintResults = await liftEslint({projectRoot, configs: eslintConfigs});
const enhancerResults = await applyEnhancers({results, enhancers: [enginesEnhancer], projectRoot});
const enhancerResults = await applyEnhancers({
results,
enhancers: [enhanceHuskyEnhancer(packageManager), enginesEnhancer],
projectRoot
});

await liftPackage(
deepmerge.all([
{projectRoot, scripts, tags, dependencies, devDependencies, packageManager},
enhancerResults,
huskyResults,
eslintResults
])
);
Expand Down

0 comments on commit d539640

Please sign in to comment.