test: replaced proxyquire with testdouble (#2537)

for #2133

Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
This commit is contained in:
Matt Travi
2022-08-26 09:32:52 -07:00
committed by GitHub
co-authored by Gregor Martynus
parent 5eea7c948e
commit 9a513a38f7
7 changed files with 267 additions and 249 deletions
+13 -5
View File
@@ -1,7 +1,7 @@
const test = require('ava');
const {union} = require('lodash');
const semver = require('semver');
const proxyquire = require('proxyquire');
const td = require('testdouble');
const getBranch = (branches, branch) => branches.find(({name}) => name === branch);
const release = (branches, name, version) => getBranch(branches, name).tags.push({version});
@@ -22,7 +22,9 @@ test('Enforce ranges with branching release workflow', async (t) => {
{name: 'beta', prerelease: true, tags: []},
{name: 'alpha', prerelease: true, tags: []},
];
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
td.replace('../../lib/branches/get-tags', () => branches);
td.replace('../../lib/branches/expand', () => []);
const getBranches = require('../../lib/branches');
let result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({
name,
@@ -199,7 +201,9 @@ test('Throw SemanticReleaseError for invalid configurations', async (t) => {
{name: 'alpha', prerelease: 'alpha', tags: []},
{name: 'preview', prerelease: 'alpha', tags: []},
];
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
td.replace('../../lib/branches/get-tags', () => branches);
td.replace('../../lib/branches/expand', () => []);
const getBranches = require('../../lib/branches');
const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))];
t.is(errors[0].name, 'SemanticReleaseError');
@@ -229,7 +233,9 @@ test('Throw a SemanticReleaseError if there is duplicate branches', async (t) =>
{name: 'master', tags: []},
{name: 'master', tags: []},
];
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
td.replace('../../lib/branches/get-tags', () => branches);
td.replace('../../lib/branches/expand', () => []);
const getBranches = require('../../lib/branches');
const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))];
@@ -244,7 +250,9 @@ test('Throw a SemanticReleaseError for each invalid branch name', async (t) => {
{name: '~master', tags: []},
{name: '^master', tags: []},
];
const getBranches = proxyquire('../../lib/branches', {'./get-tags': () => branches, './expand': () => []});
td.replace('../../lib/branches/get-tags', () => branches);
td.replace('../../lib/branches/expand', () => []);
const getBranches = require('../../lib/branches');
const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))];
+41 -11
View File
@@ -1,9 +1,12 @@
const test = require('ava');
const {escapeRegExp} = require('lodash');
const proxyquire = require('proxyquire').noPreserveCache();
const td = require('testdouble');
const {stub} = require('sinon');
const {SECRET_REPLACEMENT} = require('../lib/definitions/constants');
let previousArgv;
let previousEnv;
test.beforeEach((t) => {
t.context.logs = '';
t.context.errors = '';
@@ -13,11 +16,17 @@ test.beforeEach((t) => {
t.context.stderr = stub(process.stderr, 'write').callsFake((value) => {
t.context.errors += value.toString();
});
previousArgv = process.argv;
previousEnv = process.env;
});
test.afterEach.always((t) => {
t.context.stdout.restore();
t.context.stderr.restore();
process.argv = previousArgv;
process.env = previousEnv;
});
test.serial('Pass options to semantic-release API', async (t) => {
@@ -63,7 +72,9 @@ test.serial('Pass options to semantic-release API', async (t) => {
'--debug',
'-d',
];
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
td.replace('..', run);
process.argv = argv;
const cli = require('../cli');
const exitCode = await cli();
@@ -105,7 +116,9 @@ test.serial('Pass options to semantic-release API with alias arguments', async (
'config2',
'--dry-run',
];
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
td.replace('..', run);
process.argv = argv;
const cli = require('../cli');
const exitCode = await cli();
@@ -122,7 +135,9 @@ test.serial('Pass options to semantic-release API with alias arguments', async (
test.serial('Pass unknown options to semantic-release API', async (t) => {
const run = stub().resolves(true);
const argv = ['', '', '--bool', '--first-option', 'value1', '--second-option', 'value2', '--second-option', 'value3'];
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
td.replace('..', run);
process.argv = argv;
const cli = require('../cli');
const exitCode = await cli();
@@ -136,7 +151,9 @@ test.serial('Pass unknown options to semantic-release API', async (t) => {
test.serial('Pass empty Array to semantic-release API for list option set to "false"', async (t) => {
const run = stub().resolves(true);
const argv = ['', '', '--publish', 'false'];
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
td.replace('..', run);
process.argv = argv;
const cli = require('../cli');
const exitCode = await cli();
@@ -148,7 +165,9 @@ test.serial('Pass empty Array to semantic-release API for list option set to "fa
test.serial('Do not set properties in option for which arg is not in command line', async (t) => {
const run = stub().resolves(true);
const argv = ['', '', '-b', 'master'];
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
td.replace('..', run);
process.argv = argv;
const cli = require('../cli');
await cli();
@@ -165,7 +184,9 @@ test.serial('Do not set properties in option for which arg is not in command lin
test.serial('Display help', async (t) => {
const run = stub().resolves(true);
const argv = ['', '', '--help'];
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
td.replace('..', run);
process.argv = argv;
const cli = require('../cli');
const exitCode = await cli();
@@ -176,7 +197,9 @@ test.serial('Display help', async (t) => {
test.serial('Return error exitCode and prints help if called with a command', async (t) => {
const run = stub().resolves(true);
const argv = ['', '', 'pre'];
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
td.replace('..', run);
process.argv = argv;
const cli = require('../cli');
const exitCode = await cli();
@@ -188,7 +211,9 @@ test.serial('Return error exitCode and prints help if called with a command', as
test.serial('Return error exitCode if multiple plugin are set for single plugin', async (t) => {
const run = stub().resolves(true);
const argv = ['', '', '--analyze-commits', 'analyze1', 'analyze2'];
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
td.replace('..', run);
process.argv = argv;
const cli = require('../cli');
const exitCode = await cli();
@@ -200,7 +225,9 @@ test.serial('Return error exitCode if multiple plugin are set for single plugin'
test.serial('Return error exitCode if semantic-release throw error', async (t) => {
const run = stub().rejects(new Error('semantic-release error'));
const argv = ['', ''];
const cli = proxyquire('../cli', {'.': run, process: {...process, argv}});
td.replace('..', run);
process.argv = argv;
const cli = require('../cli');
const exitCode = await cli();
@@ -212,7 +239,10 @@ test.serial('Hide sensitive environment variable values from the logs', async (t
const env = {MY_TOKEN: 'secret token'};
const run = stub().rejects(new Error(`Throw error: Exposing token ${env.MY_TOKEN}`));
const argv = ['', ''];
const cli = proxyquire('../cli', {'.': run, process: {...process, argv, env: {...process.env, ...env}}});
td.replace('..', run);
process.argv = argv;
process.env = {...process.env, ...env};
const cli = require('../cli');
const exitCode = await cli();
+3 -2
View File
@@ -3,7 +3,7 @@ const {format} = require('util');
const test = require('ava');
const {writeFile, outputJson} = require('fs-extra');
const {omit} = require('lodash');
const proxyquire = require('proxyquire');
const td = require('testdouble');
const {stub} = require('sinon');
const yaml = require('js-yaml');
const {gitRepo, gitTagVersion, gitCommits, gitShallowClone, gitAddConfig} = require('./helpers/git-utils');
@@ -17,7 +17,8 @@ const DEFAULT_PLUGINS = [
test.beforeEach((t) => {
t.context.plugins = stub().returns({});
t.context.getConfig = proxyquire('../lib/get-config', {'./plugins': t.context.plugins});
td.replace('../lib/plugins', t.context.plugins);
t.context.getConfig = require('../lib/get-config');
});
test('Default values, reading repositoryUrl from package.json', async (t) => {
+103 -138
View File
@@ -1,6 +1,6 @@
const test = require('ava');
const {escapeRegExp, isString, sortBy, omit} = require('lodash');
const proxyquire = require('proxyquire');
const td = require('testdouble');
const {spy, stub} = require('sinon');
const {WritableStreamBuffer} = require('stream-buffers');
const AggregateError = require('aggregate-error');
@@ -23,7 +23,6 @@ const {
gitGetNote,
} = require('./helpers/git-utils');
const requireNoCache = proxyquire.noPreserveCache();
const pluginNoop = require.resolve('./fixtures/plugin-noop');
test.beforeEach((t) => {
@@ -144,10 +143,9 @@ test('Plugins are called with expected values', async (t) => {
{...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: pluginNoop},
];
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => envCi,
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => envCi);
const semanticRelease = require('..');
const result = await semanticRelease(options, {
cwd,
env,
@@ -420,10 +418,9 @@ test('Use custom tag format', async (t) => {
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
t.truthy(
await semanticRelease(options, {
cwd,
@@ -479,10 +476,9 @@ test('Use new gitHead, and recreate release notes if a prepare plugin create a c
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
t.truthy(
await semanticRelease(options, {
@@ -546,10 +542,9 @@ test('Make a new release when a commit is forward-ported to an upper branch', as
success,
};
const semanticRelease = proxyquire('..', {
'./lib/logger': t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
t.truthy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}));
t.is(addChannel.callCount, 0);
@@ -581,10 +576,9 @@ test('Publish a pre-release version', async (t) => {
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'beta', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'beta', isPr: false}));
const semanticRelease = require('..');
let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}});
t.is(releases.length, 1);
@@ -634,10 +628,9 @@ test('Publish releases from different branch on the same channel', async (t) =>
fail: stub().resolves(),
};
let semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'next', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'next', isPr: false}));
let semanticRelease = require('..');
let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}});
t.is(releases.length, 1);
@@ -660,10 +653,9 @@ test('Publish releases from different branch on the same channel', async (t) =>
await merge('next', {cwd});
await gitPush('origin', 'master', {cwd});
semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
semanticRelease = require('..');
t.falsy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}));
t.is(addChannel.callCount, 0);
@@ -694,10 +686,9 @@ test('Publish pre-releases the same channel as regular releases', async (t) => {
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'beta', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'beta', isPr: false}));
const semanticRelease = require('..');
let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}});
t.is(releases.length, 1);
@@ -760,10 +751,9 @@ test('Do not add pre-releases to a different channel', async (t) => {
success,
};
const semanticRelease = proxyquire('..', {
'./lib/logger': t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
t.truthy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}));
t.is(addChannel.callCount, 0);
@@ -829,10 +819,9 @@ async function addChannelMacro(t, mergeFunction) {
gitHead: commits[2].hash,
};
const semanticRelease = proxyquire('..', {
'./lib/logger': t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
const result = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}});
t.deepEqual(result.releases, [
@@ -896,10 +885,9 @@ test('Call all "success" plugins even if one errors out', async (t) => {
success: [success1, success2],
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
await t.throwsAsync(
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
@@ -941,10 +929,9 @@ test('Log all "verifyConditions" errors', async (t) => {
fail,
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
const errors = [
...(await t.throwsAsync(
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
@@ -986,10 +973,9 @@ test('Log all "verifyRelease" errors', async (t) => {
fail,
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
const errors = [
...(await t.throwsAsync(
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
@@ -1040,10 +1026,9 @@ test('Dry-run skips addChannel, prepare, publish and success', async (t) => {
success,
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
t.truthy(
await semanticRelease(options, {
cwd,
@@ -1093,10 +1078,9 @@ test('Dry-run skips fail', async (t) => {
fail,
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
const errors = [
...(await t.throwsAsync(
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
@@ -1153,10 +1137,9 @@ test('Force a dry-run if not on a CI and "noCi" is not explicitly set', async (t
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: false, branch: 'master'}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: false, branch: 'master'}));
const semanticRelease = require('..');
t.truthy(
await semanticRelease(options, {
cwd,
@@ -1203,10 +1186,9 @@ test('Dry-run does not print changelog if "generateNotes" return "undefined"', a
success: false,
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
t.truthy(
await semanticRelease(options, {
cwd,
@@ -1262,10 +1244,9 @@ test('Allow local releases with "noCi" option', async (t) => {
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: false, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: false, branch: 'master', isPr: false}));
const semanticRelease = require('..');
t.truthy(
await semanticRelease(options, {
cwd,
@@ -1332,10 +1313,9 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
t.truthy(
await semanticRelease(options, {
cwd,
@@ -1361,10 +1341,9 @@ test('Returns false if triggered by a PR', async (t) => {
// Create a git repository, set the current working directory at the root of the repo
const {cwd, repositoryUrl} = await gitRepo(true);
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', prBranch: 'patch-1', isPr: true}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', prBranch: 'patch-1', isPr: true}));
const semanticRelease = require('..');
t.false(
await semanticRelease(
@@ -1414,10 +1393,9 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren
success,
};
const semanticRelease = proxyquire('..', {
'./lib/logger': t.context.logger,
'env-ci': () => ({isCi: true, branch: '1.x', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: '1.x', isPr: false}));
const semanticRelease = require('..');
const error = await t.throwsAsync(
semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})
@@ -1466,10 +1444,9 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren
success,
};
const semanticRelease = proxyquire('..', {
'./lib/logger': t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
const error = await t.throwsAsync(
semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})
@@ -1526,10 +1503,9 @@ test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a ma
fail,
};
const semanticRelease = proxyquire('..', {
'./lib/logger': t.context.logger,
'env-ci': () => ({isCi: true, branch: '1.1.x', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: '1.1.x', isPr: false}));
const semanticRelease = require('..');
const errors = [
...(await t.throwsAsync(
semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})
@@ -1563,10 +1539,9 @@ test('Returns false value if triggered on an outdated clone', async (t) => {
await gitCommits(['Third'], {cwd});
await gitPush(repositoryUrl, 'master', {cwd});
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
t.false(
await semanticRelease(
@@ -1596,10 +1571,9 @@ test('Returns false if not running from the configured branch', async (t) => {
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'other-branch', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'other-branch', isPr: false}));
const semanticRelease = require('..');
t.false(
await semanticRelease(options, {
@@ -1641,10 +1615,9 @@ test('Returns false if there is no relevant changes', async (t) => {
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
t.false(
await semanticRelease(options, {
@@ -1697,10 +1670,9 @@ test('Exclude commits with [skip release] or [release skip] from analysis', asyn
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
await semanticRelease(options, {
cwd,
env: {},
@@ -1725,10 +1697,9 @@ test('Log both plugins errors and errors thrown by "fail" plugin', async (t) =>
verifyConditions: stub().rejects(pluginError),
fail: [stub().rejects(failError1), stub().rejects(failError2)],
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
await t.throwsAsync(
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
@@ -1750,10 +1721,9 @@ test('Call "fail" only if a plugin returns a SemanticReleaseError', async (t) =>
verifyConditions: stub().rejects(pluginError),
fail,
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
await t.throwsAsync(
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
@@ -1767,10 +1737,9 @@ test('Throw SemanticReleaseError if repositoryUrl is not set and cannot be found
// Create a git repository, set the current working directory at the root of the repo
const {cwd} = await gitRepo();
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
const errors = [
...(await t.throwsAsync(
semanticRelease({}, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
@@ -1807,10 +1776,9 @@ test('Throw an Error if plugin returns an unexpected value', async (t) => {
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
const error = await t.throwsAsync(
semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}),
{instanceOf: SemanticReleaseError}
@@ -1837,10 +1805,9 @@ test('Hide sensitive information passed to "fail" plugin', async (t) => {
fail,
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
await t.throwsAsync(
semanticRelease(options, {cwd, env, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()})
);
@@ -1882,10 +1849,9 @@ test('Hide sensitive information passed to "success" plugin', async (t) => {
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
await semanticRelease(options, {cwd, env, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()});
const release = success.args[0][1].releases[0];
@@ -1932,10 +1898,9 @@ test('Get all commits including the ones not in the shallow clone', async (t) =>
fail: stub().resolves(),
};
const semanticRelease = requireNoCache('..', {
'./lib/get-logger': () => t.context.logger,
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/get-logger', () => t.context.logger);
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
t.truthy(
await semanticRelease(options, {
cwd,
+4 -7
View File
@@ -1,6 +1,6 @@
const path = require('path');
const test = require('ava');
const proxyquire = require('proxyquire');
const td = require('testdouble');
const {escapeRegExp} = require('lodash');
const {writeJson, readJson} = require('fs-extra');
const execa = require('execa');
@@ -26,8 +26,6 @@ const npmRegistry = require('./helpers/npm-registry');
/* eslint camelcase: ["error", {properties: "never"}] */
const requireNoCache = proxyquire.noPreserveCache();
// Environment variables used with semantic-release cli (similar to what a user would setup)
const {GITHUB_ACTION, GITHUB_TOKEN, ...processEnvWithoutGitHubActionsVariables} = process.env;
const env = {
@@ -509,10 +507,9 @@ test('Pass options via CLI arguments', async (t) => {
});
test('Run via JS API', async (t) => {
const semanticRelease = requireNoCache('..', {
'./lib/logger': {log: () => {}, error: () => {}, stdout: () => {}},
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
});
td.replace('../lib/logger', {log: () => {}, error: () => {}, stdout: () => {}});
td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false}));
const semanticRelease = require('..');
const packageName = 'test-js-api';
const owner = 'git';
// Create a git repository, set the current working directory at the root of the repo