Skip to content

Commit

Permalink
chore(release): add e2e case for conventional-commits
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed Sep 27, 2023
1 parent 3e859cd commit f78364d
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions e2e/release/src/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
updateJson,
} from '@nx/e2e/utils';
import { execSync } from 'child_process';
import { writeFileSync } from 'fs';
import { join } from 'path';

expect.addSnapshotSerializer({
serialize(str: string) {
Expand Down Expand Up @@ -618,5 +620,82 @@ describe('nx release', () => {
/Applying new version 1100.1.0 to 1 package which depends on my-pkg-\d*/g
).length
).toEqual(1);

writeFileSync(
join(tmpProjPath(), `${pkg1}/my-file.txt`),
'update for conventional-commits testing'
);

// Add custom nx release config to control version resolution
updateJson<NxJsonConfiguration>('nx.json', (nxJson) => {
nxJson.release = {
groups: {
default: {
// @proj/source will be added as a project by the verdaccio setup, but we aren't versioning or publishing it, so we exclude it here
projects: ['*', '!@proj/source'],
version: {
specifierSource: 'conventional-commits',
generator: '@nx/js:release-version',
generatorOptions: {
// Resolve the latest version from the git tag
currentVersionResolver: 'git-tag',
currentVersionResolverMetadata: {
tagVersionPrefix: 'xx',
},
},
},
},
},
};
return nxJson;
});

const versionOutput4 = runCLI(`release version`);

expect(
versionOutput4.match(/Running release version for project: my-pkg-\d*/g)
.length
).toEqual(3);
expect(
versionOutput4.match(
/Reading data for package "@proj\/my-pkg-\d*" from my-pkg-\d*\/package.json/g
).length
).toEqual(3);

// It should resolve the current version from the registry once...
expect(
versionOutput4.match(
new RegExp(
`Resolved the current version as 1100.0.0 from git tag "xx1100.0.0"`,
'g'
)
).length
).toEqual(1);
// ...and then reuse it twice
expect(
versionOutput4.match(
new RegExp(
`Using the current version 1100.0.0 already resolved from git tag "xx1100.0.0"`,
'g'
)
).length
).toEqual(2);

expect(versionOutput4.match(/Skipping versioning/g).length).toEqual(3);

execSync(
`git add ${pkg1}/my-file.txt && git commit -m "feat!: add new file"`,
{
cwd: tmpProjPath(),
}
);

const versionOutput5 = runCLI(`release version`);

expect(
versionOutput5.match(
/New version 1101.0.0 written to my-pkg-\d*\/package.json/g
).length
).toEqual(3);
}, 500000);
});

0 comments on commit f78364d

Please sign in to comment.