fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at feat/use-query-options 245 lines 7.8 kB view raw
1import type * as getGitHubInfo from '@changesets/get-github-info'; 2import parse from '@changesets/parse'; 3import type { ModCompWithPackage, NewChangesetWithCommit, VersionType } from '@changesets/types'; 4import { describe, expect, it, vi } from 'vitest'; 5 6import changelog from '../.changeset/changelog.js'; 7 8type GetGitHubInfo = typeof getGitHubInfo; 9 10const data = { 11 commit: 'a085003', 12 pull: 1613, 13 repo: 'hey-api/openapi-ts', 14 user: 'someone', 15}; 16 17vi.mock( 18 '@changesets/get-github-info', 19 (): GetGitHubInfo => ({ 20 async getInfo({ commit, repo }) { 21 const { pull, user } = data; 22 const links = { 23 commit: `[\`${commit}\`](https://github.com/${repo}/commit/${commit})`, 24 pull: `[#${pull}](https://github.com/${repo}/pull/${pull})`, 25 user: `[@${user}](https://github.com/${user})`, 26 }; 27 return { 28 links, 29 pull, 30 user, 31 }; 32 }, 33 async getInfoFromPullRequest({ pull, repo }) { 34 const { commit, user } = data; 35 const links = { 36 commit: `[\`${commit}\`](https://github.com/${repo}/commit/${commit})`, 37 pull: `[#${pull}](https://github.com/${repo}/pull/${pull})`, 38 user: `[@${user}](https://github.com/${user})`, 39 }; 40 return { 41 commit, 42 links, 43 user, 44 }; 45 }, 46 }), 47); 48 49const getChangeset = ( 50 content: string, 51 commit: string | undefined, 52): [NewChangesetWithCommit, VersionType, null | Record<string, any>] => [ 53 { 54 ...parse( 55 `--- 56pkg: "minor" 57--- 58 59something 60${content} 61`, 62 ), 63 commit, 64 id: 'some-id', 65 }, 66 'minor', 67 { repo: data.repo }, 68]; 69 70describe('changelog', () => { 71 it('formats dependency release lines', async () => { 72 const changesets: NewChangesetWithCommit[] = [ 73 { 74 commit: 'abc123', 75 id: 'fake-id', 76 releases: [], 77 summary: 'update deps', 78 }, 79 ]; 80 const deps: ModCompWithPackage[] = [ 81 { 82 changesets: ['fake-id'], 83 dir: '/fake/path', 84 name: '@hey-api/openapi-ts', 85 newVersion: '0.0.2', 86 oldVersion: '0.0.1', 87 packageJson: { 88 name: '@hey-api/openapi-ts', 89 version: '0.0.1', 90 }, 91 type: 'patch', 92 }, 93 ]; 94 95 const line = await changelog.getDependencyReleaseLine(changesets, deps, { 96 repo: 'org/repo', 97 }); 98 99 expect(line).toEqual('### Updated Dependencies:\n - @hey-api/openapi-ts@0.0.2'); 100 }); 101 102 it('formats regular release lines', async () => { 103 const changeset: NewChangesetWithCommit = { 104 commit: 'abc123', 105 id: 'fake-id', 106 releases: [], 107 summary: 'Fixed bug in parser', 108 }; 109 110 const line = await changelog.getReleaseLine(changeset, 'patch', { 111 repo: 'org/repo', 112 }); 113 114 expect(line).toContain('Fixed bug in parser'); 115 expect(line).toContain('abc123'); 116 }); 117 118 it('with multiple authors', async () => { 119 expect( 120 await changelog.getReleaseLine( 121 ...getChangeset(['author: @one', 'author: @two'].join('\n'), data.commit), 122 ), 123 ).toEqual( 124 `\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@one](https://github.com/one), [@two](https://github.com/two)`, 125 ); 126 }); 127 128 it('places metadata on the first line and preserves markdown code blocks', async () => { 129 const summary = [ 130 'refactor(config): replace `off` with null to disable options', 131 '', 132 '### Updated `output` options', 133 '', 134 'We made the `output` configuration more consistent by using `null` to represent disabled options. [This change](https://heyapi.dev/openapi-ts/migrating#updated-output-options) does not affect boolean options.', 135 '', 136 '```js', 137 'export default {', 138 ' input: "hey-api/backend", // sign up at app.heyapi.dev', 139 ' output: {', 140 ' format: null,', 141 ' lint: null,', 142 ' path: "src/client",', 143 ' tsConfigPath: null,', 144 ' },', 145 '};', 146 '```', 147 ].join('\n'); 148 const changeset = { 149 commit: 'fcdd73b816d74babf47e6a1f46032f5b8ebb4b48', 150 id: 'fake-id', 151 releases: [], 152 summary, 153 }; 154 const line = await changelog.getReleaseLine(changeset, 'minor', { 155 repo: 'hey-api/openapi-ts', 156 }); 157 // Metadata should be on the first line 158 expect(line).toMatch( 159 /^\n- refactor\(config\): replace `off` with null to disable options \(\[#1613\]\(https:\/\/github.com\/hey-api\/openapi-ts\/pull\/1613\)\) \(\[`fcdd73b`\]\(https:\/\/github.com\/hey-api\/openapi-ts\/commit\/fcdd73b816d74babf47e6a1f46032f5b8ebb4b48\)\) by \[@someone\]\(https:\/\/github.com\/someone\)/, 160 ); 161 // Should not contain quadruple backticks 162 expect(line).not.toContain('````'); 163 // Should contain a markdown code block 164 expect(line).toContain('```js\nexport default {'); 165 expect(line).toContain(' input: "hey-api/backend", // sign up at app.heyapi.dev'); 166 expect(line).toContain(' output: {'); 167 expect(line).toContain(' format: null,'); 168 expect(line).toContain(' lint: null,'); 169 expect(line).toContain(' path: "src/client",'); 170 expect(line).toContain(' tsConfigPath: null,'); 171 expect(line).toContain(' },'); 172 expect(line).toContain('};'); 173 expect(line).toContain('```'); 174 }); 175 176 it('converts multiple code blocks and preserves non-code content', async () => { 177 const summary = [ 178 'feat: add foo', 179 '', 180 '```js', 181 'console.log(1);', 182 '```', 183 '', 184 'Some text.', 185 '', 186 '```ts', 187 'console.log(2);', 188 '```', 189 ].join('\n'); 190 const changeset = { 191 commit: 'abc123', 192 id: 'fake-id', 193 releases: [], 194 summary, 195 }; 196 const line = await changelog.getReleaseLine(changeset, 'minor', { 197 repo: 'hey-api/openapi-ts', 198 }); 199 expect(line).toContain('```js\nconsole.log(1);\n```'); 200 expect(line).toContain('```ts\nconsole.log(2);\n```'); 201 expect(line).toContain('Some text.'); 202 }); 203 204 describe.each(['author', 'user'])('override author with %s keyword', (keyword) => { 205 it.each(['with @', 'without @'])('%s', async (kind) => { 206 expect( 207 await changelog.getReleaseLine( 208 ...getChangeset(`${keyword}: ${kind === 'with @' ? '@' : ''}other`, data.commit), 209 ), 210 ).toEqual( 211 `\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@other](https://github.com/other)`, 212 ); 213 }); 214 }); 215 216 describe.each([data.commit, 'wrongcommit', undefined])( 217 'with commit from changeset of %s', 218 (commitFromChangeset) => { 219 describe.each(['pr', 'pull request', 'pull'])('override pr with %s keyword', (keyword) => { 220 it.each(['with #', 'without #'])('%s', async (kind) => { 221 expect( 222 await changelog.getReleaseLine( 223 ...getChangeset( 224 `${keyword}: ${kind === 'with #' ? '#' : ''}${data.pull}`, 225 commitFromChangeset, 226 ), 227 ), 228 ).toEqual( 229 `\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@someone](https://github.com/someone)`, 230 ); 231 }); 232 }); 233 234 it('override commit with commit keyword', async () => { 235 expect( 236 await changelog.getReleaseLine( 237 ...getChangeset(`commit: ${data.commit}`, commitFromChangeset), 238 ), 239 ).toEqual( 240 `\n- something ([#1613](https://github.com/hey-api/openapi-ts/pull/1613)) ([\`a085003\`](https://github.com/hey-api/openapi-ts/commit/a085003)) by [@someone](https://github.com/someone)`, 241 ); 242 }); 243 }, 244 ); 245});