11import * as fs from 'node:fs/promises' ;
2+ import os from 'node:os' ;
23
34import { beforeEach , describe , expect , it , vi } from 'vitest' ;
45
@@ -14,6 +15,7 @@ import { SupportedBuilder, SupportedFramework } from '../types';
1415import { AddonVitestService } from './AddonVitestService' ;
1516
1617vi . mock ( 'node:fs/promises' , { spy : true } ) ;
18+ vi . mock ( 'node:os' , { spy : true } ) ;
1719vi . mock ( 'storybook/internal/common' , { spy : true } ) ;
1820vi . mock ( 'storybook/internal/node-logger' , { spy : true } ) ;
1921vi . mock ( 'empathic/find' , { spy : true } ) ;
@@ -418,6 +420,7 @@ describe('AddonVitestService', () => {
418420 it ( 'should execute playwright install command' , async ( ) => {
419421 const originalCI = process . env . CI ;
420422 delete process . env . CI ;
423+ vi . mocked ( os . platform ) . mockReturnValue ( 'linux' ) ;
421424 try {
422425 type ChildProcessFactory = ( signal ?: AbortSignal ) => ResultPromise ;
423426 let commandFactory : ChildProcessFactory | ChildProcessFactory [ ] ;
@@ -447,6 +450,7 @@ describe('AddonVitestService', () => {
447450 it ( 'should execute playwright install command with --with-deps in CI' , async ( ) => {
448451 const originalCI = process . env . CI ;
449452 process . env . CI = 'true' ;
453+ vi . mocked ( os . platform ) . mockReturnValue ( 'linux' ) ;
450454 try {
451455 type ChildProcessFactory = ( signal ?: AbortSignal ) => ResultPromise ;
452456 let commandFactory : ChildProcessFactory | ChildProcessFactory [ ] ;
@@ -474,6 +478,38 @@ describe('AddonVitestService', () => {
474478 }
475479 } ) ;
476480
481+ it . each ( [ 'darwin' , 'win32' ] as const ) (
482+ 'should execute playwright install command with --with-deps on %s' ,
483+ async ( platform ) => {
484+ const originalCI = process . env . CI ;
485+ delete process . env . CI ;
486+ vi . mocked ( os . platform ) . mockReturnValue ( platform ) ;
487+ try {
488+ type ChildProcessFactory = ( signal ?: AbortSignal ) => ResultPromise ;
489+ let commandFactory : ChildProcessFactory | ChildProcessFactory [ ] ;
490+ vi . mocked ( prompt . confirm ) . mockResolvedValue ( true ) ;
491+ vi . mocked ( prompt . executeTaskWithSpinner ) . mockImplementation (
492+ async ( factory : ChildProcessFactory | ChildProcessFactory [ ] ) => {
493+ commandFactory = Array . isArray ( factory ) ? factory [ 0 ] : factory ;
494+ commandFactory ( ) ;
495+ }
496+ ) ;
497+
498+ await service . installPlaywright ( ) ;
499+
500+ expect ( mockPackageManager . runPackageCommand ) . toHaveBeenCalledWith ( {
501+ args : [ 'playwright' , 'install' , 'chromium' , '--with-deps' ] ,
502+ signal : undefined ,
503+ stdio : [ 'inherit' , 'pipe' , 'pipe' ] ,
504+ } ) ;
505+ } finally {
506+ if ( originalCI !== undefined ) {
507+ process . env . CI = originalCI ;
508+ }
509+ }
510+ }
511+ ) ;
512+
477513 it ( 'should capture error stack when installation fails' , async ( ) => {
478514 const error = new Error ( 'Installation failed' ) ;
479515 error . stack = 'Error stack trace' ;
0 commit comments