From 56a66795b5fbde2dbca7fc6c304e845d3c11144c Mon Sep 17 00:00:00 2001 From: Matt Travi Date: Fri, 7 Oct 2022 16:29:53 -0500 Subject: [PATCH] test(branches): made the tests run serially since the stub setup was bleeding between tests we should try to adjust the stub setup in each test to try to avoid the need for this, but i think that should be tackled separately from the current esm effort for #2543 --- test/branches/branches.test.js | 67 +++++++++++++++++----------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/test/branches/branches.test.js b/test/branches/branches.test.js index 50514b3eb5..8ec438a671 100644 --- a/test/branches/branches.test.js +++ b/test/branches/branches.test.js @@ -11,8 +11,21 @@ const merge = (branches, source, target, tag) => { getBranch(branches, target).tags ); }; +const remoteBranches = []; +const repositoryUrl = 'repositoryUrl'; +let expand, getTags, getBranches; -test('Enforce ranges with branching release workflow', async (t) => { +test.beforeEach(async (t) => { + getTags = (await td.replaceEsm('../../lib/branches/get-tags.js')).default; + expand = (await td.replaceEsm('../../lib/branches/expand.js')).default; + getBranches = (await import('../../lib/branches/index.js')).default; +}) + +test.afterEach.always((t) => { + td.reset(); +}); + +test.serial('Enforce ranges with branching release workflow', async (t) => { const branches = [ {name: '1.x', tags: []}, {name: '1.0.x', tags: []}, @@ -22,17 +35,11 @@ test('Enforce ranges with branching release workflow', async (t) => { {name: 'beta', prerelease: true, tags: []}, {name: 'alpha', prerelease: true, tags: []}, ]; - 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,})); + td.when(expand(repositoryUrl, context, branches)).thenResolve(remoteBranches); + td.when(getTags(context, remoteBranches)).thenResolve(branches); + let result = (await getBranches(repositoryUrl, 'master', context)).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'); @@ -40,10 +47,7 @@ test('Enforce ranges with branching release workflow', async (t) => { t.is(getBranch(result, 'next-major').range, '>=1.0.0'); release(branches, 'master', '1.0.0'); - result = (await getBranches('repositoryUrl', 'master', {options: {branches}})).map(({name, range}) => ({ - name, - range, - })); + result = (await getBranches('repositoryUrl', 'master', context)).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'); @@ -194,7 +198,7 @@ test('Enforce ranges with branching release workflow', async (t) => { t.is(getBranch(result, '1.x').range, '>=1.2.0 <2.0.0', 'Can release on 1.x only within range'); }); -test('Throw SemanticReleaseError for invalid configurations', async (t) => { +test.serial('Throw SemanticReleaseError for invalid configurations', async (t) => { const branches = [ {name: '123', range: '123', tags: []}, {name: '1.x', tags: []}, @@ -204,10 +208,12 @@ test('Throw SemanticReleaseError for invalid configurations', async (t) => { {name: 'alpha', prerelease: 'alpha', tags: []}, {name: 'preview', prerelease: 'alpha', tags: []}, ]; - td.replace('../../lib/branches/get-tags', () => branches); - td.replace('../../lib/branches/expand', () => []); - const getBranches = (await import('../../lib/branches/index.js')).default; - const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', {options: {branches}})))]; + const context = {options: {branches}}; + td.when(expand(repositoryUrl, context, branches)).thenResolve(remoteBranches); + td.when(getTags(context, remoteBranches)).thenResolve(branches); + + const error = await t.throwsAsync(getBranches(repositoryUrl, 'master', context)); + const errors = [...error.errors]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EMAINTENANCEBRANCH'); @@ -231,20 +237,16 @@ test('Throw SemanticReleaseError for invalid configurations', async (t) => { t.truthy(errors[4].details); }); -test('Throw a SemanticReleaseError if there is duplicate branches', async (t) => { +test.serial('Throw a SemanticReleaseError if there is duplicate branches', async (t) => { const branches = [ {name: 'master', tags: []}, {name: 'master', tags: []}, ]; - 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; + td.when(expand(repositoryUrl, context, branches)).thenResolve(remoteBranches); + td.when(getTags(context, remoteBranches)).thenResolve(branches); - const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', context)))]; + const errors = [...(await t.throwsAsync(getBranches(repositoryUrl, 'master', context))).errors]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EDUPLICATEBRANCHES'); @@ -252,20 +254,17 @@ test('Throw a SemanticReleaseError if there is duplicate branches', async (t) => t.truthy(errors[0].details); }); -test('Throw a SemanticReleaseError for each invalid branch name', async (t) => { +test.serial('Throw a SemanticReleaseError for each invalid branch name', async (t) => { const branches = [ {name: '~master', tags: []}, {name: '^master', tags: []}, ]; - 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; + td.when(expand(repositoryUrl, context, branches)).thenResolve(remoteBranches); + td.when(getTags(context, remoteBranches)).thenResolve(branches); - const errors = [...(await t.throwsAsync(getBranches('repositoryUrl', 'master', context)))]; + const errors = [...(await t.throwsAsync(getBranches(repositoryUrl, 'master', context))).errors]; t.is(errors[0].name, 'SemanticReleaseError'); t.is(errors[0].code, 'EINVALIDBRANCHNAME');