Skip to content

Commit

Permalink
test(semver): add custom preset e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
edbzn committed Dec 14, 2023
1 parent 2c8c1b1 commit 945c83d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`@jscutlery/semver @jscutlery/semver:version when libs/a changed should generate CHANGELOG.md 1`] = `
"# Changelog
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
# 0.1.0 (yyyy-mm-dd)
### Bug Fixes
* **a:** 🐞 fix bug xxxxxxx
### Features
* **a:** 🚀 new feature xxxxxxx
"
`;

exports[`@jscutlery/semver @jscutlery/semver:version when libs/b changed should generate CHANGELOG.md 1`] = `
"# Changelog
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
## 0.1.0 (yyyy-mm-dd)
### Features
* **b:** 🚀 new feature xxxxxxx
### Bug Fixes
* **b:** 🐞 fix bug xxxxxxx
"
`;
73 changes: 26 additions & 47 deletions packages/semver/src/executors/version/index.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,22 @@ describe('@jscutlery/semver', () => {
testingWorkspace.runNx(
`g @nx/js:lib a --directory=libs --unitTestRunner=none --linter=none --bundler=none --minimal --publishable --importPath=@proj/a`,
);
// Lib b is publishable.
testingWorkspace.runNx(`g @jscutlery/semver:install --projects=a`);
// Lib b is publishable and uses the conventional commits preset.
testingWorkspace.runNx(
`g @nx/js:lib b --directory=libs --unitTestRunner=none --linter=none --bundler=none --minimal --publishable --importPath=@proj/b`,
);
testingWorkspace.runNx(
`g @jscutlery/semver:install --projects=b --preset=conventionalcommits`,
);
// 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,b`);
testingWorkspace.exec(
`
git add .
git commit -m "build: 📦 setup semver"
git commit -m "chore: 🐣 setup workspace" --no-verify
`,
);
});
Expand All @@ -54,6 +51,12 @@ describe('@jscutlery/semver', () => {
/@commitlint\/cli/,
);
});

it('should add custom preset', () => {
expect(readFile(`${testingWorkspace.root}/libs/b/project.json`)).toMatch(
/conventionalcommits/,
);
});
});

describe('@jscutlery/semver:version', () => {
Expand Down Expand Up @@ -99,25 +102,10 @@ describe('@jscutlery/semver', () => {

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 .*
$`),
);
deterministicChangelog(
readFile(`${testingWorkspace.root}/libs/a/CHANGELOG.md`),
),
).toMatchSnapshot();
});
});

Expand Down Expand Up @@ -163,25 +151,10 @@ $`),

it('should generate CHANGELOG.md', () => {
expect(
readFile(`${testingWorkspace.root}/libs/b/CHANGELOG.md`),
).toMatch(
new RegExp(`^# Changelog
This file was generated.*
# 0.1.0 \\(.*\\)
### Bug Fixes
\\* \\*\\*b:\\*\\* 🐞 fix bug .*
### Features
\\* \\*\\*b:\\*\\* 🚀 new feature .*
$`),
);
deterministicChangelog(
readFile(`${testingWorkspace.root}/libs/b/CHANGELOG.md`),
),
).toMatchSnapshot();
});
});

Expand Down Expand Up @@ -241,3 +214,9 @@ function uncommitedChanges(dir: string) {
.filter((line) => line.length !== 0)
);
}

function deterministicChangelog(changelog: string) {
return changelog
.replace(/(\d{4}-\d{2}-\d{2})/g, 'yyyy-mm-dd')
.replace(/([0-9a-f]{7})/g, 'xxxxxxx');
}

0 comments on commit 945c83d

Please sign in to comment.