diff --git a/package.json b/package.json index 263be8752f..2e52229f38 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,10 @@ "files": [ "test/**/*.test.js" ], + "nodeArguments": [ + "--loader=testdouble", + "--no-warnings" + ], "timeout": "2m" }, "bin": { diff --git a/test/branches/branches.test.js b/test/branches/branches.test.js index 14c6b743ba..50514b3eb5 100644 --- a/test/branches/branches.test.js +++ b/test/branches/branches.test.js @@ -22,14 +22,17 @@ test('Enforce ranges with branching release workflow', async (t) => { {name: 'beta', prerelease: true, tags: []}, {name: 'alpha', prerelease: true, tags: []}, ]; - td.replace('../../lib/branches/get-tags', () => branches); - td.replace('../../lib/branches/expand', () => []); - const getBranches = require('../../lib/branches'); + const getTags = await td.replaceEsm('../../lib/branches/get-tags.js'); + const expand = await td.replaceEsm('../../lib/branches/expand.js'); + const remoteBranches = []; + const context = {options: {branches}}; + td.when(expand.default()).thenResolve(remoteBranches); + td.when(getTags.default(context, remoteBranches)).thenResolve(branches); + + const getBranches = (await import('../../lib/branches/index.js')).default; + const result = (await getBranches('repositoryUrl', 'master', context)) + .map(({name, range}) => ({name, range,})); - let result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({ - name, - range, - })); t.is(getBranch(result, '1.0.x').range, '>=1.0.0 <1.0.0', 'Cannot release on 1.0.x before a releasing on master'); t.is(getBranch(result, '1.x').range, '>=1.1.0 <1.0.0', 'Cannot release on 1.x before a releasing on master'); t.is(getBranch(result, 'master').range, '>=1.0.0'); @@ -203,7 +206,7 @@ test('Throw SemanticReleaseError for invalid configurations', async (t) => { ]; td.replace('../../lib/branches/get-tags', () => branches); td.replace('../../lib/branches/expand', () => []); - const getBranches = require('../../lib/branches'); + const getBranches = (await import('../../lib/branches/index.js')).default; const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))]; t.is(errors[0].name, 'SemanticReleaseError'); @@ -233,11 +236,15 @@ test('Throw a SemanticReleaseError if there is duplicate branches', async (t) => {name: 'master', tags: []}, {name: 'master', tags: []}, ]; - td.replace('../../lib/branches/get-tags', () => branches); - td.replace('../../lib/branches/expand', () => []); - const getBranches = require('../../lib/branches'); + const getTags = await td.replaceEsm('../../lib/branches/get-tags.js'); + const expand = await td.replaceEsm('../../lib/branches/expand.js'); + const context = {options: {branches}}; + const remoteBranches = []; + td.when(expand.default()).thenResolve(remoteBranches); + td.when(getTags.default(context, remoteBranches)).thenResolve(branches); + const getBranches = (await import('../../lib/branches/index.js')).default; - const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))]; + const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', context)))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EDUPLICATEBRANCHES'); @@ -250,11 +257,15 @@ test('Throw a SemanticReleaseError for each invalid branch name', async (t) => { {name: '~master', tags: []}, {name: '^master', tags: []}, ]; - td.replace('../../lib/branches/get-tags', () => branches); - td.replace('../../lib/branches/expand', () => []); - const getBranches = require('../../lib/branches'); + const getTags = await td.replaceEsm('../../lib/branches/get-tags.js'); + const expand = await td.replaceEsm('../../lib/branches/expand.js'); + const context = {options: {branches}}; + const remoteBranches = []; + td.when(expand.default()).thenResolve(remoteBranches); + td.when(getTags.default(context, remoteBranches)).thenResolve(branches); + const getBranches = (await import('../../lib/branches/index.js')).default; - const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))]; + const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', context)))]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EINVALIDBRANCHNAME'); diff --git a/test/get-config.test.js b/test/get-config.test.js index 3ca6972454..6cb04370bd 100644 --- a/test/get-config.test.js +++ b/test/get-config.test.js @@ -17,10 +17,10 @@ const DEFAULT_PLUGINS = [ '@semantic-release/github', ]; -test.beforeEach((t) => { +test.beforeEach(async (t) => { t.context.plugins = stub().returns({}); - td.replace('../lib/plugins', t.context.plugins); - t.context.getConfig = require('../lib/get-config'); + await td.replaceEsm('../lib/plugins.js', null, t.context.plugins); + t.context.getConfig = (await import('../lib/get-config.js')).default; }); test('Default values, reading repositoryUrl from package.json', async (t) => { diff --git a/test/index.test.js b/test/index.test.js index 59df22f11f..6edacb3ffd 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -142,9 +142,9 @@ test('Plugins are called with expected values', async (t) => { {...nextRelease, notes: `${notes1}\n\n${notes2}\n\n${notes3}`, pluginName: pluginNoop}, ]; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => envCi); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => envCi); + const semanticRelease = (await import('../index.js')).default; const result = await semanticRelease(options, { cwd, env, @@ -417,9 +417,9 @@ test('Use custom tag format', async (t) => { fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.truthy( await semanticRelease(options, { cwd, @@ -475,9 +475,9 @@ test('Use new gitHead, and recreate release notes if a prepare plugin create a c fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.truthy( await semanticRelease(options, { @@ -541,9 +541,9 @@ test('Make a new release when a commit is forward-ported to an upper branch', as success, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.truthy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})); t.is(addChannel.callCount, 0); @@ -575,9 +575,9 @@ test('Publish a pre-release version', async (t) => { fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'beta', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'beta', isPr: false})); + const semanticRelease = (await import('../index.js')).default; let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); t.is(releases.length, 1); @@ -627,9 +627,9 @@ test('Publish releases from different branch on the same channel', async (t) => fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'next', isPr: false})); - let semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'next', isPr: false})); + let semanticRelease = (await import('../index.js')).default; let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); t.is(releases.length, 1); @@ -652,9 +652,9 @@ test('Publish releases from different branch on the same channel', async (t) => await merge('next', {cwd}); await gitPush('origin', 'master', {cwd}); - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + semanticRelease = (await import('../index.js')).default; t.falsy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})); t.is(addChannel.callCount, 0); @@ -685,9 +685,9 @@ test('Publish pre-releases the same channel as regular releases', async (t) => { fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'beta', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'beta', isPr: false})); + const semanticRelease = (await import('../index.js')).default; let {releases} = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); t.is(releases.length, 1); @@ -750,9 +750,9 @@ test('Do not add pre-releases to a different channel', async (t) => { success, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.truthy(await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}})); t.is(addChannel.callCount, 0); @@ -818,9 +818,9 @@ async function addChannelMacro(t, mergeFunction) { gitHead: commits[2].hash, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; const result = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); t.deepEqual(result.releases, [ @@ -884,9 +884,9 @@ test('Call all "success" plugins even if one errors out', async (t) => { success: [success1, success2], }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) @@ -928,9 +928,9 @@ test('Log all "verifyConditions" errors', async (t) => { fail, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; const errors = [ ...(await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) @@ -972,9 +972,9 @@ test('Log all "verifyRelease" errors', async (t) => { fail, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; const errors = [ ...(await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) @@ -1025,9 +1025,9 @@ test('Dry-run skips addChannel, prepare, publish and success', async (t) => { success, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.truthy( await semanticRelease(options, { cwd, @@ -1077,9 +1077,9 @@ test('Dry-run skips fail', async (t) => { fail, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; const errors = [ ...(await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) @@ -1136,9 +1136,9 @@ test('Force a dry-run if not on a CI and "noCi" is not explicitly set', async (t fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: false, branch: 'master'})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: false, branch: 'master'})); + const semanticRelease = (await import('../index.js')).default; t.truthy( await semanticRelease(options, { cwd, @@ -1185,9 +1185,9 @@ test('Dry-run does not print changelog if "generateNotes" return "undefined"', a success: false, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.truthy( await semanticRelease(options, { cwd, @@ -1243,9 +1243,9 @@ test('Allow local releases with "noCi" option', async (t) => { fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: false, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: false, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.truthy( await semanticRelease(options, { cwd, @@ -1312,9 +1312,9 @@ test('Accept "undefined" value returned by "generateNotes" and "false" by "publi fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.truthy( await semanticRelease(options, { cwd, @@ -1340,9 +1340,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); - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', prBranch: 'patch-1', isPr: true})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', prBranch: 'patch-1', isPr: true})); + const semanticRelease = (await import('../index.js')).default; t.false( await semanticRelease( @@ -1392,9 +1392,9 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren success, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: '1.x', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: '1.x', isPr: false})); + const semanticRelease = (await import('../index.js')).default; const error = await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}) @@ -1443,9 +1443,9 @@ test('Throws "EINVALIDNEXTVERSION" if next release is out of range of the curren success, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; const error = await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}) @@ -1502,9 +1502,9 @@ test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a ma fail, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: '1.1.x', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: '1.1.x', isPr: false})); + const semanticRelease = await import('../index.js'); const errors = [ ...(await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}) @@ -1538,9 +1538,9 @@ test('Returns false value if triggered on an outdated clone', async (t) => { await gitCommits(['Third'], {cwd}); await gitPush(repositoryUrl, 'master', {cwd}); - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.false( await semanticRelease( @@ -1570,9 +1570,9 @@ test('Returns false if not running from the configured branch', async (t) => { fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'other-branch', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'other-branch', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.false( await semanticRelease(options, { @@ -1614,9 +1614,9 @@ test('Returns false if there is no relevant changes', async (t) => { fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.false( await semanticRelease(options, { @@ -1669,9 +1669,9 @@ test('Exclude commits with [skip release] or [release skip] from analysis', asyn fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; await semanticRelease(options, { cwd, env: {}, @@ -1696,9 +1696,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)], }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) @@ -1720,9 +1720,9 @@ test('Call "fail" only if a plugin returns a SemanticReleaseError', async (t) => verifyConditions: stub().rejects(pluginError), fail, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) @@ -1736,9 +1736,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(); - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; const errors = [ ...(await t.throwsAsync( semanticRelease({}, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) @@ -1775,9 +1775,9 @@ test('Throw an Error if plugin returns an unexpected value', async (t) => { fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; const error = await t.throwsAsync( semanticRelease(options, {cwd, env: {}, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}), {instanceOf: SemanticReleaseError} @@ -1804,9 +1804,9 @@ test('Hide sensitive information passed to "fail" plugin', async (t) => { fail, }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; await t.throwsAsync( semanticRelease(options, {cwd, env, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}) ); @@ -1848,9 +1848,9 @@ test('Hide sensitive information passed to "success" plugin', async (t) => { fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; await semanticRelease(options, {cwd, env, stdout: new WritableStreamBuffer(), stderr: new WritableStreamBuffer()}); const release = success.args[0][1].releases[0]; @@ -1897,9 +1897,9 @@ test('Get all commits including the ones not in the shallow clone', async (t) => fail: stub().resolves(), }; - td.replace('../lib/get-logger', () => t.context.logger); - td.replace('env-ci', () => ({isCi: true, branch: 'master', isPr: false})); - const semanticRelease = require('..'); + await td.replaceEsm('../lib/get-logger.js', null, () => t.context.logger); + await td.replaceEsm('env-ci', null, () => ({isCi: true, branch: 'master', isPr: false})); + const semanticRelease = (await import('../index.js')).default; t.truthy( await semanticRelease(options, { cwd,