@@ -10,6 +10,8 @@ import {
1010 AuditOutputs ,
1111 AuditReport ,
1212 UploadConfig ,
13+ AuditOutput ,
14+ Issue ,
1315} from '../src/index' ;
1416
1517const __pluginSlug__ = 'mock-plugin-slug' ;
@@ -77,7 +79,7 @@ export function mockAuditConfig(opt?: { auditSlug?: string }): Audit {
7779 title : auditSlug + ' title' ,
7880 description : 'audit description' ,
7981 docsUrl : 'http://www.my-docs.dev' ,
80- } ;
82+ } satisfies Required < Audit > ;
8183}
8284
8385export function mockPersistConfig ( opt ?: Partial < PersistConfig > ) : PersistConfig {
@@ -87,7 +89,7 @@ export function mockPersistConfig(opt?: Partial<PersistConfig>): PersistConfig {
8789 return {
8890 outputPath,
8991 format,
90- } ;
92+ } satisfies Required < PersistConfig > ;
9193}
9294
9395export function mockGroupConfig ( opt ?: {
@@ -113,7 +115,7 @@ export function mockGroupConfig(opt?: {
113115 weight : randWeight ( ) ,
114116 } ,
115117 ] ,
116- } ;
118+ } satisfies Required < AuditGroup > ;
117119}
118120
119121export function mockCategory ( opt ?: {
@@ -172,8 +174,9 @@ export function mockCategory(opt?: {
172174 . map ( word => word . slice ( 0 , 1 ) . toUpperCase ( ) + word . slice ( 1 ) )
173175 . join ( ' ' ) } `,
174176 description : `This is the category description of ${ categorySlug } . Enjoy dummy text and data to the full.` ,
177+ docsUrl : 'https://category.dev?' + categorySlug ,
175178 refs : categoryAuditRefs . concat ( categoryGroupRefs ) ,
176- } ;
179+ } satisfies Required < CategoryConfig > ;
177180}
178181
179182export function mockReport ( opt ?: {
@@ -203,28 +206,25 @@ export function mockPluginReport(opt?: {
203206 date : new Date ( ) . toDateString ( ) ,
204207 duration : randDuration ( ) ,
205208 slug : pluginSlug ,
206- docsUrl : `http://plugin.io/docs/${ pluginSlug } ` ,
207209 title : 'Mock plugin Name' ,
210+ description : 'Plugin description of ' + pluginSlug ,
211+ docsUrl : `http://plugin.io/docs/${ pluginSlug } ` ,
208212 icon : 'socket' ,
209213 audits : Array . isArray ( auditSlug )
210214 ? auditSlug . map ( a => mockAuditReport ( { auditSlug : a } ) )
211215 : [ mockAuditReport ( { auditSlug } ) ] ,
212- } ;
216+ } satisfies Required < PluginReport > ;
213217}
214218
215219export function mockAuditReport ( opt ?: { auditSlug : string } ) : AuditReport {
216220 let { auditSlug } = opt || { } ;
217221 auditSlug = auditSlug || __auditSlug__ ;
218222 return {
219- slug : auditSlug ,
220- displayValue : 'mocked value' ,
221- value : Math . floor ( Math . random ( ) * 100 ) ,
222- score : Math . round ( Math . random ( ) ) ,
223- title : auditSlug ,
224- } ;
223+ ...( mockAuditOutput ( { auditSlug } ) as Required < AuditOutput > ) ,
224+ } satisfies Required < AuditReport > ;
225225}
226226
227- export function mockConfig ( opt ?: {
227+ export function mockCoreConfig ( opt ?: {
228228 outputPath ?: string ;
229229 categorySlug ?: string | string [ ] ;
230230 pluginSlug ?: string | string [ ] ;
@@ -235,6 +235,7 @@ export function mockConfig(opt?: {
235235 opt || { } ;
236236 return {
237237 persist : mockPersistConfig ( { outputPath } ) ,
238+ upload : mockUploadConfig ( ) ,
238239 plugins : Array . isArray ( pluginSlug )
239240 ? pluginSlug . map ( slug =>
240241 mockPluginConfig ( { pluginSlug : slug , auditSlug, groupSlug } ) ,
@@ -245,7 +246,7 @@ export function mockConfig(opt?: {
245246 mockCategory ( { categorySlug : slug , auditSlug, groupSlug } ) ,
246247 )
247248 : [ mockCategory ( { categorySlug, auditSlug, groupSlug } ) ] ,
248- } ;
249+ } satisfies Required < CoreConfig > ;
249250}
250251
251252export function mockUploadConfig ( opt ?: Partial < UploadConfig > ) : UploadConfig {
@@ -261,23 +262,40 @@ export function mockAuditOutputs(opt?: {
261262} ) : AuditOutputs {
262263 let { auditSlug } = opt || { } ;
263264 auditSlug = auditSlug || 'mock-audit-output-slug' ;
264- const audits = Array . isArray ( auditSlug )
265- ? auditSlug . map ( ( slug , idx ) => ( {
266- slug,
267- title : 'Title of ' + slug ,
268- value : idx ,
269- displayValue : '' ,
270- score : 0 ,
271- } ) )
272- : [
273- {
274- slug : auditSlug ,
275- title : 'Title of ' + auditSlug ,
276- value : 12 ,
277- displayValue : '' ,
278- score : 0 ,
279- } ,
280- ] ;
265+ return Array . isArray ( auditSlug )
266+ ? auditSlug . map ( ( slug , idx ) => mockAuditOutput ( { auditSlug : slug } ) )
267+ : [ mockAuditOutput ( { auditSlug } ) ] ;
268+ }
269+
270+ export function mockAuditOutput ( opt ?: { auditSlug : string } ) : AuditOutput {
271+ let { auditSlug } = opt || { } ;
272+ auditSlug = auditSlug || 'mock-audit-output-slug' ;
273+ return {
274+ slug : auditSlug ,
275+ title : 'Title of ' + auditSlug ,
276+ description : 'Description of ' + auditSlug ,
277+ docsUrl : 'https://audit.dev?' + auditSlug ,
278+ details : {
279+ issues : [ mockIssueOutput ( ) ] ,
280+ } ,
281+ value : 12 ,
282+ displayValue : '' ,
283+ score : 0 ,
284+ } satisfies Required < AuditOutput > ;
285+ }
281286
282- return audits ;
287+ export function mockIssueOutput ( ) : Issue {
288+ return {
289+ severity : 'error' ,
290+ message : '' ,
291+ source : {
292+ file : 'the-file.ts' ,
293+ position : {
294+ startLine : 1 ,
295+ startColumn : 2 ,
296+ endLine : 3 ,
297+ endColumn : 4 ,
298+ } ,
299+ } ,
300+ } satisfies Required < Issue > ;
283301}
0 commit comments