From 722e4d6e8aeec073e204894ee4852ab19caae952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Blyz=CC=8Ce=CC=87?= Date: Thu, 18 Mar 2021 14:30:01 +0200 Subject: [PATCH 1/4] feat: use the current branch name as the base for wiby testing branch name --- lib/clean.js | 3 +- lib/context.js | 17 +++++- lib/result.js | 5 +- lib/test.js | 59 ++++++++----------- package.json | 4 +- test/clean.js | 6 +- test/cli/clean.js | 18 +++--- test/cli/result.js | 4 ++ test/cli/test.js | 10 ++-- test/fixtures/http/clean-command-dry.js | 2 +- test/fixtures/http/clean-command.js | 4 +- .../result-command-empty-branch-checks.js | 4 +- .../result-command-positive-checks-failed.js | 2 +- test/fixtures/http/result-command-positive.js | 8 +-- 14 files changed, 80 insertions(+), 66 deletions(-) diff --git a/lib/clean.js b/lib/clean.js index 72dbb51..d063276 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -24,7 +24,8 @@ module.exports = async ({ dependents }, { all, dryRun }) => { let branches - const branch = await context.getTestingBranchName(parentPkgJSON.name) + const parentBranchName = await context.getParentBranchName() + const branch = await context.getTestingBranchName(parentBranchName) if (all) { branches = await github.getWibyBranches(dependentPkgInfo.owner, dependentPkgInfo.name) diff --git a/lib/context.js b/lib/context.js index 59d8a5e..a815dc2 100644 --- a/lib/context.js +++ b/lib/context.js @@ -1,9 +1,20 @@ 'use strict' +const simpleGit = require('simple-git') const fsPromises = require('fs').promises -exports.getTestingBranchName = async function getTestingBranchName (parentPackageName) { - return `wiby-${parentPackageName}` +exports.getParentBranchName = async function getParentBranchName () { + const { current } = await simpleGit().branch() + + return current +} + +exports.getTestingBranchName = function getTestingBranchName (parentBranchName) { + return `wiby-${parentBranchName}` +} + +exports.getDependencyLink = async function getDependencyLink (owner, repo, commitish) { + return `${owner}/${repo}#${commitish}` } exports.getLocalPackageJSON = async function getLocalPackageJSON () { @@ -15,7 +26,7 @@ exports.getLocalPackageJSON = async function getLocalPackageJSON () { The check should search both the dev and peer dependencies to find out if the dependency is regular, dev or peer. */ -exports.checkPackageInPackageJSON = function checkPackageInPackageJSON (dep, packageJSON) { +exports.checkDependentUsesParent = function checkDependentUsesParent (dep, packageJSON) { const dependencyKeyNames = [ 'dependencies', 'devDependencies', diff --git a/lib/result.js b/lib/result.js index 7354793..93ce1d4 100644 --- a/lib/result.js +++ b/lib/result.js @@ -30,11 +30,12 @@ module.exports = async function ({ dependents }) { const dependentPkgJSON = await github.getPackageJson(dependentPkgInfo.owner, dependentPkgInfo.name) debug(`Dependent module: ${dependentPkgInfo.owner}/${dependentPkgInfo.name}`) - if (!context.checkPackageInPackageJSON(parentPkgJSON.name, dependentPkgJSON)) { + if (!context.checkDependentUsesParent(parentPkgJSON.name, dependentPkgJSON)) { throw new Error(`${parentPkgInfo.owner}/${parentPkgJSON.name} not found in the package.json of ${dependentPkgInfo.owner}/${dependentPkgInfo.name}`) } - const branch = await context.getTestingBranchName(parentPkgJSON.name) + const parentBranchName = await context.getParentBranchName() + const branch = await context.getTestingBranchName(parentBranchName) let resp = await github.getChecks(dependentPkgInfo.owner, dependentPkgInfo.name, branch) if (resp.data.check_runs.length === 0) { resp = await github.getCommitStatusesForRef(dependentPkgInfo.owner, dependentPkgInfo.name, branch) diff --git a/lib/test.js b/lib/test.js index c02861b..e00f594 100644 --- a/lib/test.js +++ b/lib/test.js @@ -14,41 +14,30 @@ module.exports = async function ({ dependents }) { logger.enableLogs(testCommandNamespace) const parentPkgJSON = await context.getLocalPackageJSON() - const parentPkgInfo = gitURLParse(parentPkgJSON.repository.url) - debug(`Parent module: ${parentPkgInfo.owner}/${parentPkgJSON.name}`) + const parentRepositoryInfo = gitURLParse(parentPkgJSON.repository.url) + const parentBranchName = await context.getParentBranchName() + debug(`Parent module: ${parentRepositoryInfo.owner}/${parentPkgJSON.name}`) - const commitURL = await getCommitURL(parentPkgInfo.owner, parentPkgInfo.name) - debug('Commit URL to test:', commitURL) + const parentDependencyLink = await context.getDependencyLink(parentRepositoryInfo.owner, parentRepositoryInfo.name, parentBranchName) + debug('Commit URL to test:', parentDependencyLink) for (const { repository: url } of dependents) { - const dependentPkgInfo = gitURLParse(url) - const dependentPkgJSON = await github.getPackageJson(dependentPkgInfo.owner, dependentPkgInfo.name) - debug(`Dependent module: ${dependentPkgInfo.owner}/${dependentPkgInfo.name}`) + const dependentRepositoryInfo = gitURLParse(url) + const dependentPkgJson = await github.getPackageJson(dependentRepositoryInfo.owner, dependentRepositoryInfo.name) + debug(`Dependent module: ${dependentRepositoryInfo.owner}/${dependentRepositoryInfo.name}`) - if (!context.checkPackageInPackageJSON(parentPkgJSON.name, dependentPkgJSON)) { - throw new Error(`${parentPkgInfo.owner}/${parentPkgJSON.name} not found in the package.json of ${dependentPkgInfo.owner}/${dependentPkgInfo.name}`) + if (!context.checkDependentUsesParent(parentPkgJSON.name, dependentPkgJson)) { + throw new Error(`${parentRepositoryInfo.owner}/${parentPkgJSON.name} not found in the package.json of ${dependentRepositoryInfo.owner}/${dependentRepositoryInfo.name}`) } - const patchedPackageJSON = applyPatch(commitURL, parentPkgJSON.name, dependentPkgJSON) - await pushPatch(patchedPackageJSON, dependentPkgInfo.owner, dependentPkgInfo.name, parentPkgJSON.name) + const patchedPackageJSON = applyPatch(parentDependencyLink, parentPkgJSON.name, dependentPkgJson, parentPkgJSON.name) + await pushPatch(patchedPackageJSON, dependentRepositoryInfo.owner, dependentRepositoryInfo.name, parentPkgJSON.name, parentBranchName) } } -const getCommitHash = async function getCommitHash (owner, repo) { - const [headSha] = await github.getShas(owner, repo) - return headSha -} - -const getCommitURL = async function getCommitURL (owner, repo, hash) { - hash = hash || await getCommitHash(owner, repo) - - const patch = `${owner}/${repo}#${hash}` - return patch -} - const applyPatch = module.exports.applyPatch = function applyPatch (patch, module, dependentPkgJSON) { - const dependencyType = context.checkPackageInPackageJSON(module, dependentPkgJSON) + const dependencyType = context.checkDependentUsesParent(module, dependentPkgJSON) if (!dependencyType) { throw new Error('Dependency not found in package.json') } @@ -56,16 +45,16 @@ function applyPatch (patch, module, dependentPkgJSON) { return dependentPkgJSON } -async function pushPatch (packageJSON, owner, repo, dep) { - const file = JSON.stringify(packageJSON, null, 2) + '\n' // assumes package.json is using two spaces +async function pushPatch (dependentPkgJson, dependentOwner, dependentRepo, parentName, parentBranchName) { + const file = JSON.stringify(dependentPkgJson, null, 2) + '\n' // assumes package.json is using two spaces const encodedFile = Buffer.from(file).toString('base64') - const message = `wiby: update ${dep}` - const branch = await context.getTestingBranchName(dep) - - const [headSha, treeSha] = await github.getShas(owner, repo) - const blobSha = await github.createBlob(owner, repo, encodedFile) - const newTreeSha = await github.createTree(owner, repo, treeSha, blobSha) - const commitSha = await github.createCommit(owner, repo, message, newTreeSha, headSha) - await github.createBranch(owner, repo, commitSha, branch) - debug(`Changes pushed to https://github.com/${owner}/${repo}/blob/${branch}/package.json`) + const message = `wiby: update ${parentName}` + const branch = await context.getTestingBranchName(parentBranchName) + + const [headSha, treeSha] = await github.getShas(dependentOwner, dependentRepo) + const blobSha = await github.createBlob(dependentOwner, dependentRepo, encodedFile) + const newTreeSha = await github.createTree(dependentOwner, dependentRepo, treeSha, blobSha) + const commitSha = await github.createCommit(dependentOwner, dependentRepo, message, newTreeSha, headSha) + await github.createBranch(dependentOwner, dependentRepo, commitSha, branch) + debug(`Changes pushed to https://github.com/${dependentOwner}/${dependentRepo}/blob/${branch}/package.json`) } diff --git a/package.json b/package.json index cfaca88..4b9be58 100644 --- a/package.json +++ b/package.json @@ -37,12 +37,14 @@ "git-url-parse": "^11.1.2", "joi": "^17.2.1", "node-fetch": "^2.6.0", + "simple-git": "^2.35.1", "yargs": "^16.0.0" }, "devDependencies": { "nock": "^13.0.3", "standard": "^16.0.0", - "tap": "^14.10.7" + "tap": "^14.10.7", + "tmp": "^0.2.1" }, "standard": { "ignore": [ diff --git a/test/clean.js b/test/clean.js index 8580023..37b8957 100644 --- a/test/clean.js +++ b/test/clean.js @@ -18,17 +18,17 @@ tap.afterEach(async () => { tap.test('wiby.clean()', async (tap) => { tap.test('should check if the wiby branch exists', async (tap) => { nock('https://api.github.com') - .get(`/repos/wiby-test/${CONFIG.DEP_REPO}/branches/wiby-wiby`) + .get(`/repos/wiby-test/${CONFIG.DEP_REPO}/branches/wiby-branch-naming`) .reply(404) await wiby.clean({ dependents: [{ repository: `https://www.github.com/${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}` }] }, {}) - // implied assertion - no DELETE requests expected - we don't need to delete the missing `wiby-wiby` branch + // implied assertion - no DELETE requests expected - we don't need to delete the missing `wiby-branch-naming` branch }) tap.test('should rethrow when github API inaccessible during branch check', async (tap) => { nock('https://api.github.com') - .get(`/repos/wiby-test/${CONFIG.DEP_REPO}/branches/wiby-wiby`) + .get(`/repos/wiby-test/${CONFIG.DEP_REPO}/branches/wiby-branch-naming`) .reply(500) await tap.rejects( diff --git a/test/cli/clean.js b/test/cli/clean.js index 2538d80..fbd1852 100644 --- a/test/cli/clean.js +++ b/test/cli/clean.js @@ -13,30 +13,33 @@ tap.test('clean command', async (tap) => { const result = childProcess.execSync(`${wibyCommand} clean`, { cwd: cwd, env: { + ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/clean-command.js` } }).toString() tap.includes(result, 'Branches deleted:') - tap.includes(result, '- https://github.com/wiby-test/partial: wiby-wiby') - tap.includes(result, '- git://github.com/wiby-test/fail: wiby-wiby') - tap.includes(result, '- git+https://github.com/wiby-test/pass: wiby-wiby') + tap.includes(result, '- https://github.com/wiby-test/partial: wiby-branch-naming') + tap.includes(result, '- git://github.com/wiby-test/fail: wiby-branch-naming') + tap.includes(result, '- git+https://github.com/wiby-test/pass: wiby-branch-naming') }) tap.test('should delete test branch in the test module at dependent URI', async (tap) => { const result = childProcess.execSync(`${wibyCommand} clean --dependent="https://github.com/wiby-test/fakeRepo"`, { cwd: cwd, env: { + ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/clean-command.js` } }).toString() tap.includes(result, 'Branches deleted:') - tap.includes(result, '- https://github.com/wiby-test/fakeRepo: wiby-wiby') + tap.includes(result, '- https://github.com/wiby-test/fakeRepo: wiby-branch-naming') }) tap.test('should delete all wiby-* branches in all configured test modules', async (tap) => { const result = childProcess.execSync(`${wibyCommand} clean --all`, { cwd: cwd, env: { + ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/clean-command-all.js` } }).toString() @@ -50,13 +53,14 @@ tap.test('clean command', async (tap) => { const result = childProcess.execSync(`${wibyCommand} clean --dry-run`, { cwd: cwd, env: { + ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/clean-command-dry.js` } }).toString() tap.includes(result, 'Branches to be deleted:') - tap.includes(result, '- https://github.com/wiby-test/partial: wiby-wiby') - tap.includes(result, '- git://github.com/wiby-test/fail: wiby-wiby') - tap.includes(result, '- git+https://github.com/wiby-test/pass: wiby-wiby') + tap.includes(result, '- https://github.com/wiby-test/partial: wiby-branch-naming') + tap.includes(result, '- git://github.com/wiby-test/fail: wiby-branch-naming') + tap.includes(result, '- git+https://github.com/wiby-test/pass: wiby-branch-naming') }) }) diff --git a/test/cli/result.js b/test/cli/result.js index 5ce4ab7..0bc04de 100644 --- a/test/cli/result.js +++ b/test/cli/result.js @@ -32,6 +32,7 @@ tap.test('result command', async (tap) => { childProcess.execSync(`${wibyCommand} result --dependent="https://github.com/wiby-test/fakeRepo"`, { cwd: cwd, env: { + ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-positive.js` } }) @@ -54,6 +55,7 @@ tap.test('result command', async (tap) => { childProcess.execSync(`${wibyCommand} result`, { cwd: cwd, env: { + ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-positive.js` } }) @@ -76,6 +78,7 @@ tap.test('result command', async (tap) => { childProcess.execSync(`${wibyCommand} result --dependent="https://github.com/wiby-test/fakeRepo"`, { cwd: cwd, env: { + ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-empty-branch-checks.js` } }) @@ -100,6 +103,7 @@ tap.test('result command', async (tap) => { childProcess.execSync(`${wibyCommand} result --dependent="https://github.com/wiby-test/fakeRepo"`, { cwd: cwd, env: { + ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-positive-checks-failed.js` } }) diff --git a/test/cli/test.js b/test/cli/test.js index 915251f..327b739 100644 --- a/test/cli/test.js +++ b/test/cli/test.js @@ -22,23 +22,25 @@ tap.test('test command', async (tap) => { const result = childProcess.execSync(`${wibyCommand} test --dependent="https://github.com/wiby-test/fakeRepo"`, { cwd: cwd, env: { + ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/test-command-positive.js` } }).toString() - tap.includes(result, 'Changes pushed to https://github.com/wiby-test/fakeRepo/blob/wiby-wiby/package.json') + tap.includes(result, 'Changes pushed to https://github.com/wiby-test/fakeRepo/blob/wiby-branch-naming/package.json') }) tap.test('test command should call test module with all deps from .wiby.json', async (tap) => { const result = childProcess.execSync(`${wibyCommand} test`, { cwd: cwd, env: { + ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/test-command-positive.js` } }).toString() - tap.includes(result, 'Changes pushed to https://github.com/wiby-test/pass/blob/wiby-wiby/package.json') - tap.includes(result, 'Changes pushed to https://github.com/wiby-test/fail/blob/wiby-wiby/package.json') - tap.includes(result, 'Changes pushed to https://github.com/wiby-test/partial/blob/wiby-wiby/package.json') + tap.includes(result, 'Changes pushed to https://github.com/wiby-test/pass/blob/wiby-branch-naming/package.json') + tap.includes(result, 'Changes pushed to https://github.com/wiby-test/fail/blob/wiby-branch-naming/package.json') + tap.includes(result, 'Changes pushed to https://github.com/wiby-test/partial/blob/wiby-branch-naming/package.json') }) }) diff --git a/test/fixtures/http/clean-command-dry.js b/test/fixtures/http/clean-command-dry.js index 3e66a37..417dfb0 100644 --- a/test/fixtures/http/clean-command-dry.js +++ b/test/fixtures/http/clean-command-dry.js @@ -9,7 +9,7 @@ nock.disableNetConnect() function nockRepo (nockInstance, repo) { return nockInstance - .get(`/repos/wiby-test/${repo}/branches/wiby-wiby`) + .get(`/repos/wiby-test/${repo}/branches/wiby-branch-naming`) .reply(200) } diff --git a/test/fixtures/http/clean-command.js b/test/fixtures/http/clean-command.js index 59d5a79..9b31cab 100644 --- a/test/fixtures/http/clean-command.js +++ b/test/fixtures/http/clean-command.js @@ -9,9 +9,9 @@ nock.disableNetConnect() function nockRepo (nockInstance, repo) { return nockInstance - .get(`/repos/wiby-test/${repo}/branches/wiby-wiby`) + .get(`/repos/wiby-test/${repo}/branches/wiby-branch-naming`) .reply(200) - .delete(`/repos/wiby-test/${repo}/git/refs/heads%2Fwiby-wiby`) + .delete(`/repos/wiby-test/${repo}/git/refs/heads%2Fwiby-branch-naming`) .reply(200) } diff --git a/test/fixtures/http/result-command-empty-branch-checks.js b/test/fixtures/http/result-command-empty-branch-checks.js index 622686c..28a3645 100644 --- a/test/fixtures/http/result-command-empty-branch-checks.js +++ b/test/fixtures/http/result-command-empty-branch-checks.js @@ -24,14 +24,14 @@ nock('https://api.github.com') } }) // get check results - .get('/repos/wiby-test/fakeRepo/commits/wiby-wiby/check-runs') + .get('/repos/wiby-test/fakeRepo/commits/wiby-branch-naming/check-runs') .reply(200, { check_runs: [ // empty checks list ] }) // get checks for ref - .get('/repos/wiby-test/fakeRepo/commits/wiby-wiby/statuses') + .get('/repos/wiby-test/fakeRepo/commits/wiby-branch-naming/statuses') .reply(200, { check_runs: [ { status: 'queued', name: 'fake_run' }, diff --git a/test/fixtures/http/result-command-positive-checks-failed.js b/test/fixtures/http/result-command-positive-checks-failed.js index c205489..4bf3c9f 100644 --- a/test/fixtures/http/result-command-positive-checks-failed.js +++ b/test/fixtures/http/result-command-positive-checks-failed.js @@ -26,7 +26,7 @@ nock('https://api.github.com') } }) // get check results - .get('/repos/wiby-test/fakeRepo/commits/wiby-wiby/check-runs') + .get('/repos/wiby-test/fakeRepo/commits/wiby-branch-naming/check-runs') .reply(200, { check_runs: [ { status: 'done', name: 'fake_run', conclusion: 'failure' } diff --git a/test/fixtures/http/result-command-positive.js b/test/fixtures/http/result-command-positive.js index 8e39693..dda2a7d 100644 --- a/test/fixtures/http/result-command-positive.js +++ b/test/fixtures/http/result-command-positive.js @@ -25,28 +25,28 @@ nock('https://api.github.com') } }) // get check results - .get('/repos/wiby-test/fakeRepo/commits/wiby-wiby/check-runs') + .get('/repos/wiby-test/fakeRepo/commits/wiby-branch-naming/check-runs') .reply(200, { check_runs: [ { status: 'queued', name: 'fake_run' }, { status: 'done', name: 'fake_run_2', conclusion: 'fake_conclusion' } ] }) - .get('/repos/wiby-test/fail/commits/wiby-wiby/check-runs') + .get('/repos/wiby-test/fail/commits/wiby-branch-naming/check-runs') .reply(200, { check_runs: [ { status: 'queued', name: 'fail_run' }, { status: 'done', name: 'fail_run_2', conclusion: 'fake_conclusion' } ] }) - .get('/repos/wiby-test/pass/commits/wiby-wiby/check-runs') + .get('/repos/wiby-test/pass/commits/wiby-branch-naming/check-runs') .reply(200, { check_runs: [ { status: 'queued', name: 'pass_run' }, { status: 'done', name: 'pass_run_2', conclusion: 'fake_conclusion' } ] }) - .get('/repos/wiby-test/partial/commits/wiby-wiby/check-runs') + .get('/repos/wiby-test/partial/commits/wiby-branch-naming/check-runs') .reply(200, { check_runs: [ { status: 'queued', name: 'partial_run' }, From e575757d68642dd6bc874b98c8bb7525e2dd7b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Blyz=CC=8Ce=CC=87?= Date: Thu, 18 Mar 2021 15:09:27 +0200 Subject: [PATCH 2/4] test: extract gitFixture.init --- test/clean.js | 20 +++-- test/cli/clean.js | 13 +-- test/cli/result.js | 17 ++-- test/cli/test.js | 13 +-- test/cli/validate.js | 11 ++- test/config.js | 73 ++++++++------- test/fixtures/git.js | 9 ++ test/internals/github.js | 56 ++++++------ test/result.js | 190 ++++++++++++++++++++------------------- test/test.js | 153 ++++++++++++++++--------------- 10 files changed, 301 insertions(+), 254 deletions(-) create mode 100644 test/fixtures/git.js diff --git a/test/clean.js b/test/clean.js index 37b8957..00d2ab3 100644 --- a/test/clean.js +++ b/test/clean.js @@ -3,19 +3,23 @@ require('dotenv').config() const tap = require('tap') const nock = require('nock') + const CONFIG = require('./fixtures/config') +const gitFixture = require('./fixtures/git') + const wiby = require('..') -tap.beforeEach(async () => { - nock.disableNetConnect() -}) +tap.test('wiby.clean()', async (tap) => { + tap.beforeEach(async () => { + nock.disableNetConnect() + gitFixture.init() + }) -tap.afterEach(async () => { - nock.cleanAll() - nock.enableNetConnect() -}) + tap.afterEach(async () => { + nock.cleanAll() + nock.enableNetConnect() + }) -tap.test('wiby.clean()', async (tap) => { tap.test('should check if the wiby branch exists', async (tap) => { nock('https://api.github.com') .get(`/repos/wiby-test/${CONFIG.DEP_REPO}/branches/wiby-branch-naming`) diff --git a/test/cli/clean.js b/test/cli/clean.js index fbd1852..f89320b 100644 --- a/test/cli/clean.js +++ b/test/cli/clean.js @@ -4,14 +4,18 @@ const tap = require('tap') const childProcess = require('child_process') const path = require('path') -const cwd = path.join(__dirname, '..', '..') -const wibyCommand = path.join(cwd, 'bin', 'wiby') +const gitFixture = require('../fixtures/git') + +const wibyCommand = path.join(__dirname, '..', '..', 'bin', 'wiby') const fixturesPath = path.resolve(path.join(__dirname, '..', 'fixtures')) tap.test('clean command', async (tap) => { + tap.beforeEach(async () => { + gitFixture.init() + }) + tap.test('should delete test branch in all configured test modules', async (tap) => { const result = childProcess.execSync(`${wibyCommand} clean`, { - cwd: cwd, env: { ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/clean-command.js` @@ -25,7 +29,6 @@ tap.test('clean command', async (tap) => { tap.test('should delete test branch in the test module at dependent URI', async (tap) => { const result = childProcess.execSync(`${wibyCommand} clean --dependent="https://github.com/wiby-test/fakeRepo"`, { - cwd: cwd, env: { ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/clean-command.js` @@ -37,7 +40,6 @@ tap.test('clean command', async (tap) => { tap.test('should delete all wiby-* branches in all configured test modules', async (tap) => { const result = childProcess.execSync(`${wibyCommand} clean --all`, { - cwd: cwd, env: { ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/clean-command-all.js` @@ -51,7 +53,6 @@ tap.test('clean command', async (tap) => { tap.test('should not delete during dry-run', async (tap) => { const result = childProcess.execSync(`${wibyCommand} clean --dry-run`, { - cwd: cwd, env: { ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/clean-command-dry.js` diff --git a/test/cli/result.js b/test/cli/result.js index 0bc04de..8afabb7 100644 --- a/test/cli/result.js +++ b/test/cli/result.js @@ -5,16 +5,21 @@ const childProcess = require('child_process') const path = require('path') const fs = require('fs') -const cwd = path.join(__dirname, '..', '..') -const wibyCommand = path.join(cwd, 'bin', 'wiby') +const gitFixture = require('../fixtures/git') + +const wibyCommand = path.join(__dirname, '..', '..', 'bin', 'wiby') const fixturesPath = path.resolve(path.join(__dirname, '..', 'fixtures')) const PENDING_RESULT_EXIT_CODE = 64 tap.test('result command', async (tap) => { + tap.beforeEach(async () => { + gitFixture.init() + }) + tap.test('result command should fail when config and dependent provided', async (tap) => { try { - childProcess.execSync(`${wibyCommand} result --config=.wiby.json --dependent="https://github.com/wiby-test/fakeRepo"`, { cwd: cwd }).toString() + childProcess.execSync(`${wibyCommand} result --config=.wiby.json --dependent="https://github.com/wiby-test/fakeRepo"`).toString() tap.fail() } catch (err) { tap.equal(true, err.message.includes('Arguments dependent and config are mutually exclusive')) @@ -30,7 +35,6 @@ tap.test('result command', async (tap) => { try { childProcess.execSync(`${wibyCommand} result --dependent="https://github.com/wiby-test/fakeRepo"`, { - cwd: cwd, env: { ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-positive.js` @@ -53,7 +57,6 @@ tap.test('result command', async (tap) => { try { childProcess.execSync(`${wibyCommand} result`, { - cwd: cwd, env: { ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-positive.js` @@ -67,7 +70,7 @@ tap.test('result command', async (tap) => { } }) - tap.test('result command handles empty response from github.getChecks()', tap => { + tap.test('result command handles empty response from github.getChecks()', (tap) => { const expected = fs.readFileSync( path.join(__dirname, '..', 'fixtures', 'expected-outputs', 'result', 'result-output-single-dependant.md'), 'utf-8' @@ -76,7 +79,6 @@ tap.test('result command', async (tap) => { try { childProcess.execSync(`${wibyCommand} result --dependent="https://github.com/wiby-test/fakeRepo"`, { - cwd: cwd, env: { ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-empty-branch-checks.js` @@ -101,7 +103,6 @@ tap.test('result command', async (tap) => { try { childProcess.execSync(`${wibyCommand} result --dependent="https://github.com/wiby-test/fakeRepo"`, { - cwd: cwd, env: { ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/result-command-positive-checks-failed.js` diff --git a/test/cli/test.js b/test/cli/test.js index 327b739..eed63ef 100644 --- a/test/cli/test.js +++ b/test/cli/test.js @@ -4,14 +4,19 @@ const tap = require('tap') const childProcess = require('child_process') const path = require('path') -const cwd = path.join(__dirname, '..', '..') -const wibyCommand = path.join(cwd, 'bin', 'wiby') +const gitFixture = require('../fixtures/git') + +const wibyCommand = path.join(__dirname, '..', '..', 'bin', 'wiby') const fixturesPath = path.resolve(path.join(__dirname, '..', 'fixtures')) tap.test('test command', async (tap) => { + tap.beforeEach(async () => { + 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"`, { cwd: cwd }).toString() + childProcess.execSync(`${wibyCommand} test --config=.wiby.json --dependent="https://github.com/wiby-test/fakeRepo"`).toString() tap.fail() } catch (err) { tap.equal(true, err.message.includes('Arguments dependent and config are mutually exclusive')) @@ -20,7 +25,6 @@ tap.test('test command', async (tap) => { tap.test('test command should call test module with dependent URI', async (tap) => { const result = childProcess.execSync(`${wibyCommand} test --dependent="https://github.com/wiby-test/fakeRepo"`, { - cwd: cwd, env: { ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/test-command-positive.js` @@ -32,7 +36,6 @@ tap.test('test command', async (tap) => { tap.test('test command should call test module with all deps from .wiby.json', async (tap) => { const result = childProcess.execSync(`${wibyCommand} test`, { - cwd: cwd, env: { ...process.env, NODE_OPTIONS: `-r ${fixturesPath}/http/test-command-positive.js` diff --git a/test/cli/validate.js b/test/cli/validate.js index 923a2d0..29d8db7 100644 --- a/test/cli/validate.js +++ b/test/cli/validate.js @@ -4,12 +4,17 @@ const tap = require('tap') const childProcess = require('child_process') const path = require('path') -const cwd = path.join(__dirname, '..', '..') -const wibyCommand = path.join(cwd, 'bin', 'wiby') +const gitFixture = require('../fixtures/git') + +const wibyCommand = path.join(__dirname, '..', '..', 'bin', 'wiby') tap.test('validate command', async (tap) => { + tap.beforeEach(async () => { + gitFixture.init() + }) + tap.test('should pass on wiby itself', async (tap) => { - childProcess.execSync(`${wibyCommand} validate`, { cwd: cwd }) + childProcess.execSync(`${wibyCommand} validate`) tap.end() }) }) diff --git a/test/config.js b/test/config.js index e50d40a..34208d7 100644 --- a/test/config.js +++ b/test/config.js @@ -2,6 +2,9 @@ const path = require('path') const tap = require('tap') + +const gitFixture = require('./fixtures/git') + const wiby = require('..') const invalidConfigs = { @@ -17,40 +20,46 @@ const validConfigs = [ 'pass-wiby.js' ] -tap.test('should pass with the .wiby.json of the wiby itself', (tap) => { - const normalizedConfig = wiby.validate({}) - tap.strictSame(normalizedConfig, { - dependents: [ - { - repository: 'https://github.com/wiby-test/partial' - }, - { - repository: 'git://github.com/wiby-test/fail' - }, - { - repository: 'git+https://github.com/wiby-test/pass' - } - ] +tap.test('config validation', async (tap) => { + tap.beforeEach(async () => { + gitFixture.init() }) - tap.end() -}) -tap.test('Invalid configs', async (tap) => { - for (const [file, expectedError] of Object.entries(invalidConfigs)) { - tap.test(file, (tap) => { - tap.throws(() => { - wiby.validate({ config: path.join(__dirname, 'fixtures', 'config', file) }) - }, { message: expectedError }) - tap.end() + tap.test('should pass with the .wiby.json of the wiby itself', (tap) => { + const normalizedConfig = wiby.validate({}) + tap.strictSame(normalizedConfig, { + dependents: [ + { + repository: 'https://github.com/wiby-test/partial' + }, + { + repository: 'git://github.com/wiby-test/fail' + }, + { + repository: 'git+https://github.com/wiby-test/pass' + } + ] }) - } -}) + tap.end() + }) -tap.test('Valid configs', async (tap) => { - for (const file of validConfigs) { - tap.test(file, (tap) => { - wiby.validate({ config: path.join(__dirname, 'fixtures', 'config', file) }) - tap.end() - }) - } + tap.test('Invalid configs', async (tap) => { + for (const [file, expectedError] of Object.entries(invalidConfigs)) { + tap.test(file, (tap) => { + tap.throws(() => { + wiby.validate({ config: path.join(__dirname, 'fixtures', 'config', file) }) + }, { message: expectedError }) + tap.end() + }) + } + }) + + tap.test('Valid configs', async (tap) => { + for (const file of validConfigs) { + tap.test(file, (tap) => { + wiby.validate({ config: path.join(__dirname, 'fixtures', 'config', file) }) + tap.end() + }) + } + }) }) diff --git a/test/fixtures/git.js b/test/fixtures/git.js new file mode 100644 index 0000000..9eeddfa --- /dev/null +++ b/test/fixtures/git.js @@ -0,0 +1,9 @@ +'use strict' + +const path = require('path') + +exports.init = function () { + const cwd = path.join(__dirname, '..', '..') + process.chdir(cwd) + return cwd +} diff --git a/test/internals/github.js b/test/internals/github.js index c8ff054..5259016 100644 --- a/test/internals/github.js +++ b/test/internals/github.js @@ -6,36 +6,38 @@ const tap = require('tap') const github = require('../../lib/github') const CONFIG = require('../fixtures/config') -tap.beforeEach(async () => { - nock.disableNetConnect() -}) +tap.test('tests for lib/github.js', async (tap) => { + tap.beforeEach(async () => { + nock.disableNetConnect() + }) -tap.afterEach(async () => { - nock.cleanAll() - nock.enableNetConnect() -}) + tap.afterEach(async () => { + nock.cleanAll() + nock.enableNetConnect() + }) -tap.test('getPackageJson() handles NotFound repository error', async tap => { - nock('https://api.github.com') - .post('/graphql') - .reply(404, { - errors: [ - { type: 'NOT_FOUND' } - ] - }) + tap.test('getPackageJson() handles NotFound repository error', async (tap) => { + nock('https://api.github.com') + .post('/graphql') + .reply(404, { + errors: [ + { type: 'NOT_FOUND' } + ] + }) - tap.rejects( - github.getPackageJson(CONFIG.DEP_ORG, CONFIG.DEP_REPO), - new Error(`Could not find GitHub repository at https://www.github.com/${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}`) - ) -}) + tap.rejects( + github.getPackageJson(CONFIG.DEP_ORG, CONFIG.DEP_REPO), + new Error(`Could not find GitHub repository at https://www.github.com/${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}`) + ) + }) -tap.test('getPackageJson() handles general error', async tap => { - nock('https://api.github.com') - .post('/graphql') - .reply(500) + tap.test('getPackageJson() handles general error', async (tap) => { + nock('https://api.github.com') + .post('/graphql') + .reply(500) - tap.rejects( - github.getPackageJson(CONFIG.DEP_ORG, CONFIG.DEP_REPO) - ) + tap.rejects( + github.getPackageJson(CONFIG.DEP_ORG, CONFIG.DEP_REPO) + ) + }) }) diff --git a/test/result.js b/test/result.js index 4143d3d..c10828a 100644 --- a/test/result.js +++ b/test/result.js @@ -3,102 +3,108 @@ require('dotenv').config() const tap = require('tap') const nock = require('nock') + const checks = require('./fixtures/checks') const CONFIG = require('./fixtures/config') -const wiby = require('..') - -tap.beforeEach(async () => { - nock.disableNetConnect() -}) +const gitFixture = require('./fixtures/git') -tap.afterEach(async () => { - nock.cleanAll() - nock.enableNetConnect() -}) - -tap.test('Test correct status returned from getResultForEachRun', tap => { - tap.equal(wiby.result.getResultForEachRun(checks).toString(), checks.expected.toString()) - tap.end() -}) +const wiby = require('..') -tap.test('result command checks package exists in dependant package.json', tap => { - nock('https://api.github.com') - // get package json - .post('/graphql') - .reply(200, { - data: { - repository: { - object: { - text: JSON.stringify({ - dependencies: { - 'other-package': '*' - } - }) +tap.test('wiby.result()', async (tap) => { + tap.beforeEach(async () => { + nock.disableNetConnect() + gitFixture.init() + }) + + tap.afterEach(async () => { + nock.cleanAll() + nock.enableNetConnect() + }) + + tap.test('Test correct status returned from getResultForEachRun', (tap) => { + tap.equal(wiby.result.getResultForEachRun(checks).toString(), checks.expected.toString()) + tap.end() + }) + + tap.test('result command checks package exists in dependant package.json', (tap) => { + nock('https://api.github.com') + // get package json + .post('/graphql') + .reply(200, { + data: { + repository: { + object: { + text: JSON.stringify({ + dependencies: { + 'other-package': '*' + } + }) + } } } - } - }) - - tap.rejects( - wiby.result({ dependents: [{ repository: `https://www.github.com/${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}` }] }), - new Error(`pkgjs/wiby not found in the package.json of ${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}`) - ) - tap.end() -}) - -tap.test('result() should return correct data object', async tap => { - // mock reall http requests with positive scenario - require('./fixtures/http/result-command-positive') - - const output = await wiby.result({ dependents: [{ repository: 'https://github.com/wiby-test/fakeRepo' }] }) - - tap.equal(output.status, 'pending') - tap.equal(output.results[0].dependent, 'wiby-test/fakeRepo') - tap.equal(output.results[0].status, 'pending') - tap.equal(output.results[0].runs.length, 2) -}) - -tap.test('getOverallStatusForAllRuns() should correctly detect overall status for runs results', async tap => { - const failedCasesPresent = [ - [null, 'failure'], - [null, 'success'], - [null, 'success'] - ] - - const unexpectedCasesPresent = [ - [null, 'unexpectedStatus'], - [null, 'success'], - [null, 'success'] - ] - - const nullCasesPresent = [ - [null, null], - [null, 'success'], - [null, 'success'] - ] - - const pendingCasesPresent = [ - [null, 'pending'], - [null, 'success'], - [null, 'success'] - ] - - const queuedCasesPresent = [ - [null, 'queued'], - [null, 'success'], - [null, 'success'] - ] - - const successCasesPresent = [ - [null, 'success'], - [null, 'success'], - [null, 'success'] - ] - - tap.equal(wiby.result.getOverallStatusForAllRuns(failedCasesPresent), 'failure') - tap.equal(wiby.result.getOverallStatusForAllRuns(unexpectedCasesPresent), 'failure') - tap.equal(wiby.result.getOverallStatusForAllRuns(nullCasesPresent), 'pending') - tap.equal(wiby.result.getOverallStatusForAllRuns(pendingCasesPresent), 'pending') - tap.equal(wiby.result.getOverallStatusForAllRuns(queuedCasesPresent), 'pending') - tap.equal(wiby.result.getOverallStatusForAllRuns(successCasesPresent), 'success') + }) + + tap.rejects( + wiby.result({ dependents: [{ repository: `https://www.github.com/${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}` }] }), + new Error(`pkgjs/wiby not found in the package.json of ${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}`) + ) + tap.end() + }) + + tap.test('result() should return correct data object', async (tap) => { + // mock reall http requests with positive scenario + require('./fixtures/http/result-command-positive') + + const output = await wiby.result({ dependents: [{ repository: 'https://github.com/wiby-test/fakeRepo' }] }) + + tap.equal(output.status, 'pending') + tap.equal(output.results[0].dependent, 'wiby-test/fakeRepo') + tap.equal(output.results[0].status, 'pending') + tap.equal(output.results[0].runs.length, 2) + }) + + tap.test('getOverallStatusForAllRuns() should correctly detect overall status for runs results', async (tap) => { + const failedCasesPresent = [ + [null, 'failure'], + [null, 'success'], + [null, 'success'] + ] + + const unexpectedCasesPresent = [ + [null, 'unexpectedStatus'], + [null, 'success'], + [null, 'success'] + ] + + const nullCasesPresent = [ + [null, null], + [null, 'success'], + [null, 'success'] + ] + + const pendingCasesPresent = [ + [null, 'pending'], + [null, 'success'], + [null, 'success'] + ] + + const queuedCasesPresent = [ + [null, 'queued'], + [null, 'success'], + [null, 'success'] + ] + + const successCasesPresent = [ + [null, 'success'], + [null, 'success'], + [null, 'success'] + ] + + tap.equal(wiby.result.getOverallStatusForAllRuns(failedCasesPresent), 'failure') + tap.equal(wiby.result.getOverallStatusForAllRuns(unexpectedCasesPresent), 'failure') + tap.equal(wiby.result.getOverallStatusForAllRuns(nullCasesPresent), 'pending') + tap.equal(wiby.result.getOverallStatusForAllRuns(pendingCasesPresent), 'pending') + tap.equal(wiby.result.getOverallStatusForAllRuns(queuedCasesPresent), 'pending') + tap.equal(wiby.result.getOverallStatusForAllRuns(successCasesPresent), 'success') + }) }) diff --git a/test/test.js b/test/test.js index 36065b5..ebfb676 100644 --- a/test/test.js +++ b/test/test.js @@ -3,91 +3,98 @@ require('dotenv').config() const tap = require('tap') const nock = require('nock') + const CONFIG = require('./fixtures/config') +const gitFixture = require('./fixtures/git') + const wiby = require('..') -tap.beforeEach(async () => { - nock.disableNetConnect() -}) +tap.test('wiby.test()', async (tap) => { + tap.beforeEach(async () => { + nock.disableNetConnect() + gitFixture.init() + }) -tap.afterEach(async () => { - nock.cleanAll() - nock.enableNetConnect() -}) + tap.afterEach(async () => { + nock.cleanAll() + nock.enableNetConnect() + }) -tap.test('Check patch applied to dependency package.json successfully', tap => { - tap.equal(JSON.stringify(wiby.test.applyPatch(CONFIG.PATCH, CONFIG.PKG_NAME_UNIT, CONFIG.PKGJSON)), JSON.stringify(CONFIG.PATCHED_PKGJSON)) - tap.end() -}) -tap.test('Check patch applied to dev dependency package.json successfully', tap => { - tap.equal(JSON.stringify(wiby.test.applyPatch(CONFIG.DEV_DEP_PATCH, CONFIG.DEV_DEP_PKG_NAME_UNIT, CONFIG.PKGJSON_DEV_DEPS)), JSON.stringify(CONFIG.PATCHED_DEV_DEPS_PKGJSON)) - tap.end() -}) + tap.test('Check patch applied to dependency package.json successfully', (tap) => { + tap.equal(JSON.stringify(wiby.test.applyPatch(CONFIG.PATCH, CONFIG.PKG_NAME_UNIT, CONFIG.PKGJSON)), JSON.stringify(CONFIG.PATCHED_PKGJSON)) + tap.end() + }) -tap.test('Check patch applied to peer dependency package.json successfully', tap => { - tap.equal(JSON.stringify(wiby.test.applyPatch(CONFIG.PEER_DEP_PATCH, CONFIG.DEV_PEER_PKG_NAME_UNIT, CONFIG.PKGJSON_PEER_DEPS)), JSON.stringify(CONFIG.PATCHED_PEER_DEPS_PKGJSON)) - tap.end() -}) + tap.test('Check patch applied to dev dependency package.json successfully', (tap) => { + tap.equal(JSON.stringify(wiby.test.applyPatch(CONFIG.DEV_DEP_PATCH, CONFIG.DEV_DEP_PKG_NAME_UNIT, CONFIG.PKGJSON_DEV_DEPS)), JSON.stringify(CONFIG.PATCHED_DEV_DEPS_PKGJSON)) + tap.end() + }) -tap.test('applyPatch() checks package exists in dependant package.json', tap => { - tap.throws( - function () { - wiby.test.applyPatch( - CONFIG.PATCH, - CONFIG.PKG_NAME_UNIT, - { - dependencies: { - 'other-package': '*' - }, - devDependencies: { - 'further-packages': '*' - }, - peerDependencies: { - 'some-plugin': '*' - }, - optionalDependencies: { - 'some-optional-dep': '*' + tap.test('Check patch applied to peer dependency package.json successfully', (tap) => { + tap.equal(JSON.stringify(wiby.test.applyPatch(CONFIG.PEER_DEP_PATCH, CONFIG.DEV_PEER_PKG_NAME_UNIT, CONFIG.PKGJSON_PEER_DEPS)), JSON.stringify(CONFIG.PATCHED_PEER_DEPS_PKGJSON)) + tap.end() + }) + + tap.test('applyPatch() checks package exists in dependant package.json', (tap) => { + tap.throws( + function () { + wiby.test.applyPatch( + CONFIG.PATCH, + CONFIG.PKG_NAME_UNIT, + { + dependencies: { + 'other-package': '*' + }, + devDependencies: { + 'further-packages': '*' + }, + peerDependencies: { + 'some-plugin': '*' + }, + optionalDependencies: { + 'some-optional-dep': '*' + } } - } - ) - }, - new Error('Dependency not found in package.json') - ) - tap.end() -}) + ) + }, + new Error('Dependency not found in package.json') + ) + tap.end() + }) -tap.test('test command checks package exists in dependant package.json', tap => { - nock('https://api.github.com') - // get package json - .post('/graphql') - .reply(200, { - data: { - repository: { - object: { - text: JSON.stringify({ - dependencies: { - 'other-package': '*' - } - }) + tap.test('test command checks package exists in dependant package.json', (tap) => { + nock('https://api.github.com') + // get package json + .post('/graphql') + .reply(200, { + data: { + repository: { + object: { + text: JSON.stringify({ + dependencies: { + 'other-package': '*' + } + }) + } } } - } - }) - .get('/repos/pkgjs/wiby/commits?per_page=1') - .reply(200, [ - { - sha: 'fake_sha', - commit: { - tree: { - sha: 'fake_sha' + }) + .get('/repos/pkgjs/wiby/commits?per_page=1') + .reply(200, [ + { + sha: 'fake_sha', + commit: { + tree: { + sha: 'fake_sha' + } } } - } - ]) + ]) - tap.rejects( - wiby.test({ dependents: [{ repository: `https://www.github.com/${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}` }] }), - new Error(`pkgjs/wiby not found in the package.json of ${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}`) - ) - tap.end() + tap.rejects( + wiby.test({ dependents: [{ repository: `https://www.github.com/${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}` }] }), + new Error(`pkgjs/wiby not found in the package.json of ${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}`) + ) + tap.end() + }) }) From f20ff12f7dc41abd54c6038ad6bf3a79dc897bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Blyz=CC=8Ce=CC=87?= Date: Thu, 18 Mar 2021 15:39:10 +0200 Subject: [PATCH 3/4] test: create a brand new git repository for each test --- test/clean.js | 6 ++--- test/cli/clean.js | 14 +++++------ test/cli/test.js | 8 +++---- test/fixtures/git.js | 23 ++++++++++++++++--- test/fixtures/http/clean-command-dry.js | 2 +- test/fixtures/http/clean-command.js | 4 ++-- .../result-command-empty-branch-checks.js | 4 ++-- .../result-command-positive-checks-failed.js | 2 +- test/fixtures/http/result-command-positive.js | 8 +++---- 9 files changed, 44 insertions(+), 27 deletions(-) diff --git a/test/clean.js b/test/clean.js index 00d2ab3..b63a2bc 100644 --- a/test/clean.js +++ b/test/clean.js @@ -22,17 +22,17 @@ tap.test('wiby.clean()', async (tap) => { tap.test('should check if the wiby branch exists', async (tap) => { nock('https://api.github.com') - .get(`/repos/wiby-test/${CONFIG.DEP_REPO}/branches/wiby-branch-naming`) + .get(`/repos/wiby-test/${CONFIG.DEP_REPO}/branches/wiby-running-unit-tests`) .reply(404) await wiby.clean({ dependents: [{ repository: `https://www.github.com/${CONFIG.DEP_ORG}/${CONFIG.DEP_REPO}` }] }, {}) - // implied assertion - no DELETE requests expected - we don't need to delete the missing `wiby-branch-naming` branch + // implied assertion - no DELETE requests expected - we don't need to delete the missing `wiby-running-unit-tests` branch }) tap.test('should rethrow when github API inaccessible during branch check', async (tap) => { nock('https://api.github.com') - .get(`/repos/wiby-test/${CONFIG.DEP_REPO}/branches/wiby-branch-naming`) + .get(`/repos/wiby-test/${CONFIG.DEP_REPO}/branches/wiby-running-unit-tests`) .reply(500) await tap.rejects( diff --git a/test/cli/clean.js b/test/cli/clean.js index f89320b..869eb36 100644 --- a/test/cli/clean.js +++ b/test/cli/clean.js @@ -22,9 +22,9 @@ tap.test('clean command', async (tap) => { } }).toString() tap.includes(result, 'Branches deleted:') - tap.includes(result, '- https://github.com/wiby-test/partial: wiby-branch-naming') - tap.includes(result, '- git://github.com/wiby-test/fail: wiby-branch-naming') - tap.includes(result, '- git+https://github.com/wiby-test/pass: wiby-branch-naming') + tap.includes(result, '- https://github.com/wiby-test/partial: wiby-running-unit-tests') + tap.includes(result, '- git://github.com/wiby-test/fail: wiby-running-unit-tests') + tap.includes(result, '- git+https://github.com/wiby-test/pass: wiby-running-unit-tests') }) tap.test('should delete test branch in the test module at dependent URI', async (tap) => { @@ -35,7 +35,7 @@ tap.test('clean command', async (tap) => { } }).toString() tap.includes(result, 'Branches deleted:') - tap.includes(result, '- https://github.com/wiby-test/fakeRepo: wiby-branch-naming') + tap.includes(result, '- https://github.com/wiby-test/fakeRepo: wiby-running-unit-tests') }) tap.test('should delete all wiby-* branches in all configured test modules', async (tap) => { @@ -60,8 +60,8 @@ tap.test('clean command', async (tap) => { }).toString() tap.includes(result, 'Branches to be deleted:') - tap.includes(result, '- https://github.com/wiby-test/partial: wiby-branch-naming') - tap.includes(result, '- git://github.com/wiby-test/fail: wiby-branch-naming') - tap.includes(result, '- git+https://github.com/wiby-test/pass: wiby-branch-naming') + tap.includes(result, '- https://github.com/wiby-test/partial: wiby-running-unit-tests') + tap.includes(result, '- git://github.com/wiby-test/fail: wiby-running-unit-tests') + tap.includes(result, '- git+https://github.com/wiby-test/pass: wiby-running-unit-tests') }) }) diff --git a/test/cli/test.js b/test/cli/test.js index eed63ef..c193be3 100644 --- a/test/cli/test.js +++ b/test/cli/test.js @@ -31,7 +31,7 @@ tap.test('test command', async (tap) => { } }).toString() - tap.includes(result, 'Changes pushed to https://github.com/wiby-test/fakeRepo/blob/wiby-branch-naming/package.json') + tap.includes(result, 'Changes pushed to https://github.com/wiby-test/fakeRepo/blob/wiby-running-unit-tests/package.json') }) tap.test('test command should call test module with all deps from .wiby.json', async (tap) => { @@ -42,8 +42,8 @@ tap.test('test command', async (tap) => { } }).toString() - tap.includes(result, 'Changes pushed to https://github.com/wiby-test/pass/blob/wiby-branch-naming/package.json') - tap.includes(result, 'Changes pushed to https://github.com/wiby-test/fail/blob/wiby-branch-naming/package.json') - tap.includes(result, 'Changes pushed to https://github.com/wiby-test/partial/blob/wiby-branch-naming/package.json') + tap.includes(result, 'Changes pushed to https://github.com/wiby-test/pass/blob/wiby-running-unit-tests/package.json') + tap.includes(result, 'Changes pushed to https://github.com/wiby-test/fail/blob/wiby-running-unit-tests/package.json') + tap.includes(result, 'Changes pushed to https://github.com/wiby-test/partial/blob/wiby-running-unit-tests/package.json') }) }) diff --git a/test/fixtures/git.js b/test/fixtures/git.js index 9eeddfa..50559a3 100644 --- a/test/fixtures/git.js +++ b/test/fixtures/git.js @@ -1,9 +1,26 @@ 'use strict' +const childProcess = require('child_process') +const fs = require('fs') const path = require('path') +const tmp = require('tmp') + +exports.TEST_BRANCH_NAME = 'running-unit-tests' exports.init = function () { - const cwd = path.join(__dirname, '..', '..') - process.chdir(cwd) - return cwd + const gitRepoPath = path.join(__dirname, '..', '..') + + const { name: tmpDir } = tmp.dirSync() + process.chdir(tmpDir) + + childProcess.execSync('git init --initial-branch=running-unit-tests') + + for (const fn of ['package.json', '.wiby.json']) { + fs.copyFileSync(path.join(gitRepoPath, fn), path.join(tmpDir, fn)) + } + + childProcess.execSync('git add .') + childProcess.execSync('git commit -m "test" --no-gpg-sign --no-verify') + + return tmpDir } diff --git a/test/fixtures/http/clean-command-dry.js b/test/fixtures/http/clean-command-dry.js index 417dfb0..7d2b1dd 100644 --- a/test/fixtures/http/clean-command-dry.js +++ b/test/fixtures/http/clean-command-dry.js @@ -9,7 +9,7 @@ nock.disableNetConnect() function nockRepo (nockInstance, repo) { return nockInstance - .get(`/repos/wiby-test/${repo}/branches/wiby-branch-naming`) + .get(`/repos/wiby-test/${repo}/branches/wiby-running-unit-tests`) .reply(200) } diff --git a/test/fixtures/http/clean-command.js b/test/fixtures/http/clean-command.js index 9b31cab..dee62b4 100644 --- a/test/fixtures/http/clean-command.js +++ b/test/fixtures/http/clean-command.js @@ -9,9 +9,9 @@ nock.disableNetConnect() function nockRepo (nockInstance, repo) { return nockInstance - .get(`/repos/wiby-test/${repo}/branches/wiby-branch-naming`) + .get(`/repos/wiby-test/${repo}/branches/wiby-running-unit-tests`) .reply(200) - .delete(`/repos/wiby-test/${repo}/git/refs/heads%2Fwiby-branch-naming`) + .delete(`/repos/wiby-test/${repo}/git/refs/heads%2Fwiby-running-unit-tests`) .reply(200) } diff --git a/test/fixtures/http/result-command-empty-branch-checks.js b/test/fixtures/http/result-command-empty-branch-checks.js index 28a3645..deab11e 100644 --- a/test/fixtures/http/result-command-empty-branch-checks.js +++ b/test/fixtures/http/result-command-empty-branch-checks.js @@ -24,14 +24,14 @@ nock('https://api.github.com') } }) // get check results - .get('/repos/wiby-test/fakeRepo/commits/wiby-branch-naming/check-runs') + .get('/repos/wiby-test/fakeRepo/commits/wiby-running-unit-tests/check-runs') .reply(200, { check_runs: [ // empty checks list ] }) // get checks for ref - .get('/repos/wiby-test/fakeRepo/commits/wiby-branch-naming/statuses') + .get('/repos/wiby-test/fakeRepo/commits/wiby-running-unit-tests/statuses') .reply(200, { check_runs: [ { status: 'queued', name: 'fake_run' }, diff --git a/test/fixtures/http/result-command-positive-checks-failed.js b/test/fixtures/http/result-command-positive-checks-failed.js index 4bf3c9f..e252c80 100644 --- a/test/fixtures/http/result-command-positive-checks-failed.js +++ b/test/fixtures/http/result-command-positive-checks-failed.js @@ -26,7 +26,7 @@ nock('https://api.github.com') } }) // get check results - .get('/repos/wiby-test/fakeRepo/commits/wiby-branch-naming/check-runs') + .get('/repos/wiby-test/fakeRepo/commits/wiby-running-unit-tests/check-runs') .reply(200, { check_runs: [ { status: 'done', name: 'fake_run', conclusion: 'failure' } diff --git a/test/fixtures/http/result-command-positive.js b/test/fixtures/http/result-command-positive.js index dda2a7d..a14b8d9 100644 --- a/test/fixtures/http/result-command-positive.js +++ b/test/fixtures/http/result-command-positive.js @@ -25,28 +25,28 @@ nock('https://api.github.com') } }) // get check results - .get('/repos/wiby-test/fakeRepo/commits/wiby-branch-naming/check-runs') + .get('/repos/wiby-test/fakeRepo/commits/wiby-running-unit-tests/check-runs') .reply(200, { check_runs: [ { status: 'queued', name: 'fake_run' }, { status: 'done', name: 'fake_run_2', conclusion: 'fake_conclusion' } ] }) - .get('/repos/wiby-test/fail/commits/wiby-branch-naming/check-runs') + .get('/repos/wiby-test/fail/commits/wiby-running-unit-tests/check-runs') .reply(200, { check_runs: [ { status: 'queued', name: 'fail_run' }, { status: 'done', name: 'fail_run_2', conclusion: 'fake_conclusion' } ] }) - .get('/repos/wiby-test/pass/commits/wiby-branch-naming/check-runs') + .get('/repos/wiby-test/pass/commits/wiby-running-unit-tests/check-runs') .reply(200, { check_runs: [ { status: 'queued', name: 'pass_run' }, { status: 'done', name: 'pass_run_2', conclusion: 'fake_conclusion' } ] }) - .get('/repos/wiby-test/partial/commits/wiby-branch-naming/check-runs') + .get('/repos/wiby-test/partial/commits/wiby-running-unit-tests/check-runs') .reply(200, { check_runs: [ { status: 'queued', name: 'partial_run' }, From d101fd03a3ff28a0b584e277fee5cfd5fb6f7e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Blyz=CC=8Ce=CC=87?= Date: Thu, 18 Mar 2021 15:47:11 +0200 Subject: [PATCH 4/4] test: set git identity --- test/fixtures/git.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/fixtures/git.js b/test/fixtures/git.js index 50559a3..cbea4fb 100644 --- a/test/fixtures/git.js +++ b/test/fixtures/git.js @@ -14,6 +14,8 @@ exports.init = function () { process.chdir(tmpDir) childProcess.execSync('git init --initial-branch=running-unit-tests') + childProcess.execSync('git config user.email "wiby@example.com"') + childProcess.execSync('git config user.name "Wiby Bot"') for (const fn of ['package.json', '.wiby.json']) { fs.copyFileSync(path.join(gitRepoPath, fn), path.join(tmpDir, fn))