11import type { ESLint } from 'eslint' ;
22import { beforeEach , describe , expect , it , vi } from 'vitest' ;
3+ import { ui } from '@code-pushup/utils' ;
34import * as utilsModule from '@code-pushup/utils' ;
45import type { LinterOutput } from './types.js' ;
56import { loadArtifacts } from './utils.js' ;
67
8+ vi . mock ( '@code-pushup/utils' , async ( ) => {
9+ const actual = await vi . importActual ( '@code-pushup/utils' ) ;
10+ return {
11+ ...actual ,
12+ readJsonFile : vi . fn ( ) ,
13+ executeProcess : vi . fn ( ) ,
14+ } ;
15+ } ) ;
16+
17+ vi . mock ( 'glob' , ( ) => ( {
18+ glob : vi . fn ( ( pattern : string ) => Promise . resolve ( [ pattern ] ) ) ,
19+ } ) ) ;
20+
721describe ( 'loadArtifacts' , ( ) => {
822 const readJsonFileSpy = vi . spyOn ( utilsModule , 'readJsonFile' ) ;
923 const executeProcessSpy = vi . spyOn ( utilsModule , 'executeProcess' ) ;
1024
11- // Mock data should be raw ESLint.LintResult[] as that's what ESLint CLI outputs
1225 const mockRawResults1 : ESLint . LintResult [ ] = [
1326 {
1427 filePath : '/test/file1.js' ,
@@ -47,7 +60,6 @@ describe('loadArtifacts', () => {
4760 } ,
4861 ] ;
4962
50- // Expected output after our function wraps raw results in LinterOutput format
5163 const expectedLinterOutput1 : LinterOutput = {
5264 results : mockRawResults1 ,
5365 ruleOptionsPerFile : { } ,
@@ -60,7 +72,7 @@ describe('loadArtifacts', () => {
6072
6173 const artifactsPaths = [ '/path/to/artifact1.json' , '/path/to/artifact2.json' ] ;
6274
63- beforeEach ( async ( ) => {
75+ beforeEach ( ( ) => {
6476 vi . clearAllMocks ( ) ;
6577 executeProcessSpy . mockResolvedValue ( {
6678 stdout : JSON . stringify ( mockRawResults1 ) ,
@@ -80,6 +92,8 @@ describe('loadArtifacts', () => {
8092 expect ( executeProcessSpy ) . not . toHaveBeenCalled ( ) ;
8193 expect ( readJsonFileSpy ) . toHaveBeenCalledTimes ( 1 ) ;
8294 expect ( readJsonFileSpy ) . toHaveBeenNthCalledWith ( 1 , artifactsPaths . at ( 0 ) ) ;
95+
96+ expect ( ui ( ) ) . not . toHaveLogged ( 'log' , expect . stringMatching ( / ^ \$ / ) ) ;
8397 } ) ;
8498
8599 it ( 'should load multiple artifacts without generateArtifactsCommand' , async ( ) => {
@@ -95,6 +109,8 @@ describe('loadArtifacts', () => {
95109 expect ( readJsonFileSpy ) . toHaveBeenCalledTimes ( 2 ) ;
96110 expect ( readJsonFileSpy ) . toHaveBeenNthCalledWith ( 1 , artifactsPaths . at ( 0 ) ) ;
97111 expect ( readJsonFileSpy ) . toHaveBeenNthCalledWith ( 2 , artifactsPaths . at ( 1 ) ) ;
112+
113+ expect ( ui ( ) ) . not . toHaveLogged ( 'log' , expect . stringMatching ( / ^ \$ / ) ) ;
98114 } ) ;
99115
100116 it ( 'should load artifacts with generateArtifactsCommand as string' , async ( ) => {
@@ -112,6 +128,7 @@ describe('loadArtifacts', () => {
112128 command : generateArtifactsCommand ,
113129 ignoreExitCode : true ,
114130 } ) ;
131+ expect ( ui ( ) ) . toHaveLogged ( 'log' , `$ ${ generateArtifactsCommand } ` ) ;
115132 } ) ;
116133
117134 it ( 'should load artifacts with generateArtifactsCommand as object' , async ( ) => {
@@ -131,5 +148,9 @@ describe('loadArtifacts', () => {
131148 ...generateArtifactsCommand ,
132149 ignoreExitCode : true ,
133150 } ) ;
151+ expect ( ui ( ) ) . toHaveLogged (
152+ 'log' ,
153+ '$ nx run-many -t lint --parallel --max-parallel=5' ,
154+ ) ;
134155 } ) ;
135156} ) ;
0 commit comments