Skip to content

Commit

Permalink
feat: fix-conventional-commit & after-lerna-version-update-lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
imcuttle committed Jan 20, 2022
1 parent 19e4c28 commit b62871e
Show file tree
Hide file tree
Showing 14 changed files with 8,315 additions and 10,775 deletions.
7 changes: 7 additions & 0 deletions __tests__/fixture/lerna-version/lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"command": {},
"packages": [
"packages/*"
],
"version": "1.0.0"
}
5 changes: 5 additions & 0 deletions __tests__/fixture/lerna-version/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "lerna-version",
"version": "1.0.0",
"dependencies": {}
}
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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "normal-c",
"version": "1.0.0"
}
11 changes: 11 additions & 0 deletions __tests__/fixture/lerna-version/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions __tests__/fixture/lerna-version/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages:
- 'packages/*'
114 changes: 114 additions & 0 deletions __tests__/patches/after-lerna-version-update-lockfile.test.js
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')])
})
})
38 changes: 38 additions & 0 deletions __tests__/patches/fix-conventional-commit.test.js
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'
})
})
})
Loading

0 comments on commit b62871e

Please sign in to comment.