11import { test , expect } from "vitest" ;
2+ import type { ParserOptions } from "conventional-commits-parser" ;
3+
24import parse from "./index.js" ;
35
6+ // conventional-changelog-angular@>=9 exposes a single default `createPreset()`
7+ // whose return is typed as `{}`; the parser options live under `.parser`.
8+ const angularParserOpts = async ( ) : Promise < ParserOptions > => {
9+ const { default : createPreset } = await import ( "conventional-changelog-angular" ) ;
10+ const { parser } = ( await createPreset ( ) ) as { parser : ParserOptions } ;
11+ return parser ;
12+ } ;
13+
414test ( "throws when called without params" , async ( ) => {
515 await expect ( ( parse as any ) ( ) ) . rejects . toThrow ( "Expected a raw commit" ) ;
616} ) ;
@@ -143,10 +153,8 @@ test("supports scopes with / and empty parserOpts", async () => {
143153
144154test ( "ignores comments" , async ( ) => {
145155 const message = "type(some/scope): subject\n# some comment" ;
146- // @ts -expect-error -- no typings
147- const changelogOpts = await import ( "conventional-changelog-angular" ) ;
148156 const opts = {
149- ...changelogOpts . parser ,
157+ ...( await angularParserOpts ( ) ) ,
150158 commentChar : "#" ,
151159 } ;
152160 const actual = await parse ( message , undefined , opts ) ;
@@ -158,9 +166,7 @@ test("ignores comments", async () => {
158166
159167test ( "parses inline references in subject and body" , async ( ) => {
160168 const message = "type(some/scope): subject #reference\n\nthings #reference" ;
161- // @ts -expect-error -- no typings
162- const changelogOpts = await import ( "conventional-changelog-angular" ) ;
163- const actual = await parse ( message , undefined , changelogOpts . parser ) ;
169+ const actual = await parse ( message , undefined , await angularParserOpts ( ) ) ;
164170
165171 expect ( actual . subject ) . toBe ( "subject #reference" ) ;
166172 expect ( actual . body ) . toBe ( "" ) ;
@@ -186,10 +192,8 @@ test("parses inline references in subject and body", async () => {
186192
187193test ( "filters comment lines when commentChar is set" , async ( ) => {
188194 const message = "type(scope): subject\n# this is a comment\nbody content" ;
189- // @ts -expect-error -- no typings
190- const changelogOpts = await import ( "conventional-changelog-angular" ) ;
191195 const opts = {
192- ...changelogOpts . parser ,
196+ ...( await angularParserOpts ( ) ) ,
193197 commentChar : "#" ,
194198 } ;
195199 const actual = await parse ( message , undefined , opts ) ;
@@ -235,11 +239,9 @@ test("allows separating -side nodes- by setting parserOpts.fieldPattern", async
235239
236240test ( "parses references leading subject" , async ( ) => {
237241 const message = "#1 some subject" ;
238- // @ts -expect-error -- no typings
239- const opts = await import ( "conventional-changelog-angular" ) ;
240242 const {
241243 references : [ actual ] ,
242- } = await parse ( message , undefined , opts ) ;
244+ } = await parse ( message , undefined , await angularParserOpts ( ) ) ;
243245
244246 expect ( actual . issue ) . toBe ( "1" ) ;
245247} ) ;
0 commit comments