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 } ) ;
@@ -391,7 +393,7 @@ describe('AddonVitestService', () => {
391393 vi . mocked ( logger . warn ) . mockImplementation ( ( ) => { } ) ;
392394 // Mock getPackageCommand to return a string
393395 vi . mocked ( mockPackageManager . getPackageCommand ) . mockReturnValue (
394- 'npx playwright install chromium --with-deps '
396+ 'npx playwright install chromium'
395397 ) ;
396398 } ) ;
397399
@@ -416,25 +418,127 @@ describe('AddonVitestService', () => {
416418 } ) ;
417419
418420 it ( 'should execute playwright install command' , async ( ) => {
419- type ChildProcessFactory = ( signal ?: AbortSignal ) => ResultPromise ;
420- let commandFactory : ChildProcessFactory | ChildProcessFactory [ ] ;
421- vi . mocked ( prompt . confirm ) . mockResolvedValue ( true ) ;
422- vi . mocked ( prompt . executeTaskWithSpinner ) . mockImplementation (
423- async ( factory : ChildProcessFactory | ChildProcessFactory [ ] ) => {
424- commandFactory = Array . isArray ( factory ) ? factory [ 0 ] : factory ;
425- // Simulate the child process completion
426- commandFactory ( ) ;
421+ const originalCI = process . env . CI ;
422+ delete process . env . CI ;
423+ vi . mocked ( os . platform ) . mockReturnValue ( 'linux' ) ;
424+ try {
425+ type ChildProcessFactory = ( signal ?: AbortSignal ) => ResultPromise ;
426+ let commandFactory : ChildProcessFactory | ChildProcessFactory [ ] ;
427+ vi . mocked ( prompt . confirm ) . mockResolvedValue ( true ) ;
428+ vi . mocked ( prompt . executeTaskWithSpinner ) . mockImplementation (
429+ async ( factory : ChildProcessFactory | ChildProcessFactory [ ] ) => {
430+ commandFactory = Array . isArray ( factory ) ? factory [ 0 ] : factory ;
431+ // Simulate the child process completion
432+ commandFactory ( ) ;
433+ }
434+ ) ;
435+
436+ await service . installPlaywright ( ) ;
437+
438+ expect ( mockPackageManager . runPackageCommand ) . toHaveBeenCalledWith ( {
439+ args : [ 'playwright' , 'install' , 'chromium' ] ,
440+ signal : undefined ,
441+ stdio : [ 'inherit' , 'pipe' , 'pipe' ] ,
442+ } ) ;
443+ } finally {
444+ if ( originalCI !== undefined ) {
445+ process . env . CI = originalCI ;
427446 }
428- ) ;
429-
430- await service . installPlaywright ( ) ;
431-
432- expect ( mockPackageManager . runPackageCommand ) . toHaveBeenCalledWith ( {
433- args : [ 'playwright' , 'install' , 'chromium' , '--with-deps' ] ,
434- signal : undefined ,
435- stdio : [ 'inherit' , 'pipe' , 'pipe' ] ,
436- } ) ;
437- } ) ;
447+ }
448+ } ) ;
449+
450+ it ( 'should warn about missing system dependencies after install on Linux' , async ( ) => {
451+ const originalCI = process . env . CI ;
452+ delete process . env . CI ;
453+ vi . mocked ( os . platform ) . mockReturnValue ( 'linux' ) ;
454+ try {
455+ type ChildProcessFactory = ( signal ?: AbortSignal ) => ResultPromise ;
456+ vi . mocked ( prompt . confirm ) . mockResolvedValue ( true ) ;
457+ vi . mocked ( prompt . executeTaskWithSpinner ) . mockImplementation (
458+ async ( factory : ChildProcessFactory | ChildProcessFactory [ ] ) => {
459+ const commandFactory = Array . isArray ( factory ) ? factory [ 0 ] : factory ;
460+ commandFactory ( ) ;
461+ }
462+ ) ;
463+
464+ const { result } = await service . installPlaywright ( ) ;
465+
466+ expect ( result ) . toBe ( 'installed' ) ;
467+ expect ( logger . warn ) . toHaveBeenCalledWith (
468+ expect . stringContaining ( 'installed without system dependencies' )
469+ ) ;
470+ expect ( logger . warn ) . toHaveBeenCalledWith (
471+ expect . stringContaining ( 'run Storybook Test from the Storybook UI' )
472+ ) ;
473+ } finally {
474+ if ( originalCI !== undefined ) {
475+ process . env . CI = originalCI ;
476+ }
477+ }
478+ } ) ;
479+
480+ it ( 'should execute playwright install command with --with-deps in CI' , async ( ) => {
481+ const originalCI = process . env . CI ;
482+ process . env . CI = 'true' ;
483+ vi . mocked ( os . platform ) . mockReturnValue ( 'linux' ) ;
484+ try {
485+ type ChildProcessFactory = ( signal ?: AbortSignal ) => ResultPromise ;
486+ let commandFactory : ChildProcessFactory | ChildProcessFactory [ ] ;
487+ vi . mocked ( prompt . confirm ) . mockResolvedValue ( true ) ;
488+ vi . mocked ( prompt . executeTaskWithSpinner ) . mockImplementation (
489+ async ( factory : ChildProcessFactory | ChildProcessFactory [ ] ) => {
490+ commandFactory = Array . isArray ( factory ) ? factory [ 0 ] : factory ;
491+ commandFactory ( ) ;
492+ }
493+ ) ;
494+
495+ await service . installPlaywright ( ) ;
496+
497+ expect ( mockPackageManager . runPackageCommand ) . toHaveBeenCalledWith ( {
498+ args : [ 'playwright' , 'install' , 'chromium' , '--with-deps' ] ,
499+ signal : undefined ,
500+ stdio : [ 'inherit' , 'pipe' , 'pipe' ] ,
501+ } ) ;
502+ } finally {
503+ if ( originalCI === undefined ) {
504+ delete process . env . CI ;
505+ } else {
506+ process . env . CI = originalCI ;
507+ }
508+ }
509+ } ) ;
510+
511+ it . each ( [ 'darwin' , 'win32' ] as const ) (
512+ 'should execute playwright install command with --with-deps on %s' ,
513+ async ( platform ) => {
514+ const originalCI = process . env . CI ;
515+ delete process . env . CI ;
516+ vi . mocked ( os . platform ) . mockReturnValue ( platform ) ;
517+ try {
518+ type ChildProcessFactory = ( signal ?: AbortSignal ) => ResultPromise ;
519+ let commandFactory : ChildProcessFactory | ChildProcessFactory [ ] ;
520+ vi . mocked ( prompt . confirm ) . mockResolvedValue ( true ) ;
521+ vi . mocked ( prompt . executeTaskWithSpinner ) . mockImplementation (
522+ async ( factory : ChildProcessFactory | ChildProcessFactory [ ] ) => {
523+ commandFactory = Array . isArray ( factory ) ? factory [ 0 ] : factory ;
524+ commandFactory ( ) ;
525+ }
526+ ) ;
527+
528+ await service . installPlaywright ( ) ;
529+
530+ expect ( mockPackageManager . runPackageCommand ) . toHaveBeenCalledWith ( {
531+ args : [ 'playwright' , 'install' , 'chromium' , '--with-deps' ] ,
532+ signal : undefined ,
533+ stdio : [ 'inherit' , 'pipe' , 'pipe' ] ,
534+ } ) ;
535+ } finally {
536+ if ( originalCI !== undefined ) {
537+ process . env . CI = originalCI ;
538+ }
539+ }
540+ }
541+ ) ;
438542
439543 it ( 'should capture error stack when installation fails' , async ( ) => {
440544 const error = new Error ( 'Installation failed' ) ;
0 commit comments