Skip to content

Commit

Permalink
fix: run husky prepare script instead of husky init
Browse files Browse the repository at this point in the history
  • Loading branch information
allohamora committed Mar 30, 2024
1 parent c519b09 commit 4df55be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions __tests__/categories/js/husky/husky.entrypoint.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import * as npm from 'src/utils/npm';
import * as runCommand from 'src/utils/run-command';
import { husky } from 'src/categories/js/husky/husky.entrypoint';
import { clearMock } from '__tests__/test-utils/clear-mock';

jest.mock('src/utils/npm');
const npmMocked = jest.mocked(npm);

jest.mock('src/utils/run-command');
const runCommandMocked = jest.mocked(runCommand);

beforeEach(() => {
clearMock(npmMocked);
clearMock(runCommandMocked);
});

describe('husky', () => {
Expand All @@ -21,9 +16,15 @@ describe('husky', () => {
expect(npmMocked.installDevelopmentDependencies).toHaveBeenCalledWith('husky');
});

test('should run husky init', async () => {
test('should add husky prepare script', async () => {
await husky();

expect(npmMocked.addScripts).toHaveBeenCalledWith({ name: 'prepare', script: 'husky' });
});

test('should run prepare script', async () => {
await husky();

expect(runCommandMocked.runCommand).toHaveBeenCalledWith('npx husky init');
expect(npmMocked.runScript).toHaveBeenCalledWith('prepare');
});
});
6 changes: 3 additions & 3 deletions src/categories/js/husky/husky.entrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { installDevelopmentDependencies } from 'src/utils/npm';
import { addScripts, installDevelopmentDependencies, runScript } from 'src/utils/npm';
import { PACKAGE_NAME } from './husky.const';
import { runCommand } from 'src/utils/run-command';

export const husky = async () => {
await installDevelopmentDependencies(PACKAGE_NAME);
await runCommand(`npx ${PACKAGE_NAME} init`);
await addScripts({ name: 'prepare', script: PACKAGE_NAME });
await runScript('prepare');
};

0 comments on commit 4df55be

Please sign in to comment.