|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const childProcess = require('child_process') |
| 4 | +const fs = require('fs') |
| 5 | +const path = require('path') |
| 6 | +const tap = require('tap') |
| 7 | + |
| 8 | +const gitFixture = require('../fixtures/git') |
| 9 | + |
| 10 | +const wibyCommand = path.join(__dirname, '..', '..', 'bin', 'wiby') |
| 11 | + |
| 12 | +tap.test('github-workflow outdated command', async (tap) => { |
| 13 | + tap.beforeEach(async () => { |
| 14 | + gitFixture.init() |
| 15 | + }) |
| 16 | + |
| 17 | + tap.test('should fail when wiby.yaml is missing', async (tap) => { |
| 18 | + try { |
| 19 | + childProcess.execSync(`${wibyCommand} github-workflow outdated`, { |
| 20 | + env: { |
| 21 | + ...process.env, |
| 22 | + INIT_CWD: '' |
| 23 | + } |
| 24 | + }) |
| 25 | + tap.fail('Should fail before reaching here') |
| 26 | + } catch (err) { |
| 27 | + tap.include(err.message, '/.github/workflows/wiby.yaml not found. Use `wiby github-workflow install` to install it.') |
| 28 | + } |
| 29 | + }) |
| 30 | + |
| 31 | + tap.test('should fail when wiby.yaml has the wrong contents', async (tap) => { |
| 32 | + const workflowsPath = path.join(process.cwd(), '.github', 'workflows') |
| 33 | + const wibyYamlPath = path.join(workflowsPath, 'wiby.yaml') |
| 34 | + const contentsBefore = 'should be overwritten with new version' |
| 35 | + |
| 36 | + fs.mkdirSync(workflowsPath, { recursive: true }) |
| 37 | + fs.writeFileSync(wibyYamlPath, contentsBefore) |
| 38 | + |
| 39 | + try { |
| 40 | + childProcess.execSync(`${wibyCommand} github-workflow outdated`, { |
| 41 | + env: { |
| 42 | + ...process.env, |
| 43 | + INIT_CWD: '' |
| 44 | + } |
| 45 | + }) |
| 46 | + tap.fail('Should fail before reaching here') |
| 47 | + } catch (err) { |
| 48 | + tap.include(err.message, '/.github/workflows/wiby.yaml is not the same as the bundled version') |
| 49 | + } |
| 50 | + }) |
| 51 | + |
| 52 | + tap.test('should pass when wiby.yaml has the same contents', async (tap) => { |
| 53 | + const originalContents = fs.readFileSync(path.join(__dirname, '..', '..', '.github', 'workflows', 'wiby.yaml')) |
| 54 | + const workflowsPath = path.join(process.cwd(), '.github', 'workflows') |
| 55 | + const wibyYamlPath = path.join(workflowsPath, 'wiby.yaml') |
| 56 | + |
| 57 | + fs.mkdirSync(workflowsPath, { recursive: true }) |
| 58 | + fs.writeFileSync(wibyYamlPath, originalContents) |
| 59 | + |
| 60 | + const result = childProcess.execSync(`${wibyCommand} github-workflow outdated`, { |
| 61 | + env: { |
| 62 | + ...process.env, |
| 63 | + INIT_CWD: '' |
| 64 | + } |
| 65 | + }).toString() |
| 66 | + |
| 67 | + tap.include(result, 'wiby.yaml is the same as the bundled version.') |
| 68 | + }) |
| 69 | + |
| 70 | + tap.test('should pass when wiby.yaml has the same contents in $INIT_CWD', async (tap) => { |
| 71 | + const originalContents = fs.readFileSync(path.join(__dirname, '..', '..', '.github', 'workflows', 'wiby.yaml')) |
| 72 | + const initCwd = path.join(process.cwd(), 'some-other-place') |
| 73 | + const workflowsPath = path.join(initCwd, '.github', 'workflows') |
| 74 | + const wibyYamlPath = path.join(workflowsPath, 'wiby.yaml') |
| 75 | + |
| 76 | + fs.mkdirSync(workflowsPath, { recursive: true }) |
| 77 | + fs.writeFileSync(wibyYamlPath, originalContents) |
| 78 | + |
| 79 | + const result = childProcess.execSync(`${wibyCommand} github-workflow outdated`, { |
| 80 | + env: { |
| 81 | + ...process.env, |
| 82 | + INIT_CWD: initCwd |
| 83 | + } |
| 84 | + }).toString() |
| 85 | + |
| 86 | + tap.include(result, 'wiby.yaml is the same as the bundled version.') |
| 87 | + }) |
| 88 | +}) |
0 commit comments