-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(husky): warned about usage of legacy hook definitions
- Loading branch information
Showing
6 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
extends: | ||
- '@form8ion' | ||
- '@form8ion/mocha' | ||
- '@form8ion/mocha' | ||
|
||
overrides: | ||
- files: example.js | ||
rules: | ||
import/no-extraneous-dependencies: off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
// #### Import | ||
// remark-usage-ignore-next | ||
import stubbedFs from 'mock-fs'; | ||
import {patrol} from './lib/index.cjs'; | ||
|
||
// remark-usage-ignore-next | ||
stubbedFs(); | ||
|
||
(async () => { | ||
await patrol(); | ||
// remark-usage-ignore-next | ||
stubbedFs.restore(); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {promises as fs} from 'fs'; | ||
import * as cliMessages from '@travi/cli-messages'; | ||
import sinon from 'sinon'; | ||
import {assert} from 'chai'; | ||
import any from '@travi/any'; | ||
import husky from './husky'; | ||
|
||
suite('husky', () => { | ||
let sandbox; | ||
|
||
setup(() => { | ||
sandbox = sinon.createSandbox(); | ||
|
||
sandbox.stub(fs, 'readFile'); | ||
sandbox.stub(cliMessages, 'warn'); | ||
}); | ||
|
||
teardown(() => sandbox.restore()); | ||
|
||
test('that no problem is reported when the legacy hooks are not used', async () => { | ||
const projectRoot = any.string(); | ||
fs.readFile | ||
.withArgs(`${projectRoot}/package.json`, 'utf8') | ||
.resolves(JSON.stringify({scripts: any.simpleObject()})); | ||
|
||
await husky(projectRoot); | ||
|
||
assert.notCalled(cliMessages.warn); | ||
}); | ||
|
||
test('that a warning is provided if a legacy `precommit` hook is defined', async () => { | ||
const projectRoot = any.string(); | ||
fs.readFile | ||
.withArgs(`${projectRoot}/package.json`, 'utf8') | ||
.resolves(JSON.stringify({scripts: {precommit: any.sentence()}})); | ||
|
||
await husky(projectRoot); | ||
|
||
assert.calledWith(cliMessages.warn, '`precommit` npm script found. This approach has been deprecated by `husky`'); | ||
assert.neverCalledWith( | ||
cliMessages.warn, | ||
'`commitmsg` npm script found. This approach has been deprecated by `husky`' | ||
); | ||
}); | ||
|
||
test('that a warning is provided if a legacy `commitmsg` hook is defined', async () => { | ||
const projectRoot = any.string(); | ||
fs.readFile | ||
.withArgs(`${projectRoot}/package.json`, 'utf8') | ||
.resolves(JSON.stringify({scripts: {commitmsg: any.sentence()}})); | ||
|
||
await husky(projectRoot); | ||
|
||
assert.neverCalledWith( | ||
cliMessages.warn, | ||
'`precommit` npm script found. This approach has been deprecated by `husky`' | ||
); | ||
assert.calledWith(cliMessages.warn, '`commitmsg` npm script found. This approach has been deprecated by `husky`'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export default function () { | ||
import {promises as fs} from 'fs'; | ||
import {warn} from '@travi/cli-messages'; | ||
|
||
export default async function (projectRoot) { | ||
const {scripts} = JSON.parse(await fs.readFile(`${projectRoot}/package.json`, 'utf8')); | ||
|
||
if (scripts.precommit) warn('`precommit` npm script found. This approach has been deprecated by `husky`'); | ||
if (scripts.commitmsg) warn('`commitmsg` npm script found. This approach has been deprecated by `husky`'); | ||
} |