|
| 1 | +import * as execa from 'execa' |
| 2 | +import * as ghGot from 'gh-got' |
| 3 | +import * as readPkg from 'read-pkg' |
| 4 | +import fs from 'fs' |
| 5 | + |
| 6 | +jest.mock('execa') |
| 7 | +jest.mock('fs') |
| 8 | +jest.mock('gh-got') |
| 9 | +jest.mock('read-pkg') |
| 10 | + |
| 11 | +afterEach(jest.resetAllMocks) |
| 12 | + |
| 13 | +it('creates initial github release', async () => { |
| 14 | + jest.spyOn(execa, 'default').mockImplementation((_command, subCommands) => { |
| 15 | + const output = require.requireActual('execa').sync('node', ['--version']) |
| 16 | + |
| 17 | + return (subCommands as string[])[0] === 'rev-list' |
| 18 | + ? { ...output, stdout: '0a1b2c3d4e5f' } |
| 19 | + : output |
| 20 | + }) |
| 21 | + |
| 22 | + jest.spyOn(readPkg, 'default').mockResolvedValue({ |
| 23 | + name: 'a-fixture', |
| 24 | + version: '1.0.0', |
| 25 | + license: 'MIT', |
| 26 | + repository: { |
| 27 | + type: 'git', |
| 28 | + url: 'git+https://github.com/wyze/a-fixture.git', |
| 29 | + }, |
| 30 | + }) |
| 31 | + |
| 32 | + jest.spyOn(ghGot, 'default').mockImplementation() |
| 33 | + |
| 34 | + // Read changelog |
| 35 | + jest |
| 36 | + .spyOn(fs, 'readFile') |
| 37 | + .mockImplementationOnce((_, cb) => |
| 38 | + cb( |
| 39 | + null, |
| 40 | + Buffer.from( |
| 41 | + '## Change Log\n\n### [v1.0.0](https://github.com/wyze/a-fixture/releases/tag/v1.0.0) (2017-05-05)\n\n* A bug fix PR ([@wyze](https://github.com/wyze) in [#1](https://github.com/wyze/a-fixture/pull/1))\n* Initial Commit ([@wyze](https://github.com/wyze) in [65578dd](https://github.com/wyze/a-fixture/commit/65578dd))\n\n' |
| 42 | + ) |
| 43 | + ) |
| 44 | + ) |
| 45 | + |
| 46 | + await require('.').default() |
| 47 | + |
| 48 | + expect(execa).toHaveBeenNthCalledWith(1, 'git', ['push', '--follow-tags']) |
| 49 | + expect(execa).toHaveBeenNthCalledWith(2, 'git', [ |
| 50 | + 'rev-list', |
| 51 | + '--max-parents=0', |
| 52 | + 'HEAD', |
| 53 | + ]) |
| 54 | + expect(ghGot).toHaveBeenCalledWith('repos/wyze/a-fixture/releases', { |
| 55 | + json: { |
| 56 | + body: |
| 57 | + '* A bug fix PR ([@wyze](https://github.com/wyze) in [#1](https://github.com/wyze/a-fixture/pull/1))\n* Initial Commit ([@wyze](https://github.com/wyze) in [65578dd](https://github.com/wyze/a-fixture/commit/65578dd))\n\nhttps://github.com/wyze/a-fixture/compare/0a1b2c3...v1.0.0', |
| 58 | + tag_name: 'v1.0.0', |
| 59 | + }, |
| 60 | + }) |
| 61 | +}) |
| 62 | + |
| 63 | +it('creates second github release', async () => { |
| 64 | + jest.spyOn(execa, 'default').mockImplementation() |
| 65 | + |
| 66 | + jest.spyOn(readPkg, 'default').mockResolvedValue({ |
| 67 | + name: 'a-fixture', |
| 68 | + version: '2.0.0', |
| 69 | + license: 'MIT', |
| 70 | + repository: { |
| 71 | + type: 'git', |
| 72 | + url: 'git+https://github.com/wyze/a-fixture.git', |
| 73 | + }, |
| 74 | + }) |
| 75 | + |
| 76 | + jest.spyOn(ghGot, 'default').mockImplementation() |
| 77 | + |
| 78 | + // Read changelog |
| 79 | + jest |
| 80 | + .spyOn(fs, 'readFile') |
| 81 | + .mockImplementationOnce((_, cb) => |
| 82 | + cb( |
| 83 | + null, |
| 84 | + Buffer.from( |
| 85 | + '## Change Log\n\n### [v2.0.0](https://github.com/wyze/a-fixture/releases/tag/v2.0.0) (2019-05-05)\n\n* A breaking change ([@wyze](https://github.com/wyze) in [#2](https://github.com/wyze/a-fixture/pull/2))\n\n### [v1.0.0](https://github.com/wyze/a-fixture/releases/tag/v1.0.0) (2017-05-05)\n\n* A bug fix PR ([@wyze](https://github.com/wyze) in [#1](https://github.com/wyze/a-fixture/pull/1))\n* Initial Commit ([@wyze](https://github.com/wyze) in [65578dd](https://github.com/wyze/a-fixture/commit/65578dd))\n\n' |
| 86 | + ) |
| 87 | + ) |
| 88 | + ) |
| 89 | + |
| 90 | + await require('.').default() |
| 91 | + |
| 92 | + expect(execa).toHaveBeenCalledWith('git', ['push', '--follow-tags']) |
| 93 | + expect(ghGot).toHaveBeenCalledWith('repos/wyze/a-fixture/releases', { |
| 94 | + json: { |
| 95 | + body: |
| 96 | + '* A breaking change ([@wyze](https://github.com/wyze) in [#2](https://github.com/wyze/a-fixture/pull/2))\n\nhttps://github.com/wyze/a-fixture/compare/v1.0.0...v2.0.0', |
| 97 | + tag_name: 'v2.0.0', |
| 98 | + }, |
| 99 | + }) |
| 100 | +}) |
0 commit comments