Skip to content

Commit

Permalink
test: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 committed Aug 14, 2024
1 parent 8d86c66 commit c6fd312
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 131 deletions.
8 changes: 4 additions & 4 deletions src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const skipChangelogLabel = ['skip-changelog']
const fixLabel = ['fix', 'bug', 'hotfix']
const breakingLabel = ['break', 'breaking', 'breaking changes']
const featureLabel = ['feature', 'feat', 'enhancement']
export const ChangelogReg = /-\s([A-Z]+)(?:\(([A-Z\s]*)\))?:\s(.+)/gi
export const PullNumberReg = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)\s/g
export const CHANGELOG_REG = /-\s([A-Z]+)(?:\(([A-Z\s]*)\))?:\s(.+)/gi
export const PULL_NUMBER_REG = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)\s/g
export function getPullNumbers(body: string) {
const arr = [...body.matchAll(PullNumberReg)]
const arr = [...body.matchAll(PULL_NUMBER_REG)]

return arr.map(n => Number(n[1])) // pr number list
}
Expand Down Expand Up @@ -52,7 +52,7 @@ export function renderMarkdown(pullRequestList: PullsData[]) {
}

if (pr.body.includes('### 📝 更新日志')) {
const arr = [...pr.body.matchAll(ChangelogReg)]
const arr = [...pr.body.matchAll(CHANGELOG_REG)]

if (arr.length === 0) {
info(`没有找到任何一条日志内容 number:${pr.number}, body:${pr.body}`)
Expand Down
159 changes: 159 additions & 0 deletions test/__snapshots__/regexp.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`regexp > : CHANGELOG_REG 1`] = `
[
[
"- fix(A): a bug fix",
"fix",
"A",
"a bug fix",
],
[
"- hotfix(A): a bug fix",
"hotfix",
"A",
"a bug fix",
],
[
"- bug(A): a bug fix",
"bug",
"A",
"a bug fix",
],
[
"- feat(B): a feature",
"feat",
"B",
"a feature",
],
[
"- feature(B): a feature",
"feature",
"B",
"a feature",
],
[
"- enhancement(B): a feature",
"enhancement",
"B",
"a feature",
],
[
"- break(C): a major update",
"break",
"C",
"a major update",
],
[
"- breaking(C): a major update",
"breaking",
"C",
"a major update",
],
[
"- feat(D): a feature",
"feat",
"D",
"a feature",
],
[
"- docs(): a doc change",
"docs",
"",
"a doc change",
],
[
"- chore: a chore",
"chore",
undefined,
"a chore",
],
[
"- break(g): a minor fix",
"break",
"g",
"a minor fix",
],
[
"- break(H H): a major update",
"break",
"H H",
"a major update",
],
]
`;

exports[`regexp > : PULL_NUMBER_REG 1`] = `
[
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/7
",
"7",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/14
",
"14",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/15
",
"15",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/16
",
"16",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/17
",
"17",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/18
",
"18",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/19
",
"19",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/20
",
"20",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/21
",
"21",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/23
",
"23",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/25
",
"25",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/26
",
"26",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/27
",
"27",
],
[
"in https://github.com/TDesignOteam/tdesign-changelog-action/pull/28
",
"28",
],
]
`;
103 changes: 0 additions & 103 deletions test/__snapshots__/renderer.test.ts.snap

This file was deleted.

3 changes: 2 additions & 1 deletion test/fixtures/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const changelog = `
const changelog = `
- fix(A): a bug fix
- hotfix(A): a bug fix
- bug(A): a bug fix
Expand All @@ -13,3 +13,4 @@ export const changelog = `
- break(g): a minor fix
- break(H H): a major update
`
export default changelog
7 changes: 2 additions & 5 deletions test/fixtures/releaseNotes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const body = `
const releaseNotes = `
## What's Changed
* feat: get latest tag by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/7
* ci: tdesign-tag-action by @liweijie0812 in https://github.com/TDesignOteam/tdesign-changelog-action/pull/14
Expand All @@ -18,7 +18,4 @@ const body = `
**Full Changelog**: https://github.com/TDesignOteam/tdesign-changelog-action/compare/0.0.1...0.2.0
`
export const releaseNotes = {
name: '0.2.0',
body,
}
export default releaseNotes
19 changes: 19 additions & 0 deletions test/regexp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expect, it } from 'vitest'
import { CHANGELOG_REG, PULL_NUMBER_REG } from '../src/renderer'
import changelog from './fixtures/changelog'
import releaseNotes from './fixtures/releaseNotes'

describe('regexp', () => {
it(': CHANGELOG_REG', () => {
const result = changelog.matchAll(CHANGELOG_REG)
const arr = [...result]
expect(arr.length).toBe(13)
expect(arr).toMatchSnapshot()
})
it(': PULL_NUMBER_REG', () => {
const result = releaseNotes.matchAll(PULL_NUMBER_REG)
const arr = [...result]
expect(arr.length).toBe(14)
expect(arr).toMatchSnapshot()
})
})
18 changes: 0 additions & 18 deletions test/renderer.test.ts

This file was deleted.

0 comments on commit c6fd312

Please sign in to comment.