Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major: prepared for semantic-release >= 11
- Loading branch information
Showing
4 changed files
with
2,870 additions
and
1,121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,64 @@ | ||
var test = require('tap').test | ||
var SRError = require('@semantic-release/error') | ||
|
||
var condition = require('./') | ||
|
||
test('raise errors in semaphore environment', function (t) { | ||
t.test('only runs on semaphore', function (tt) { | ||
tt.plan(2) | ||
|
||
condition({}, {env: {}}, function (err) { | ||
tt.ok(err instanceof SRError) | ||
tt.is(err.code, 'ENOSEMAPHORE') | ||
}) | ||
}) | ||
|
||
t.test('not running on pull requests', function (tt) { | ||
tt.plan(2) | ||
condition({}, { | ||
env: { | ||
SEMAPHORE: 'true', | ||
PULL_REQUEST_NUMBER: '1' | ||
} | ||
}, function (err) { | ||
tt.ok(err instanceof SRError) | ||
tt.is(err.code, 'EPULLREQUEST') | ||
}) | ||
}) | ||
|
||
t.test('only running on specified branch', function (tt) { | ||
tt.plan(5) | ||
|
||
condition({}, { | ||
env: { | ||
SEMAPHORE: 'true', | ||
BRANCH_NAME: 'master' | ||
}, | ||
options: { | ||
branch: 'master' | ||
} | ||
}, function (err) { | ||
tt.is(err, null) | ||
}) | ||
|
||
condition({}, { | ||
env: { | ||
SEMAPHORE: 'true', | ||
BRANCH_NAME: 'notmaster' | ||
}, | ||
options: { | ||
branch: 'master' | ||
} | ||
}, function (err) { | ||
tt.ok(err instanceof SRError) | ||
tt.is(err.code, 'EBRANCHMISMATCH') | ||
}) | ||
|
||
condition({}, { | ||
env: { | ||
SEMAPHORE: 'true', | ||
BRANCH_NAME: 'master' | ||
}, | ||
options: { | ||
branch: 'foo' | ||
} | ||
}, function (err) { | ||
tt.ok(err instanceof SRError) | ||
tt.is(err.code, 'EBRANCHMISMATCH') | ||
}) | ||
}) | ||
|
||
t.test('not running on tags', function (tt) { | ||
tt.plan(2) | ||
condition({}, { | ||
env: { | ||
SEMAPHORE: 'true', | ||
BRANCH_NAME: 'v1.0.0' | ||
}, | ||
options: {} | ||
}, function (err) { | ||
tt.ok(err instanceof SRError) | ||
tt.is(err.code, 'EGITTAG') | ||
}) | ||
}) | ||
|
||
t.end() | ||
import test from 'ava' | ||
import SemanticReleaseError from '@semantic-release/error' | ||
import condition from './' | ||
|
||
const envBackup = Object.assign({}, process.env) | ||
|
||
test.beforeEach(() => { | ||
// Delete env variables in case they are on the machine running the tests | ||
delete process.env.SEMAPHORE | ||
delete process.env.PULL_REQUEST_NUMBER | ||
delete process.env.BRANCH_NAME | ||
}) | ||
|
||
test.afterEach.always(() => { | ||
// Restore process.env | ||
process.env = envBackup | ||
}) | ||
|
||
test.serial('only runs on semaphore', async (t) => { | ||
const err = await t.throws(condition(), SemanticReleaseError) | ||
t.is(err.code, 'ENOSEMAPHORE') | ||
}) | ||
|
||
test.serial('not running on pull requests', async (t) => { | ||
process.env.SEMAPHORE = 'true' | ||
process.env.PULL_REQUEST_NUMBER = '1' | ||
|
||
const err = await t.throws(condition(), SemanticReleaseError) | ||
t.is(err.code, 'EPULLREQUEST') | ||
}) | ||
|
||
test.serial('only running on specified branch', async (t) => { | ||
let err | ||
process.env.SEMAPHORE = 'true' | ||
process.env.BRANCH_NAME = 'master' | ||
|
||
await condition({}, { options: { branch: 'master' } }) | ||
|
||
process.env.BRANCH_NAME = 'notmaster' | ||
|
||
err = await t.throws( | ||
condition({}, { options: { branch: 'master' } }), | ||
SemanticReleaseError | ||
) | ||
|
||
t.is(err.code, 'EBRANCHMISMATCH') | ||
|
||
process.env.BRANCH_NAME = 'master' | ||
|
||
err = await t.throws( | ||
condition({}, { options: { branch: 'notmaster' } }), | ||
SemanticReleaseError | ||
) | ||
|
||
t.is(err.code, 'EBRANCHMISMATCH') | ||
}) | ||
|
||
test.serial('not running on tags', async (t) => { | ||
process.env.SEMAPHORE = 'true' | ||
process.env.BRANCH_NAME = 'v1.0.0' | ||
|
||
const err = await t.throws(condition(), SemanticReleaseError) | ||
t.is(err.code, 'EGITTAG') | ||
}) |
Oops, something went wrong.