Skip to content

Commit

Permalink
tests: added tests for getConfigMultiSemrel.js
Browse files Browse the repository at this point in the history
  • Loading branch information
GeeWizWow authored and antongolub committed Jun 13, 2022
1 parent 08f01db commit b12238a
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/getConfigMultiSemrel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import resolveFrom from "resolve-from";
import { cosmiconfig } from "cosmiconfig";
import { default as resolveFrom } from "resolve-from";
import { pickBy, isNil, castArray } from "lodash-es";
import { pickBy, isNil, castArray, uniq } from "lodash-es";
import { createRequire } from "module";

const CONFIG_NAME = "multi-release";
Expand All @@ -26,6 +26,8 @@ const mergeConfig = (a = {}, b = {}) => {
...a.deps,
...pickBy(b.deps, (option) => !isNil(option)),
},
// Treat arrays differently by merging them
ignorePackages: uniq([...castArray(a.ignorePackages || []), ...castArray(b.ignorePackages || [])]),
};
};

Expand Down Expand Up @@ -63,7 +65,7 @@ export default async function getConfig(cwd, cliOptions) {
firstParent: false,
debug: false,
ignorePrivate: true,
ignorePackages: "",
ignorePackages: [],
tagFormat: "${name}@${version}",
dryRun: false,
deps: {
Expand Down
27 changes: 27 additions & 0 deletions test/fixtures/yarnWorkspacesConfig/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "msr-test-yarn",
"author": "Dave Houlbrooke <[email protected]",
"version": "0.0.0-semantically-released",
"private": true,
"license": "0BSD",
"engines": {
"node": ">=8.3"
},
"workspaces": {
"packages": ["packages/*"]
},
"release": {
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator"
],
"noCi": true
},
"multi-release": {
"debug": true,
"ignorePackages": ["!packages/d/**"],
"deps": {
"bump": "inherit"
}
}
}
8 changes: 8 additions & 0 deletions test/fixtures/yarnWorkspacesConfig/packages/a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "msr-test-a",
"version": "0.0.0",
"peerDependencies": {
"msr-test-c": "*",
"left-pad": "latest"
}
}
11 changes: 11 additions & 0 deletions test/fixtures/yarnWorkspacesConfig/packages/b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "msr-test-b",
"version": "0.0.0",
"dependencies": {
"msr-test-a": "*"
},
"devDependencies": {
"msr-test-c": "*",
"left-pad": "latest"
}
}
3 changes: 3 additions & 0 deletions test/fixtures/yarnWorkspacesConfig/packages/c/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tagFormat": "multi-semantic-release-test-c@v${version}"
}
8 changes: 8 additions & 0 deletions test/fixtures/yarnWorkspacesConfig/packages/c/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "msr-test-c",
"version": "0.0.0",
"devDependencies": {
"msr-test-b": "*",
"msr-test-d": "*"
}
}
4 changes: 4 additions & 0 deletions test/fixtures/yarnWorkspacesConfig/packages/d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "msr-test-d",
"version": "0.0.0"
}
5 changes: 5 additions & 0 deletions test/fixtures/yarnWorkspacesConfigExtends/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
deps: {
bump: "satisfy",
},
};
28 changes: 28 additions & 0 deletions test/fixtures/yarnWorkspacesConfigExtends/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "msr-test-yarn",
"author": "Dave Houlbrooke <[email protected]",
"version": "0.0.0-semantically-released",
"private": true,
"license": "0BSD",
"engines": {
"node": ">=8.3"
},
"workspaces": {
"packages": ["packages/*"]
},
"release": {
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator"
],
"noCi": true
},
"multi-release": {
"debug": true,
"ignorePackages": ["!packages/d/**"],
"deps": {
"bump": "inherit"
},
"extends": ["./config.js"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "msr-test-a",
"version": "0.0.0",
"peerDependencies": {
"msr-test-c": "*",
"left-pad": "latest"
}
}
11 changes: 11 additions & 0 deletions test/fixtures/yarnWorkspacesConfigExtends/packages/b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "msr-test-b",
"version": "0.0.0",
"dependencies": {
"msr-test-a": "*"
},
"devDependencies": {
"msr-test-c": "*",
"left-pad": "latest"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tagFormat": "multi-semantic-release-test-c@v${version}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "msr-test-c",
"version": "0.0.0",
"devDependencies": {
"msr-test-b": "*",
"msr-test-d": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "msr-test-d",
"version": "0.0.0"
}
149 changes: 149 additions & 0 deletions test/lib/getConfigMultiSemrel.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import getConfig from "../../lib/getConfigMultiSemrel.js";
import { gitInit } from "../helpers/git.js";
import { copyDirectory } from "../helpers/file.js";

// Tests.
describe("getConfig()", () => {
test("Default options", async () => {
const result = await getConfig(process.cwd(), {});
expect(result).toMatchObject({
sequentialInit: false,
sequentialPrepare: true,
firstParent: false,
debug: false,
ignorePrivate: true,
ignorePackages: [],
tagFormat: "${name}@${version}",
dryRun: false,
deps: {
bump: "override",
release: "patch",
prefix: "",
},
});
});

test("Only CLI flags and default options", async () => {
const cliFlags = {
debug: true,
ignorePackages: ["!packages/d/**"],
deps: {
bump: "inherit",
},
};
const result = await getConfig(process.cwd(), cliFlags);
expect(result).toMatchObject({
sequentialInit: false,
sequentialPrepare: true,
firstParent: false,
debug: true,
ignorePrivate: true,
ignorePackages: ["!packages/d/**"],
tagFormat: "${name}@${version}",
dryRun: false,
deps: {
bump: "inherit",
release: "patch",
prefix: "",
},
});
});

test("package.json config", async () => {
const cwd = await gitInit();
copyDirectory(`test/fixtures/yarnWorkspacesConfig/`, cwd);
const result = await getConfig(cwd, {});
expect(result).toMatchObject({
sequentialInit: false,
sequentialPrepare: true,
firstParent: false,
debug: true,
ignorePrivate: true,
ignorePackages: ["!packages/d/**"],
tagFormat: "${name}@${version}",
dryRun: false,
deps: {
bump: "inherit",
release: "patch",
prefix: "",
},
});
});

test("package.json config and CLI flags", async () => {
const cwd = await gitInit();
const cliFlags = {
debug: false,
ignorePackages: ["!packages/c/**"],
deps: {
release: "minor",
},
};
copyDirectory(`test/fixtures/yarnWorkspacesConfig/`, cwd);
const result = await getConfig(cwd, cliFlags);
expect(result).toMatchObject({
sequentialInit: false,
sequentialPrepare: true,
firstParent: false,
debug: false,
ignorePrivate: true,
ignorePackages: ["!packages/d/**", "!packages/c/**"],
tagFormat: "${name}@${version}",
dryRun: false,
deps: {
bump: "inherit",
release: "minor",
prefix: "",
},
});
});

test("package.json extends", async () => {
const cwd = await gitInit();
copyDirectory(`test/fixtures/yarnWorkspacesConfigExtends/`, cwd);
const result = await getConfig(cwd, {});
expect(result).toMatchObject({
sequentialInit: false,
sequentialPrepare: true,
firstParent: false,
debug: true,
ignorePrivate: true,
ignorePackages: ["!packages/d/**"],
tagFormat: "${name}@${version}",
dryRun: false,
deps: {
bump: "satisfy",
release: "patch",
prefix: "",
},
});
});

test("package.json extends and CLI flags", async () => {
const cwd = await gitInit();
const cliFlags = {
debug: false,
ignorePackages: ["!packages/c/**"],
deps: {
release: "minor",
},
};
copyDirectory(`test/fixtures/yarnWorkspacesConfigExtends/`, cwd);
const result = await getConfig(cwd, cliFlags);
expect(result).toMatchObject({
sequentialInit: false,
sequentialPrepare: true,
firstParent: false,
debug: false,
ignorePrivate: true,
ignorePackages: ["!packages/d/**", "!packages/c/**"],
tagFormat: "${name}@${version}",
dryRun: false,
deps: {
bump: "satisfy",
release: "minor",
prefix: "",
},
});
});
});

0 comments on commit b12238a

Please sign in to comment.