This repository has been archived by the owner on Dec 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(husky): reported a next-step when using v4 config with v5
to prepare to automatically upgrade the config
- Loading branch information
Showing
13 changed files
with
230 additions
and
17 deletions.
There are no files selected for viewing
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,69 @@ | ||
import * as core from '@form8ion/core'; | ||
import {assert} from 'chai'; | ||
import sinon from 'sinon'; | ||
import any from '@travi/any'; | ||
import * as execa from '../thirdparty-wrappers/execa'; | ||
import liftHusky from './husky'; | ||
|
||
suite('husky', () => { | ||
let sandbox; | ||
const projectRoot = any.string(); | ||
|
||
setup(() => { | ||
sandbox = sinon.createSandbox(); | ||
|
||
sandbox.stub(core, 'fileExists'); | ||
sandbox.stub(execa, 'default'); | ||
}); | ||
|
||
teardown(() => sandbox.restore()); | ||
|
||
test('that a next-step is listed when v5 is installed, but config is still for v4', async () => { | ||
core.fileExists.withArgs(`${projectRoot}/.huskyrc.json`).resolves(true); | ||
execa.default | ||
.withArgs('npm', ['ls', 'husky', '--json']) | ||
.resolves(JSON.stringify({dependencies: {husky: {version: '5.0.0'}}})); | ||
|
||
assert.deepEqual( | ||
await liftHusky({projectRoot}), | ||
{nextSteps: [{summary: 'Husky configuration is outdated for the installed Husky version'}]} | ||
); | ||
}); | ||
|
||
test('that a next-step is listed when greater than v5 is installed, but config is still for v4', async () => { | ||
core.fileExists.withArgs(`${projectRoot}/.huskyrc.json`).resolves(true); | ||
execa.default | ||
.withArgs('npm', ['ls', 'husky', '--json']) | ||
.resolves(JSON.stringify({dependencies: {husky: {version: '5.0.1'}}})); | ||
|
||
assert.deepEqual( | ||
await liftHusky({projectRoot}), | ||
{nextSteps: [{summary: 'Husky configuration is outdated for the installed Husky version'}]} | ||
); | ||
}); | ||
|
||
test('that no next-step is listed when v4 is installed', async () => { | ||
core.fileExists.withArgs(`${projectRoot}/.huskyrc.json`).resolves(true); | ||
execa.default | ||
.withArgs('npm', ['ls', 'husky', '--json']) | ||
.resolves(JSON.stringify({dependencies: {husky: {version: '4.5.6'}}})); | ||
|
||
assert.deepEqual(await liftHusky({projectRoot}), {}); | ||
}); | ||
|
||
test('that no next-step is listed when v5 is installed and v5 config exists', async () => { | ||
execa.default | ||
.withArgs('npm', ['ls', 'husky', '--json']) | ||
.resolves(JSON.stringify({dependencies: {husky: {version: '5.6.7'}}})); | ||
core.fileExists.resolves(false); | ||
|
||
assert.deepEqual(await liftHusky({projectRoot}), {}); | ||
}); | ||
|
||
test('that not having husky installed does not result in an error', async () => { | ||
execa.default.withArgs('npm', ['ls', 'husky', '--json']).resolves(JSON.stringify({})); | ||
core.fileExists.resolves(any.boolean()); | ||
|
||
await liftHusky({projectRoot}); | ||
}); | ||
}); |
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,18 @@ | ||
import semver from 'semver'; | ||
import {fileExists} from '@form8ion/core'; | ||
import execa from '../thirdparty-wrappers/execa'; | ||
|
||
export default async function ({projectRoot}) { | ||
const [huskyVersionDetails, huskyV4ConfigExists] = await Promise.all([ | ||
await execa('npm', ['ls', 'husky', '--json']), | ||
await fileExists(`${projectRoot}/.huskyrc.json`) | ||
]); | ||
|
||
const {dependencies} = JSON.parse(huskyVersionDetails); | ||
|
||
if (dependencies && semver.gte(dependencies.husky.version, '5.0.0') && huskyV4ConfigExists) { | ||
return {nextSteps: [{summary: 'Husky configuration is outdated for the installed Husky version'}]}; | ||
} | ||
|
||
return {}; | ||
} |
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
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,19 @@ | ||
Feature: Husky | ||
|
||
Scenario: Husky v5 installed, v4 config | ||
Given husky v5 is installed | ||
And husky config is in v4 format | ||
When the scaffolder results are processed | ||
Then the next-steps include a warning about the husky config | ||
|
||
Scenario: Husky v5 installed, v5 config | ||
Given husky v5 is installed | ||
And husky config is in v5 format | ||
When the scaffolder results are processed | ||
Then the next-steps do not include a warning about the husky config | ||
|
||
Scenario: Husky v4 installed, v4 config | ||
Given husky v4 is installed | ||
And husky config is in v4 format | ||
When the scaffolder results are processed | ||
Then the next-steps do not include a warning about the husky config |
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
Oops, something went wrong.