16
16
import { test , expect } from './baseFixtures' ;
17
17
import path from 'path' ;
18
18
import fs from 'fs' ;
19
+ import { PackageManager } from '../src/types' ;
19
20
20
- for ( const packageManager of [ 'npm' , 'yarn' ] as ( 'npm' | 'yarn' ) [ ] ) {
21
+ for ( const packageManager of [ 'npm' , 'pnpm' , ' yarn'] as PackageManager [ ] ) {
21
22
test . describe ( `Package manager: ${ packageManager } ` , ( ) => {
22
23
test . use ( { packageManager } ) ;
23
24
@@ -29,8 +30,10 @@ for (const packageManager of ['npm', 'yarn'] as ('npm' | 'yarn')[]) {
29
30
expect ( fs . existsSync ( path . join ( dir , 'package.json' ) ) ) . toBeTruthy ( ) ;
30
31
if ( packageManager === 'npm' )
31
32
expect ( fs . existsSync ( path . join ( dir , 'package-lock.json' ) ) ) . toBeTruthy ( ) ;
32
- else
33
+ else if ( packageManager === 'yarn' )
33
34
expect ( fs . existsSync ( path . join ( dir , 'yarn.lock' ) ) ) . toBeTruthy ( ) ;
35
+ else if ( packageManager === 'pnpm' )
36
+ expect ( fs . existsSync ( path . join ( dir , 'pnpm-lock.yaml' ) ) ) . toBeTruthy ( ) ;
34
37
expect ( fs . existsSync ( path . join ( dir , 'playwright.config.ts' ) ) ) . toBeTruthy ( ) ;
35
38
const playwrightConfigContent = fs . readFileSync ( path . join ( dir , 'playwright.config.ts' ) , 'utf8' ) ;
36
39
expect ( playwrightConfigContent ) . toContain ( 'tests' ) ;
@@ -39,9 +42,12 @@ for (const packageManager of ['npm', 'yarn'] as ('npm' | 'yarn')[]) {
39
42
if ( packageManager === 'npm' ) {
40
43
expect ( stdout ) . toContain ( 'Initializing NPM project (npm init -y)…' ) ;
41
44
expect ( stdout ) . toContain ( 'Installing Playwright Test (npm install --save-dev @playwright/test)…' ) ;
42
- } else {
45
+ } else if ( packageManager === 'yarn' ) {
43
46
expect ( stdout ) . toContain ( 'Initializing Yarn project (yarn init -y)…' ) ;
44
47
expect ( stdout ) . toContain ( 'Installing Playwright Test (yarn add --dev @playwright/test)…' ) ;
48
+ } else if ( packageManager === 'pnpm' ) {
49
+ expect ( stdout ) . toContain ( 'pnpm init' ) ; // pnpm command outputs name in different case, hence we are not testing the whole string
50
+ expect ( stdout ) . toContain ( 'Installing Playwright Test (pnpm add --save-dev @playwright/test)…' ) ;
45
51
}
46
52
expect ( stdout ) . toContain ( 'npx playwright install' + process . platform === 'linux' ? ' --with-deps' : '' ) ;
47
53
} ) ;
@@ -53,8 +59,10 @@ for (const packageManager of ['npm', 'yarn'] as ('npm' | 'yarn')[]) {
53
59
expect ( fs . existsSync ( path . join ( dir , 'foobar/package.json' ) ) ) . toBeTruthy ( ) ;
54
60
if ( packageManager === 'npm' )
55
61
expect ( fs . existsSync ( path . join ( dir , 'foobar/package-lock.json' ) ) ) . toBeTruthy ( ) ;
56
- else
62
+ else if ( packageManager === 'yarn' )
57
63
expect ( fs . existsSync ( path . join ( dir , 'foobar/yarn.lock' ) ) ) . toBeTruthy ( ) ;
64
+ else if ( packageManager === 'pnpm' )
65
+ expect ( fs . existsSync ( path . join ( dir , 'foobar/pnpm-lock.yaml' ) ) ) . toBeTruthy ( ) ;
58
66
expect ( fs . existsSync ( path . join ( dir , 'foobar/playwright.config.ts' ) ) ) . toBeTruthy ( ) ;
59
67
expect ( fs . existsSync ( path . join ( dir , 'foobar/.github/workflows/playwright.yml' ) ) ) . toBeTruthy ( ) ;
60
68
} ) ;
@@ -66,8 +74,10 @@ for (const packageManager of ['npm', 'yarn'] as ('npm' | 'yarn')[]) {
66
74
expect ( fs . existsSync ( path . join ( dir , 'package.json' ) ) ) . toBeTruthy ( ) ;
67
75
if ( packageManager === 'npm' )
68
76
expect ( fs . existsSync ( path . join ( dir , 'package-lock.json' ) ) ) . toBeTruthy ( ) ;
69
- else
77
+ else if ( packageManager === 'yarn' )
70
78
expect ( fs . existsSync ( path . join ( dir , 'yarn.lock' ) ) ) . toBeTruthy ( ) ;
79
+ else if ( packageManager === 'pnpm' )
80
+ expect ( fs . existsSync ( path . join ( dir , 'pnpm-lock.yaml' ) ) ) . toBeTruthy ( ) ;
71
81
expect ( fs . existsSync ( path . join ( dir , 'playwright.config.js' ) ) ) . toBeTruthy ( ) ;
72
82
expect ( fs . existsSync ( path . join ( dir , '.github/workflows/playwright.yml' ) ) ) . toBeFalsy ( ) ;
73
83
} ) ;
@@ -81,11 +91,11 @@ for (const packageManager of ['npm', 'yarn'] as ('npm' | 'yarn')[]) {
81
91
expect ( fs . existsSync ( path . join ( dir , 'playwright.config.ts' ) ) ) . toBeTruthy ( ) ;
82
92
83
93
{
84
- const { code } = await exec ( packageManager === 'npm' ? 'npx' : 'yarn' , [ 'playwright' , 'install-deps' ] ) ;
94
+ const { code } = await exec ( packageManager === 'npm' ? 'npx' : packageManager === 'pnpm' ? 'pnpm dlx' : 'yarn' , [ 'playwright' , 'install-deps' ] ) ;
85
95
expect ( code ) . toBe ( 0 ) ;
86
96
}
87
97
88
- const { code } = await exec ( packageManager === 'npm' ? 'npx' : 'yarn' , [ 'playwright' , 'test' ] ) ;
98
+ const { code } = await exec ( packageManager === 'npm' ? 'npx' : packageManager === 'pnpm' ? 'pnpm dlx' : 'yarn' , [ 'playwright' , 'test' ] ) ;
89
99
expect ( code ) . toBe ( 0 ) ;
90
100
} ) ;
91
101
@@ -98,11 +108,11 @@ for (const packageManager of ['npm', 'yarn'] as ('npm' | 'yarn')[]) {
98
108
expect ( fs . existsSync ( path . join ( dir , 'playwright.config.js' ) ) ) . toBeTruthy ( ) ;
99
109
100
110
{
101
- const { code } = await exec ( packageManager === 'npm' ? 'npx' : 'yarn' , [ 'playwright' , 'install-deps' ] ) ;
111
+ const { code } = await exec ( packageManager === 'npm' ? 'npx' : packageManager === 'pnpm' ? 'pnpm dlx' : 'yarn' , [ 'playwright' , 'install-deps' ] ) ;
102
112
expect ( code ) . toBe ( 0 ) ;
103
113
}
104
114
105
- const { code } = await exec ( packageManager === 'npm' ? 'npx' : 'yarn' , [ 'playwright' , 'test' ] ) ;
115
+ const { code } = await exec ( packageManager === 'npm' ? 'npx' : packageManager === 'pnpm' ? 'pnpm dlx' : 'yarn' , [ 'playwright' , 'test' ] ) ;
106
116
expect ( code ) . toBe ( 0 ) ;
107
117
} ) ;
108
118
} ) ;
0 commit comments