@@ -8,6 +8,8 @@ import path from 'node:path';
88
99import type { RawUniversalConfig , RawGovernanceConfig } from '../types.js' ;
1010import { Source } from '../../resolve.js' ;
11+ import { Config } from '../config.js' ;
12+ import { SpecVersion } from '../../oas-types.js' ;
1113
1214const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
1315
@@ -259,11 +261,14 @@ describe('resolveConfig', () => {
259261 const rootOrApiRawConfig = {
260262 extends : [ 'local-config-with-custom-function.yaml' ] ,
261263 } ;
262- const { plugins } = await resolveConfig ( {
264+ const { plugins, resolvedConfig } = await resolveConfig ( {
263265 rawConfigDocument : makeDocument ( rootOrApiRawConfig , configPath ) ,
264266 configPath,
265267 } ) ;
266268
269+ // instantiate the config to register custom assertions
270+ new Config ( resolvedConfig , { plugins } ) ;
271+
267272 expect ( plugins ) . toBeDefined ( ) ;
268273 expect ( plugins ?. length ) . toBe ( 2 ) ;
269274 expect ( asserts [ 'test-plugin/checkWordsCount' as keyof Asserts ] ) . toBeDefined ( ) ;
@@ -274,33 +279,34 @@ describe('resolveConfig', () => {
274279 extends : [ 'local-config-with-wrong-custom-function.yaml' ] ,
275280 } ;
276281 try {
277- await resolveConfig ( {
282+ const config = await resolveConfig ( {
278283 rawConfigDocument : makeDocument ( rootOrApiRawConfig , configPath ) ,
279284 configPath,
280285 } ) ;
286+ new Config ( config . resolvedConfig , { plugins : config . plugins } ) ;
281287 } catch ( e ) {
282288 expect ( e . message . toString ( ) ) . toContain (
283289 `Plugin ${ colorize . red (
284290 'test-plugin'
285291 ) } doesn't export assertions function with name ${ colorize . red ( 'checkWordsCount2' ) } .`
286292 ) ;
287293 }
288-
289- expect ( asserts [ 'test-plugin/checkWordsCount' as keyof Asserts ] ) . toBeDefined ( ) ;
290294 } ) ;
291295
292296 it ( 'should correctly merge assertions from nested config' , async ( ) => {
293297 const rootOrApiRawConfig = {
294298 extends : [ 'local-config-with-file.yaml' ] ,
295299 } ;
296300
297- const { resolvedConfig, plugins } = await resolveConfig ( {
301+ const { resolvedConfig } = await resolveConfig ( {
298302 rawConfigDocument : makeDocument ( rootOrApiRawConfig , configPath ) ,
299303 configPath,
300304 } ) ;
301305
302- expect ( Array . isArray ( resolvedConfig . rules ?. assertions ) ) . toEqual ( true ) ;
303- expect ( resolvedConfig . rules ?. assertions ) . toMatchObject ( [
306+ const config = new Config ( resolvedConfig , { plugins : [ ] } ) ;
307+
308+ expect ( Array . isArray ( config . rules [ SpecVersion . OAS3_1 ] . assertions ) ) . toEqual ( true ) ;
309+ expect ( config . rules [ SpecVersion . OAS3_1 ] . assertions ) . toMatchObject ( [
304310 {
305311 subject : { type : 'PathItem' , property : 'get' } ,
306312 message : 'Every path item must have a GET operation.' ,
@@ -342,7 +348,7 @@ describe('resolveConfig', () => {
342348 it ( 'should resolve `recommended-strict` ruleset correctly' , async ( ) => {
343349 const expectedStrict = JSON . parse ( JSON . stringify ( recommended ) ) as Omit <
344350 RawGovernanceConfig ,
345- 'extends'
351+ 'extends' | 'plugins'
346352 > ;
347353 for ( const section of Object . values ( expectedStrict ) ) {
348354 for ( let ruleName in section ) {
0 commit comments