From c6fd312cbadd26483eebdb6602654cc354d774a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Wed, 14 Aug 2024 10:20:21 +0800 Subject: [PATCH] test: wip --- src/renderer.ts | 8 +- test/__snapshots__/regexp.test.ts.snap | 159 +++++++++++++++++++++++ test/__snapshots__/renderer.test.ts.snap | 103 --------------- test/fixtures/changelog.ts | 3 +- test/fixtures/releaseNotes.ts | 7 +- test/regexp.test.ts | 19 +++ test/renderer.test.ts | 18 --- 7 files changed, 186 insertions(+), 131 deletions(-) create mode 100644 test/__snapshots__/regexp.test.ts.snap delete mode 100644 test/__snapshots__/renderer.test.ts.snap create mode 100644 test/regexp.test.ts delete mode 100644 test/renderer.test.ts diff --git a/src/renderer.ts b/src/renderer.ts index 95dcd27..4d7c839 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -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 } @@ -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}`) diff --git a/test/__snapshots__/regexp.test.ts.snap b/test/__snapshots__/regexp.test.ts.snap new file mode 100644 index 0000000..ce24d77 --- /dev/null +++ b/test/__snapshots__/regexp.test.ts.snap @@ -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", + ], +] +`; diff --git a/test/__snapshots__/renderer.test.ts.snap b/test/__snapshots__/renderer.test.ts.snap deleted file mode 100644 index 5dfd7fc..0000000 --- a/test/__snapshots__/renderer.test.ts.snap +++ /dev/null @@ -1,103 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`renderer > : changelogReg 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[`renderer > : getPullNumber 1`] = ` -[ - 7, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 23, - 25, - 26, - 27, - 28, -] -`; diff --git a/test/fixtures/changelog.ts b/test/fixtures/changelog.ts index 8162aef..a99bcb2 100644 --- a/test/fixtures/changelog.ts +++ b/test/fixtures/changelog.ts @@ -1,4 +1,4 @@ -export const changelog = ` +const changelog = ` - fix(A): a bug fix - hotfix(A): a bug fix - bug(A): a bug fix @@ -13,3 +13,4 @@ export const changelog = ` - break(g): a minor fix - break(H H): a major update ` +export default changelog diff --git a/test/fixtures/releaseNotes.ts b/test/fixtures/releaseNotes.ts index 3a0d9d4..a48ef0f 100644 --- a/test/fixtures/releaseNotes.ts +++ b/test/fixtures/releaseNotes.ts @@ -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 @@ -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 diff --git a/test/regexp.test.ts b/test/regexp.test.ts new file mode 100644 index 0000000..38063ef --- /dev/null +++ b/test/regexp.test.ts @@ -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() + }) +}) diff --git a/test/renderer.test.ts b/test/renderer.test.ts deleted file mode 100644 index 76bebd4..0000000 --- a/test/renderer.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { ChangelogReg, getPullNumbers } from '../src/renderer' -import { changelog } from './fixtures/changelog' -import { releaseNotes } from './fixtures/releaseNotes' - -describe('renderer', () => { - it(': changelogReg', () => { - const result = changelog.matchAll(ChangelogReg) - const arr = [...result] - expect(arr.length).toBe(13) - expect(arr).toMatchSnapshot() - }) - it(': getPullNumber', () => { - const result = getPullNumbers(releaseNotes.body) - expect(result.length).toBe(14) - expect(result).toMatchSnapshot() - }) -})