-
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: fix-conventional-commit & after-lerna-version-update-lockfile
- Loading branch information
Showing
14 changed files
with
8,315 additions
and
10,775 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"command": {}, | ||
"packages": [ | ||
"packages/*" | ||
], | ||
"version": "1.0.0" | ||
} |
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,5 @@ | ||
{ | ||
"name": "lerna-version", | ||
"version": "1.0.0", | ||
"dependencies": {} | ||
} |
7 changes: 7 additions & 0 deletions
7
__tests__/fixture/lerna-version/packages/normal-a/package.json
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,7 @@ | ||
{ | ||
"name": "normal-a", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"normal-c": "^1.0.0" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
__tests__/fixture/lerna-version/packages/normal-c/package.json
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,4 @@ | ||
{ | ||
"name": "normal-c", | ||
"version": "1.0.0" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
packages: | ||
- 'packages/*' |
114 changes: 114 additions & 0 deletions
114
__tests__/patches/after-lerna-version-update-lockfile.test.js
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,114 @@ | ||
/** | ||
* @file main | ||
* @author imcuttle | ||
* @date 2018/4/4 | ||
*/ | ||
|
||
const { fixture } = require('../helper') | ||
const fs = require('fs') | ||
const cp = require('child_process') | ||
const nps = require('path') | ||
const readYaml = require('read-yaml-file') | ||
|
||
const { getPackagesSync } = require('@lerna/project') | ||
const { gitAdd } = require('@lerna/version/lib/git-add') | ||
const { gitCommit } = require('@lerna/version/lib/git-commit') | ||
const { gitPush } = require('@lerna/version/lib/git-push') | ||
const { gitTag } = require('@lerna/version/lib/git-tag') | ||
|
||
const pnpmBinPath = nps.resolve(__dirname, '../../node_modules/.bin/pnpm') | ||
|
||
jest.mock('@lerna/version/lib/git-add', () => { | ||
return { | ||
gitAdd: jest.fn(() => {}) | ||
} | ||
}) | ||
|
||
jest.mock('@lerna/version/lib/git-push', () => { | ||
return { | ||
gitPush: jest.fn(() => {}) | ||
} | ||
}) | ||
|
||
jest.mock('@lerna/version/lib/git-commit', () => { | ||
return { | ||
gitCommit: jest.fn(() => {}) | ||
} | ||
}) | ||
|
||
jest.mock('@lerna/version/lib/git-tag', () => { | ||
return { | ||
gitTag: jest.fn(() => {}) | ||
} | ||
}) | ||
|
||
describe('lerna patches: after-lerna-version-update-lockfile', function () { | ||
let unpatch | ||
beforeEach(async () => { | ||
gitPush.mockClear() | ||
gitAdd.mockClear() | ||
gitTag.mockClear() | ||
gitCommit.mockClear() | ||
|
||
const pkgs = getPackagesSync(fixture('lerna-version')) | ||
for (const pkg of pkgs) { | ||
pkg.version = '0.0.0' | ||
if (pkg.dependencies) { | ||
pkg.dependencies['normal-c'] = '^0.0.0' | ||
} | ||
await pkg.serialize() | ||
} | ||
|
||
cp.execSync(`echo $PWD && ${pnpmBinPath} i`, { cwd: fixture('lerna-version'), stdio: 'inherit' }) | ||
const lockData = await readYaml(fixture('lerna-version/pnpm-lock.yaml')) | ||
expect(lockData.importers['packages/normal-a'].specifiers['normal-c']).toBe('^0.0.0') | ||
|
||
unpatch = require('../../src/patches/after-lerna-version-update-lockfile')() | ||
}) | ||
afterEach(() => { | ||
unpatch() | ||
}) | ||
|
||
it('spec unpatch', async function () { | ||
unpatch() | ||
const factory = require('@lerna/version') | ||
const versionCmd = factory({ | ||
cwd: fixture('lerna-version'), | ||
forcePublish: true, | ||
bump: '1.0.0', | ||
yes: true | ||
}) | ||
await versionCmd.runner | ||
expect(gitAdd.mock.calls.length).toBe(1) | ||
expect(gitAdd.mock.calls[0][0]).toEqual([ | ||
fixture('lerna-version/packages/normal-c/package.json'), | ||
fixture('lerna-version/packages/normal-a/package.json'), | ||
fixture('lerna-version/lerna.json') | ||
]) | ||
expect(gitAdd.mock.calls[0][2]).toMatchObject({ | ||
cwd: fixture('lerna-version') | ||
}) | ||
}) | ||
|
||
it('spec patched', async function () { | ||
const factory = require('@lerna/version') | ||
const versionCmd = factory({ | ||
cwd: fixture('lerna-version'), | ||
forcePublish: true, | ||
bump: '1.0.0', | ||
yes: true | ||
}) | ||
await versionCmd.runner | ||
|
||
const lockData = await readYaml(fixture('lerna-version/pnpm-lock.yaml')) | ||
expect(lockData.importers['packages/normal-a'].specifiers['normal-c']).toBe('^1.0.0') | ||
|
||
expect(gitAdd.mock.calls.length).toBe(2) | ||
expect(gitAdd.mock.calls[0][0]).toEqual([ | ||
fixture('lerna-version/packages/normal-c/package.json'), | ||
fixture('lerna-version/packages/normal-a/package.json'), | ||
fixture('lerna-version/lerna.json') | ||
]) | ||
expect(gitAdd.mock.calls[1][0]).toEqual([fixture('lerna-version/pnpm-lock.yaml')]) | ||
}) | ||
}) |
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,38 @@ | ||
/** | ||
* @file main | ||
* @author imcuttle | ||
* @date 2018/4/4 | ||
*/ | ||
|
||
describe('lerna patches: fix-conventional-commit', function () { | ||
let unpatch | ||
beforeEach(() => { | ||
unpatch = require('../../src/patches/fix-conventional-commit')() | ||
}) | ||
afterEach(() => { | ||
unpatch() | ||
}) | ||
|
||
it('spec', async function () { | ||
unpatch() | ||
const { getChangelogConfig } = require('@lerna/conventional-commits/lib/get-changelog-config') | ||
const input = { | ||
name: 'conventional-changelog-conventionalcommits' | ||
} | ||
await getChangelogConfig(input, __dirname) | ||
expect(input).not.toEqual({ | ||
name: 'conventional-changelog-conventionalcommits' | ||
}) | ||
}) | ||
|
||
it('spec fixed', async function () { | ||
const input = { | ||
name: 'conventional-changelog-conventionalcommits' | ||
} | ||
const { getChangelogConfig } = require('@lerna/conventional-commits/lib/get-changelog-config') | ||
await getChangelogConfig(input, __dirname) | ||
expect(input).toEqual({ | ||
name: 'conventional-changelog-conventionalcommits' | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.