Skip to content

Commit

Permalink
Merge pull request #26 from ghiscoding/chore/unit-test-part2
Browse files Browse the repository at this point in the history
fix(version): add missing code conventional-preset legacy loading
  • Loading branch information
ghiscoding committed Feb 16, 2022
2 parents 5dad704 + b377c68 commit b897936
Show file tree
Hide file tree
Showing 49 changed files with 1,232 additions and 8 deletions.
9 changes: 9 additions & 0 deletions helpers/git-checkout/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

const execa = require("execa");

module.exports.gitCheckout = gitCheckout;

function gitCheckout(cwd, args) {
return execa("git", ["checkout", ...args], { cwd });
}
11 changes: 11 additions & 0 deletions helpers/git-checkout/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@lerna-test/git-checkout",
"version": "0.0.0-test-only",
"description": "A local test helper",
"main": "index.js",
"private": true,
"license": "MIT",
"dependencies": {
"execa": "^5.0.0"
}
}
9 changes: 9 additions & 0 deletions helpers/git-merge/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

const execa = require("execa");

module.exports.gitMerge = gitMerge;

function gitMerge(cwd, args) {
return execa("git", ["merge", ...args], { cwd });
}
11 changes: 11 additions & 0 deletions helpers/git-merge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@lerna-test/git-merge",
"version": "0.0.0-test-only",
"description": "A local test helper",
"main": "index.js",
"private": true,
"license": "MIT",
"dependencies": {
"execa": "^5.0.0"
}
}
9 changes: 9 additions & 0 deletions helpers/git-status/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

const cp = require("child_process");

module.exports.gitStatus = gitStatus;

function gitStatus(cwd) {
return cp.spawnSync("git", ["status", "--porcelain"], { cwd, encoding: "utf8" });
}
11 changes: 11 additions & 0 deletions helpers/git-status/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@lerna-test/git-status",
"version": "0.0.0-test-only",
"description": "A local test helper",
"main": "index.js",
"private": true,
"license": "MIT",
"dependencies": {
"execa": "^5.0.0"
}
}
9 changes: 9 additions & 0 deletions helpers/git-tag/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

const execa = require("execa");

module.exports.gitTag = gitTag;

function gitTag(cwd, tagName) {
return execa("git", ["tag", tagName, "-m", tagName], { cwd });
}
11 changes: 11 additions & 0 deletions helpers/git-tag/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@lerna-test/git-tag",
"version": "0.0.0-test-only",
"description": "A local test helper",
"main": "index.js",
"private": true,
"license": "MIT",
"dependencies": {
"execa": "^5.0.0"
}
}
18 changes: 18 additions & 0 deletions helpers/serialize-changelog/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";

const normalizeNewline = require("normalize-newline");
const gitSHA = require("../serialize-git-sha");

// expect.addSnapshotSerializer(require("@lerna-test/serialize-changelog"));
module.exports = {
serialize(str) {
return gitSHA
.serialize(normalizeNewline(str))
.replace(/(\[.*?\])\(.*\/compare\/(.*?)\)/g, "$1(/compare/$2)")
.replace(/(\[.*?\])\(.*\/commits\/GIT_HEAD\)/g, "$1(COMMIT_URL)")
.replace(/\(\d{4}-\d{2}-\d{2}\)/g, "(YYYY-MM-DD)");
},
test(val) {
return val != null && typeof val === "string";
},
};
12 changes: 12 additions & 0 deletions helpers/serialize-changelog/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@lerna-test/serialize-changelog",
"version": "0.0.0-test-only",
"description": "A local test helper",
"main": "index.js",
"private": true,
"license": "MIT",
"dependencies": {
"@lerna-test/serialize-git-sha": "file:../serialize-git-sha",
"normalize-newline": "^3.0.0"
}
}
17 changes: 17 additions & 0 deletions helpers/serialize-git-sha/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

