Skip to content

Commit

Permalink
fix(semver): pass changelog path
Browse files Browse the repository at this point in the history
  • Loading branch information
edbzn committed Oct 22, 2023
1 parent cd7fa8e commit c07a70a
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 43 deletions.
158 changes: 115 additions & 43 deletions packages/semver/src/executors/version/index.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -102,12 +174,12 @@ This file was generated.*
### Bug Fixes
\\* \\*\\*a:\\*\\* 🐞 fix bug .*
\\* \\*\\*b:\\*\\* 🐞 fix bug .*
### Features
\\* \\*\\*a:\\*\\* 🚀 new feature .*
\\* \\*\\*b:\\*\\* 🚀 new feature .*
$`),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ export function createConventionalCommitStream(
},
},
{ version: newVersion },
/// @ts-expect-error - Partially typed API
{ path: config.projectRoot },
);
}

0 comments on commit c07a70a

Please sign in to comment.