1212 * - sudo present vs absent in the `mv` command
1313 */
1414
15- import * as exec from "@actions/exec" ;
16- import * as io from "@actions/io" ;
15+ import { jest } from "@jest/globals" ;
1716import * as path from "path" ;
18-
19- import { installOnUnix } from "../src/installer/unix" ;
20- import { downloadAndExtractZip as _downloadAndExtractZip } from "../src/installer/download" ;
21- import {
22- detectFullChromeVersion as _detectFullChromeVersion ,
23- resolveLegacyVersion as _resolveLegacyVersion ,
24- resolveModernDownload as _resolveModernDownload ,
25- } from "../src/installer/version" ;
26- import { getInstallPath } from "../src/chromedriver-helper" ;
27-
28- jest . mock ( "@actions/exec" ) ;
29- jest . mock ( "@actions/io" ) ;
30- jest . mock ( "@actions/core" ) ;
31- jest . mock ( "../src/installer/download" ) ;
32- jest . mock ( "../src/installer/version" ) ;
33-
34- const execMock = exec . exec as jest . MockedFunction < typeof exec . exec > ;
35- const whichMock = io . which as jest . MockedFunction < typeof io . which > ;
36- const downloadAndExtractZip = _downloadAndExtractZip as jest . MockedFunction <
37- typeof _downloadAndExtractZip
38- > ;
39- const detectFullChromeVersion = _detectFullChromeVersion as jest . MockedFunction <
40- typeof _detectFullChromeVersion
41- > ;
42- const resolveLegacyVersion = _resolveLegacyVersion as jest . MockedFunction <
43- typeof _resolveLegacyVersion
44- > ;
45- const resolveModernDownload = _resolveModernDownload as jest . MockedFunction <
46- typeof _resolveModernDownload
47- > ;
17+ import type { ExecOptions } from "@actions/exec" ;
18+ import { getInstallPath } from "../src/chromedriver-helper.js" ;
19+
20+ jest . unstable_mockModule ( "@actions/exec" , ( ) => ( {
21+ exec : jest . fn ( ) ,
22+ } ) ) ;
23+ jest . unstable_mockModule ( "@actions/io" , ( ) => ( {
24+ which : jest . fn ( ) ,
25+ cp : jest . fn ( ) ,
26+ mkdirP : jest . fn ( ) ,
27+ mv : jest . fn ( ) ,
28+ } ) ) ;
29+ jest . unstable_mockModule ( "@actions/core" , ( ) => ( {
30+ addPath : jest . fn ( ) ,
31+ getInput : jest . fn ( ) ,
32+ info : jest . fn ( ) ,
33+ setFailed : jest . fn ( ) ,
34+ } ) ) ;
35+ jest . unstable_mockModule ( "../src/installer/download.js" , ( ) => ( {
36+ downloadAndExtractZip : jest . fn ( ) ,
37+ } ) ) ;
38+ jest . unstable_mockModule ( "../src/installer/version.js" , ( ) => ( {
39+ detectFullChromeVersion : jest . fn ( ) ,
40+ resolveLegacyVersion : jest . fn ( ) ,
41+ resolveModernDownload : jest . fn ( ) ,
42+ } ) ) ;
43+
44+ const exec = await import ( "@actions/exec" ) ;
45+ const io = await import ( "@actions/io" ) ;
46+ const { installOnUnix } = await import ( "../src/installer/unix.js" ) ;
47+ const downloadMod = await import ( "../src/installer/download.js" ) ;
48+ const versionMod = await import ( "../src/installer/version.js" ) ;
49+
50+ const execMock = jest . mocked ( exec . exec ) ;
51+ const whichMock = jest . mocked ( io . which ) ;
52+ const downloadAndExtractZip = jest . mocked ( downloadMod . downloadAndExtractZip ) ;
53+ const detectFullChromeVersion = jest . mocked ( versionMod . detectFullChromeVersion ) ;
54+ const resolveLegacyVersion = jest . mocked ( versionMod . resolveLegacyVersion ) ;
55+ const resolveModernDownload = jest . mocked ( versionMod . resolveModernDownload ) ;
4856
4957// The install path is derived from process.platform at runtime. Compute the
5058// expected value the same way the implementation does so the test is valid
@@ -70,12 +78,12 @@ function setPresentCommands(present: string[]): void {
7078function execCalls ( ) : Array < {
7179 command : string ;
7280 args : string [ ] ;
73- options ?: exec . ExecOptions ;
81+ options ?: ExecOptions ;
7482} > {
7583 return execMock . mock . calls . map ( ( call ) => ( {
7684 command : call [ 0 ] ,
7785 args : ( call [ 1 ] as string [ ] ) ?? [ ] ,
78- options : call [ 2 ] as exec . ExecOptions | undefined ,
86+ options : call [ 2 ] as ExecOptions | undefined ,
7987 } ) ) ;
8088}
8189
0 commit comments