@@ -4,6 +4,7 @@ const nock = require('nock');
44const io = require ( '@actions/io' ) ;
55const os = require ( 'os' ) ;
66const fs = require ( 'fs' ) ;
7+ const exec = require ( '@actions/exec' ) ;
78const util = require ( '../lib/util' ) ;
89
910const cachePath = path . join ( __dirname , 'CACHE' )
@@ -13,19 +14,26 @@ process.env['RUNNER_TEMP'] = tempPath
1314process . env [ 'RUNNER_TOOL_CACHE' ] = cachePath
1415
1516describe ( 'pmd-github-action-util' , function ( ) {
16- beforeAll ( function ( ) {
17+ let platformMock ;
18+ let execMock ;
19+
20+ beforeAll ( function ( ) {
1721 setGlobal ( 'TEST_DOWNLOAD_TOOL_RETRY_MIN_SECONDS' , 0 )
1822 setGlobal ( 'TEST_DOWNLOAD_TOOL_RETRY_MAX_SECONDS' , 0 )
1923 } )
2024
2125 beforeEach ( async function ( ) {
26+ platformMock = jest . spyOn ( os , 'platform' ) ;
27+ execMock = jest . spyOn ( exec , 'getExecOutput' ) ;
2228 await io . rmRF ( cachePath )
2329 await io . rmRF ( tempPath )
2430 await io . mkdirP ( cachePath )
2531 await io . mkdirP ( tempPath )
2632 } )
2733
2834 afterEach ( function ( ) {
35+ platformMock . mockRestore ( ) ;
36+ execMock . mockRestore ( ) ;
2937 } )
3038
3139 afterAll ( async function ( ) {
@@ -136,11 +144,38 @@ describe('pmd-github-action-util', function () {
136144 . reply ( 503 , 'Test Internal Server Error' ) ;
137145
138146 expect ( ( ) => util . downloadPmd ( 'latest' , 'my_test_token' ) ) . rejects . toThrow ( ) ;
139- } ) ;
147+ } )
140148
141149 it ( 'failure while executing PMD' , async ( ) => {
142150 expect ( ( ) => util . executePmd ( { path : 'non-existing-pmd-path' } , '.' , 'ruleset.xml' , 'sarif' , 'pmd-report.sarif' ) ) . rejects . toThrow ( ) ;
143- } ) ;
151+ } )
152+
153+ it ( 'can execute PMD win32' , async ( ) => {
154+ platformMock . mockReturnValueOnce ( 'win32' ) ;
155+ execMock . mockReturnValueOnce ( { exitCode : 0 , stdout : '' , stderr : '' } ) ;
156+ nock ( 'https://api.github.com' )
157+ . get ( '/repos/pmd/pmd/releases/latest' )
158+ . replyWithFile ( 200 , __dirname + '/data/releases-latest.json' , {
159+ 'Content-Type' : 'application/json' ,
160+ } )
161+ nock ( 'https://github.com' )
162+ . get ( '/pmd/pmd/releases/download/pmd_releases/6.40.0/pmd-bin-6.40.0.zip' )
163+ . replyWithFile ( 200 , __dirname + '/data/pmd-bin-6.40.0.zip' )
164+
165+ const pmdInfo = await util . downloadPmd ( 'latest' , 'my_test_token' ) ;
166+ await util . executePmd ( pmdInfo , '.' , 'ruleset.xml' , 'sarif' , 'pmd-report.sarif' ) ;
167+
168+ expect ( execMock ) . toBeCalledWith ( `${ pmdInfo . path } \\bin\\pmd.bat` , [
169+ '-no-cache' ,
170+ '-d' , '.' ,
171+ '-f' , 'sarif' ,
172+ '-R' , 'ruleset.xml' ,
173+ '-r' , 'pmd-report.sarif' ,
174+ ] ,
175+ {
176+ ignoreReturnCode : true
177+ } ) ;
178+ } )
144179} ) ;
145180
146181function setGlobal ( key , value ) {
0 commit comments