11import type { PluginAnswer } from '@code-pushup/models' ;
2- import { createMockTree } from '@code-pushup/test-utils' ;
2+ import {
3+ createMockCodegenInput ,
4+ createMockTree ,
5+ } from '@code-pushup/test-utils' ;
36import { axeSetupBinding as binding } from './binding.js' ;
47
58const defaultAnswers : Record < string , PluginAnswer > = {
@@ -32,8 +35,7 @@ describe('axeSetupBinding', () => {
3235 describe ( 'generateConfig with categories selected' , ( ) => {
3336 it ( 'should declare plugin as a variable for use in category refs' , async ( ) => {
3437 const { pluginDeclaration } = await binding . generateConfig (
35- defaultAnswers ,
36- createMockTree ( ) ,
38+ createMockCodegenInput ( defaultAnswers , createMockTree ( ) ) ,
3739 ) ;
3840 expect ( pluginDeclaration ) . toStrictEqual ( {
3941 identifier : 'axe' ,
@@ -43,8 +45,7 @@ describe('axeSetupBinding', () => {
4345
4446 it ( 'should import axeGroupRefs helper' , async ( ) => {
4547 const { imports } = await binding . generateConfig (
46- defaultAnswers ,
47- createMockTree ( ) ,
48+ createMockCodegenInput ( defaultAnswers , createMockTree ( ) ) ,
4849 ) ;
4950 expect ( imports ) . toStrictEqual ( [
5051 expect . objectContaining ( { namedImports : [ 'axeGroupRefs' ] } ) ,
@@ -53,8 +54,7 @@ describe('axeSetupBinding', () => {
5354
5455 it ( 'should produce accessibility category with refs expression' , async ( ) => {
5556 const { categories } = await binding . generateConfig (
56- defaultAnswers ,
57- createMockTree ( ) ,
57+ createMockCodegenInput ( defaultAnswers , createMockTree ( ) ) ,
5858 ) ;
5959 expect ( categories ) . toStrictEqual ( [
6060 expect . objectContaining ( {
@@ -68,24 +68,21 @@ describe('axeSetupBinding', () => {
6868 describe ( 'generateConfig without categories selected' , ( ) => {
6969 it ( 'should not declare plugin as a variable' , async ( ) => {
7070 const { pluginDeclaration } = await binding . generateConfig (
71- noCategoryAnswers ,
72- createMockTree ( ) ,
71+ createMockCodegenInput ( noCategoryAnswers , createMockTree ( ) ) ,
7372 ) ;
7473 expect ( pluginDeclaration ) . toBeUndefined ( ) ;
7574 } ) ;
7675
7776 it ( 'should not import axeGroupRefs helper' , async ( ) => {
7877 const { imports } = await binding . generateConfig (
79- noCategoryAnswers ,
80- createMockTree ( ) ,
78+ createMockCodegenInput ( noCategoryAnswers , createMockTree ( ) ) ,
8179 ) ;
8280 expect ( imports [ 0 ] ) . not . toHaveProperty ( 'namedImports' ) ;
8381 } ) ;
8482
8583 it ( 'should not produce categories' , async ( ) => {
8684 const { categories } = await binding . generateConfig (
87- noCategoryAnswers ,
88- createMockTree ( ) ,
85+ createMockCodegenInput ( noCategoryAnswers , createMockTree ( ) ) ,
8986 ) ;
9087 expect ( categories ) . toBeUndefined ( ) ;
9188 } ) ;
@@ -95,8 +92,10 @@ describe('axeSetupBinding', () => {
9592 it ( 'should write setup script file when confirmed' , async ( ) => {
9693 const tree = createMockTree ( ) ;
9794 await binding . generateConfig (
98- { ...defaultAnswers , 'axe.setupScript' : true } ,
99- tree ,
95+ createMockCodegenInput (
96+ { ...defaultAnswers , 'axe.setupScript' : true } ,
97+ tree ,
98+ ) ,
10099 ) ;
101100 expect ( tree . written . get ( './axe-setup.ts' ) ) . toContain (
102101 "import type { Page } from 'playwright-core'" ,
@@ -105,8 +104,10 @@ describe('axeSetupBinding', () => {
105104
106105 it ( 'should include setupScript in plugin call when confirmed' , async ( ) => {
107106 const { pluginDeclaration } = await binding . generateConfig (
108- { ...defaultAnswers , 'axe.setupScript' : true } ,
109- createMockTree ( ) ,
107+ createMockCodegenInput (
108+ { ...defaultAnswers , 'axe.setupScript' : true } ,
109+ createMockTree ( ) ,
110+ ) ,
110111 ) ;
111112 expect ( pluginDeclaration ! . expression ) . toContain (
112113 "setupScript: './axe-setup.ts'" ,
@@ -115,26 +116,32 @@ describe('axeSetupBinding', () => {
115116
116117 it ( 'should not write setup script file when declined' , async ( ) => {
117118 const tree = createMockTree ( ) ;
118- await binding . generateConfig ( defaultAnswers , tree ) ;
119+ await binding . generateConfig (
120+ createMockCodegenInput ( defaultAnswers , tree ) ,
121+ ) ;
119122 expect ( tree . written . size ) . toBe ( 0 ) ;
120123 } ) ;
121124 } ) ;
122125
123126 it ( 'should include non-default preset in plugin call' , async ( ) => {
124127 const { pluginDeclaration } = await binding . generateConfig (
125- { ...defaultAnswers , 'axe.preset' : 'wcag22aa' } ,
126- createMockTree ( ) ,
128+ createMockCodegenInput (
129+ { ...defaultAnswers , 'axe.preset' : 'wcag22aa' } ,
130+ createMockTree ( ) ,
131+ ) ,
127132 ) ;
128133 expect ( pluginDeclaration ! . expression ) . toContain ( "preset: 'wcag22aa'" ) ;
129134 } ) ;
130135
131136 it ( 'should format multiple URLs as array' , async ( ) => {
132137 const { pluginDeclaration } = await binding . generateConfig (
133- {
134- ...defaultAnswers ,
135- 'axe.urls' : 'http://localhost:4200/login, http://localhost:4200/home' ,
136- } ,
137- createMockTree ( ) ,
138+ createMockCodegenInput (
139+ {
140+ ...defaultAnswers ,
141+ 'axe.urls' : 'http://localhost:4200/login, http://localhost:4200/home' ,
142+ } ,
143+ createMockTree ( ) ,
144+ ) ,
138145 ) ;
139146 expect ( pluginDeclaration ! . expression ) . toContain (
140147 "axePlugin(['http://localhost:4200/login', 'http://localhost:4200/home']" ,
0 commit comments