Skip to content

Commit

Permalink
test(branches): made the tests run serially since the stub setup was …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
travi committed Oct 7, 2022
1 parent 00683dc commit 56a6679
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions test/branches/branches.test.js
Expand Up @@ -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: []},
Expand All @@ -22,28 +35,19 @@ 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');
t.is(getBranch(result, 'next').range, '>=1.0.0');
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');
Expand Down Expand Up @@ -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: []},
Expand All @@ -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');
Expand All @@ -231,41 +237,34 @@ 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');
t.truthy(errors[0].message);
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');
Expand Down

0 comments on commit 56a6679

Please sign in to comment.