// expect.addSnapshotSerializer(require("@lerna-test/serialize-git-sha"));
module.exports = {
serialize(str) {
return (
str
// short SHA tends to be in the path diff comparisons
.replace(/\b[0-9a-f]{7,8}\b/g, "SHA")
// full SHA corresponds to gitHead property in package.json files
.replace(/\b[0-9a-f]{40}\b/g, "GIT_HEAD")
);
},
test(val) {
return val != null && typeof val === "string" && /[0-9a-f]{7,40}/.test(val);
},
};
9 changes: 9 additions & 0 deletions helpers/serialize-git-sha/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@lerna-test/serialize-git-sha",
"version": "0.0.0-test-only",
"description": "A local test helper",
"main": "index.js",
"private": true,
"license": "MIT",
"dependencies": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"command": {
"publish": {
"conventionalCommits": true
}
},
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "changelog-missing",
"repository": "lerna/changelog-missing",
"version": "0.0.0-root"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "package-1",
"repository": "lerna/changelog-missing",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "package-2",
"repository": "lerna/changelog-missing",
"version": "1.0.0",
"dependencies": {
"package-1": "^1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

<a name="1.0.0"></a>

# 1.0.0 (YYYY-MM-DD)

### Features

* I should be placed in the CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"command": {
"publish": {
"conventionalCommits": true
}
},
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "conventional-commits-fixed",
"repository": "lerna/conventional-commits-fixed",
"version": "0.0.0-root"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

<a name="1.0.0"></a>

# 1.0.0 (YYYY-MM-DD)

### Features

* I should be placed in the CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "package-1",
"repository": "lerna/conventional-commits-fixed",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

<a name="1.0.0"></a>

# 1.0.0 (YYYY-MM-DD)

### Features

* I should be placed in the CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "package-2",
"repository": "lerna/conventional-commits-fixed",
"version": "1.0.0",
"dependencies": {
"package-1": "^1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";

// https://git.io/vx5iq (conventional-changelog-angular/conventional-recommended-bump.js, etc)
const parserOpts = require("./parser-opts");
const writerOpts = require("./writer-opts");
const whatBump = require("./what-bump");

// https://git.io/fhyKK
module.exports = presetOpts;

function presetOpts(param) {
if (typeof param !== "function") {
return Promise.resolve(
Object.assign(param, {
parserOpts,
writerOpts,
whatBump,
})
);
}

process.nextTick(param, null, {
parserOpts,
writerOpts,
whatBump,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

module.exports = {
recommendedBumpOpts: {
whatBump: "I should be a function",
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

// https://git.io/vx5iq (conventional-changelog-angular/conventional-recommended-bump.js, etc)
const parserOpts = require("./parser-opts");
const writerOpts = require("./writer-opts");
const whatBump = require("./what-bump");

// https://git.io/fhyKK
module.exports = presetOpts;

function presetOpts(cb) {
process.nextTick(cb, null, {
parserOpts,
writerOpts,
whatBump,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

// https://git.io/vx5iq (conventional-changelog-angular/conventional-recommended-bump.js, etc)
const parserOpts = require("./parser-opts");
const writerOpts = require("./writer-opts");
const whatBump = require("./what-bump");

module.exports = {
conventionalChangelog: {
parserOpts,
writerOpts,
},
recommendedBumpOpts: {
parserOpts,
whatBump,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

// https://git.io/vx5iq (conventional-changelog-angular/conventional-recommended-bump.js, etc)
const parserOpts = require("./parser-opts");
const writerOpts = require("./writer-opts");
const whatBump = require("./null-what-bump");

module.exports = {
conventionalChangelog: {
parserOpts,
writerOpts,
},
recommendedBumpOpts: {
parserOpts,
whatBump,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";

module.exports = whatBump;

function whatBump(commits) {
let level = null;
let breakings = 0;
let features = 0;

commits.forEach((commit) => {
if (commit.notes.length > 0) {
breakings += commit.notes.length;
level = 0;
} else if (commit.type === "feat") {
features += 1;
if (level === 2) {
level = 1;
}
} else if (commit.type === "fix") {
level = 2;
}
});

return {
level,
reason:
breakings === 1
? `There are ${breakings} BREAKING CHANGE and ${features} features`
: `There are ${breakings} BREAKING CHANGES and ${features} features`,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

// https://git.io/vx5iq (conventional-changelog-angular/conventional-recommended-bump.js, etc)
const parserOpts = require("./parser-opts");
const writerOpts = require("./writer-opts");
const whatBump = require("./what-bump");

module.exports = {
parserOpts,
writerOpts,
whatBump,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

module.exports = {
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: [`type`, `scope`, `subject`],
noteKeywords: [`BREAKING CHANGE`],
revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
revertCorrespondence: [`header`, `hash`],
};

0 comments on commit b897936

Please sign in to comment.