diff --git a/lib/context.js b/lib/context.js index a815dc2..b434770 100644 --- a/lib/context.js +++ b/lib/context.js @@ -10,7 +10,7 @@ exports.getParentBranchName = async function getParentBranchName () { } exports.getTestingBranchName = function getTestingBranchName (parentBranchName) { - return `wiby-${parentBranchName}` + return parentBranchName.startsWith('wiby-') ? parentBranchName : `wiby-${parentBranchName}` } exports.getDependencyLink = async function getDependencyLink (owner, repo, commitish) { diff --git a/test/cli/test.js b/test/cli/test.js index 96c2fbb..13b4e8d 100644 --- a/test/cli/test.js +++ b/test/cli/test.js @@ -10,11 +10,9 @@ const wibyCommand = path.join(__dirname, '..', '..', 'bin', 'wiby') const fixturesPath = path.resolve(path.join(__dirname, '..', 'fixtures')) tap.test('test command', async (tap) => { - tap.beforeEach(async () => { + tap.test('test command should fail when config and dependent provided', async (tap) => { gitFixture.init() - }) - tap.test('test command should fail when config and dependent provided', async (tap) => { try { childProcess.execSync(`${wibyCommand} test --config=.wiby.json --dependent="https://github.com/wiby-test/fakeRepo"`).toString() tap.fail() @@ -24,6 +22,8 @@ tap.test('test command', async (tap) => { }) tap.test('test command should call test module with dependent URI', async (tap) => { + gitFixture.init() + const result = childProcess.execSync(`${wibyCommand} test --dependent="https://github.com/wiby-test/fakeRepo"`, { env: { ...process.env, @@ -35,6 +35,23 @@ tap.test('test command', async (tap) => { }) tap.test('test command should call test module with all deps from .wiby.json', async (tap) => { + gitFixture.init() + + const result = childProcess.execSync(`${wibyCommand} test`, { + env: { + ...process.env, + NODE_OPTIONS: `-r ${fixturesPath}/http/test-command-positive.js` + } + }).toString() + + tap.match(result, 'Changes pushed to https://github.com/wiby-test/pass/blob/wiby-running-unit-tests/package.json') + tap.match(result, 'Changes pushed to https://github.com/wiby-test/fail/blob/wiby-running-unit-tests/package.json') + tap.match(result, 'Changes pushed to https://github.com/wiby-test/partial/blob/wiby-running-unit-tests/package.json') + }) + + tap.test('test command should not add `wiby-` prefix when branch already has it', async (tap) => { + gitFixture.init('wiby-running-unit-tests') + const result = childProcess.execSync(`${wibyCommand} test`, { env: { ...process.env, diff --git a/test/fixtures/git.js b/test/fixtures/git.js index cbea4fb..aa68acc 100644 --- a/test/fixtures/git.js +++ b/test/fixtures/git.js @@ -5,15 +5,13 @@ const fs = require('fs') const path = require('path') const tmp = require('tmp') -exports.TEST_BRANCH_NAME = 'running-unit-tests' - -exports.init = function () { +exports.init = function (initialBranch = 'running-unit-tests') { const gitRepoPath = path.join(__dirname, '..', '..') const { name: tmpDir } = tmp.dirSync() process.chdir(tmpDir) - childProcess.execSync('git init --initial-branch=running-unit-tests') + childProcess.execSync(`git init --initial-branch=${initialBranch}`) childProcess.execSync('git config user.email "wiby@example.com"') childProcess.execSync('git config user.name "Wiby Bot"')