Skip to content

Commit b23b6d2

Browse files
committed
test: add semantic prefix replacer example
1 parent 44a942e commit b23b6d2

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

src/tests/drafter/render-template.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,39 @@ describe('render template', () => {
218218
expect(output).toMatchInlineSnapshot('"abc ABC"')
219219
})
220220
})
221+
222+
describe('semantic prefix replacers (issue #1228)', () => {
223+
const multilineBody = [
224+
"# What's Changed",
225+
'',
226+
'* feat(foo): Add feature (#1) @user',
227+
'* fix: Bug fix (#2) @user',
228+
'* ci(deps): Update dependencies (#3) @user',
229+
'* chore: Regular maintenance (#4) @user',
230+
].join('\n')
231+
232+
it('regex using ^ with multiline flag AND accounting for the "* " prefix strips semantic prefixes', () => {
233+
// An alternative that preserves the `^` intent: capture the `* ` prefix
234+
// together and put it back in the replacement.
235+
const output = renderTemplate({
236+
template: multilineBody,
237+
object: {},
238+
replacers: [
239+
{
240+
search: /^(\* )(fix|feat|ci)(\(.+?\))?: /gm,
241+
replace: '$1',
242+
},
243+
],
244+
})
245+
246+
expect(output).toMatchInlineSnapshot(`
247+
"# What's Changed
248+
249+
* Add feature (#1) @user
250+
* Bug fix (#2) @user
251+
* Update dependencies (#3) @user
252+
* chore: Regular maintenance (#4) @user"
253+
`)
254+
})
255+
})
221256
})

0 commit comments

Comments
 (0)