Skip to content

Commit

Permalink
fix: do not prepend wiby- to branch name if it is already there
Browse files Browse the repository at this point in the history
Bullet point in #78
  • Loading branch information
dominykas committed Apr 18, 2021
1 parent 5e7f6d6 commit ce845d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 20 additions & 3 deletions test/cli/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions test/fixtures/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"')
childProcess.execSync('git config user.name "Wiby Bot"')

Expand Down

0 comments on commit ce845d4

Please sign in to comment.