From c07a70a71fb66bcddb19ac9c67697753e61033f9 Mon Sep 17 00:00:00 2001 From: Edouard Bozon Date: Sun, 22 Oct 2023 12:04:41 +0200 Subject: [PATCH] fix(semver): pass changelog path --- .../src/executors/version/index.e2e.spec.ts | 158 +++++++++++++----- .../version/utils/conventional-commit.ts | 2 + 2 files changed, 117 insertions(+), 43 deletions(-) diff --git a/packages/semver/src/executors/version/index.e2e.spec.ts b/packages/semver/src/executors/version/index.e2e.spec.ts index 51735dc65..9822a14c5 100644 --- a/packages/semver/src/executors/version/index.e2e.spec.ts +++ b/packages/semver/src/executors/version/index.e2e.spec.ts @@ -5,93 +5,165 @@ import { readFileSync, existsSync } from 'fs'; describe('@jscutlery/semver', () => { let testingWorkspace: TestingWorkspace; - describe('package "a"', () => { - beforeAll(() => { - testingWorkspace = setupTestingWorkspace(); - testingWorkspace.runNx( - `g @nx/js:lib a --directory=libs --unitTestRunner=none --linter=none --bundler=none --minimal --publishable --importPath=@proj/a`, - ); - testingWorkspace.exec( - ` + beforeAll(() => { + testingWorkspace = setupTestingWorkspace(); + testingWorkspace.runNx( + `g @nx/js:lib a --directory=libs --unitTestRunner=none --linter=none --bundler=none --minimal --publishable --importPath=@proj/a`, + ); + testingWorkspace.runNx( + `g @nx/js:lib b --directory=libs --unitTestRunner=none --linter=none --bundler=none --minimal --publishable --importPath=@proj/b`, + ); + // Lib c is not publishable. + testingWorkspace.runNx( + `g @nx/js:lib c --directory=libs --unitTestRunner=none --linter=none --bundler=none --minimal`, + ); + testingWorkspace.exec( + ` git add . git commit -m "🐣" - `, - ); - testingWorkspace.runNx(`g @jscutlery/semver:install --projects=a`); - testingWorkspace.exec( - ` + `, + ); + testingWorkspace.runNx(`g @jscutlery/semver:install --projects=a,b`); + testingWorkspace.exec( + ` git add . git commit -m "build: 📦 setup semver" - `, + `, + ); + }); + + afterAll(() => testingWorkspace.tearDown()); + + describe('@jscutlery/semver:install', () => { + it('should add commitlint config', () => { + expect(existsSync(`${testingWorkspace.root}/.commitlintrc.json`)).toBe( + true, ); }); - afterAll(() => testingWorkspace.tearDown()); + it('should add commitlint config', () => { + expect(readFile(`${testingWorkspace.root}/package.json`)).toMatch( + /@commitlint\/config-angular/, + ); + }); - describe('@jscutlery/semver:install', () => { + it('should add commitlint CLI', () => { + expect(readFile(`${testingWorkspace.root}/package.json`)).toMatch( + /@commitlint\/cli/, + ); + }); + }); + + describe('@jscutlery/semver:version', () => { + describe('when libs/a changed', () => { beforeAll(() => { testingWorkspace.exec( ` - echo feat > libs/a/a.txt - git add . - git commit -m "feat(a): 🚀 new feature" - - echo fix >> libs/a/a.txt - git add . - git commit -m "fix(a): 🐞 fix bug" - `, + echo feat > libs/a/a.txt + git add . + git commit -m "feat(a): 🚀 new feature" + + echo fix >> libs/a/a.txt + git add . + git commit -m "fix(a): 🐞 fix bug" + `, ); // @TODO: Remove --noVerify when "release" commit type is allowed by commitlint. testingWorkspace.runNx(`run a:version --noVerify`); }); - it('should add commitlint config', () => { - expect(existsSync(`${testingWorkspace.root}/.commitlintrc.json`)).toBe( - true, - ); + it('should commit all changes', () => { + expect(uncommitedChanges(testingWorkspace.root)).toHaveLength(0); }); - it('should add commitlint config', () => { - expect(readFile(`${testingWorkspace.root}/package.json`)).toMatch( - /@commitlint\/config-angular/, + it('should tag with version', () => { + expect(getLastTag(testingWorkspace.root)).toBe('a-0.1.0'); + }); + + it('should create only one tag', () => { + expect(getTags(testingWorkspace.root)).toHaveLength(1); + }); + + it('should commit with description', () => { + expect(getLastCommitDescription(testingWorkspace.root)).toBe( + 'chore(a): release version 0.1.0', ); }); - it('should add commitlint CLI', () => { - expect(readFile(`${testingWorkspace.root}/package.json`)).toMatch( - /@commitlint\/cli/, + it('should bump package version', () => { + expect( + readFile(`${testingWorkspace.root}/libs/a/package.json`), + ).toMatch(/"version": "0.1.0"/); + }); + + it('should generate CHANGELOG.md', () => { + expect( + readFile(`${testingWorkspace.root}/libs/a/CHANGELOG.md`), + ).toMatch( + new RegExp(`^# Changelog + +This file was generated.* + +# 0.1.0 \\(.*\\) + + +### Bug Fixes + +\\* \\*\\*a:\\*\\* 🐞 fix bug .* + + +### Features + +\\* \\*\\*a:\\*\\* 🚀 new feature .* +$`), ); }); }); - describe('@jscutlery/semver:version', () => { + describe('when libs/b changed', () => { + beforeAll(() => { + testingWorkspace.exec( + ` + echo feat > libs/b/b.txt + git add . + git commit -m "feat(b): 🚀 new feature" + + echo fix >> libs/b/b.txt + git add . + git commit -m "fix(b): 🐞 fix bug" + `, + ); + // @TODO: Remove --noVerify when "release" commit type is allowed by commitlint. + testingWorkspace.runNx(`run b:version --noVerify`); + }); + it('should commit all changes', () => { expect(uncommitedChanges(testingWorkspace.root)).toHaveLength(0); }); it('should tag with version', () => { - expect(getLastTag(testingWorkspace.root)).toBe('a-0.1.0'); + expect(getLastTag(testingWorkspace.root)).toBe('b-0.1.0'); }); - it('should create only one tag', () => { - expect(getTags(testingWorkspace.root)).toHaveLength(1); + it('should create second tag', () => { + expect(getTags(testingWorkspace.root)).toHaveLength(2); }); it('should commit with description', () => { expect(getLastCommitDescription(testingWorkspace.root)).toBe( - 'chore(a): release version 0.1.0', + 'chore(b): release version 0.1.0', ); }); it('should bump package version', () => { expect( - readFile(`${testingWorkspace.root}/libs/a/package.json`), + readFile(`${testingWorkspace.root}/libs/b/package.json`), ).toMatch(/"version": "0.1.0"/); }); it('should generate CHANGELOG.md', () => { expect( - readFile(`${testingWorkspace.root}/libs/a/CHANGELOG.md`), + readFile(`${testingWorkspace.root}/libs/b/CHANGELOG.md`), ).toMatch( new RegExp(`^# Changelog @@ -102,12 +174,12 @@ This file was generated.* ### Bug Fixes -\\* \\*\\*a:\\*\\* 🐞 fix bug .* +\\* \\*\\*b:\\*\\* 🐞 fix bug .* ### Features -\\* \\*\\*a:\\*\\* 🚀 new feature .* +\\* \\*\\*b:\\*\\* 🚀 new feature .* $`), ); }); diff --git a/packages/semver/src/executors/version/utils/conventional-commit.ts b/packages/semver/src/executors/version/utils/conventional-commit.ts index 2d9cca92e..f16daef44 100644 --- a/packages/semver/src/executors/version/utils/conventional-commit.ts +++ b/packages/semver/src/executors/version/utils/conventional-commit.ts @@ -15,5 +15,7 @@ export function createConventionalCommitStream( }, }, { version: newVersion }, + /// @ts-expect-error - Partially typed API + { path: config.projectRoot }, ); }