Skip to content

Commit 9bc8e8f

Browse files
authored
test: migrate to exec fixture (#152)
1 parent ecdbf87 commit 9bc8e8f

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

tests/integration.spec.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import childProcess from 'child_process';
1716
import fs from 'fs';
1817
import path from 'path';
1918
import { assertLockFilesExist, expect, packageManagerToNpxCommand, test } from './baseFixtures';
@@ -97,12 +96,12 @@ test('should generate be able to run JS examples successfully', async ({ run, di
9796
await exec(packageManagerToNpxCommand(packageManager), ['playwright', 'test']);
9897
});
9998

100-
test('should generate in the root of pnpm workspace', async ({ run, packageManager }) => {
99+
test('should generate in the root of pnpm workspace', async ({ run, packageManager, exec }) => {
101100
test.skip(packageManager !== 'pnpm');
102101

103102
const dir = test.info().outputDir;
104103
fs.mkdirSync(dir, { recursive: true });
105-
childProcess.execSync('pnpm init', { cwd: dir });
104+
await exec('pnpm', ['init'], { cwd: dir });
106105
fs.writeFileSync(path.join(dir, 'pnpm-workspace.yaml'), `packages:\n - 'packages/*'\n`);
107106
fs.mkdirSync(path.join(dir, 'packages', 'foo'), { recursive: true });
108107
fs.writeFileSync(path.join(dir, 'packages', 'foo', 'package.json'), `{}`);
@@ -114,7 +113,7 @@ test('should generate in the root of pnpm workspace', async ({ run, packageManag
114113
expect(fs.existsSync(path.join(dir, 'playwright.config.ts'))).toBeTruthy();
115114
});
116115

117-
test('should generate in the root of yarn workspaces', async ({ run, packageManager }) => {
116+
test('should generate in the root of yarn workspaces', async ({ run, packageManager, exec }) => {
118117
test.skip(packageManager !== 'yarn-berry' && packageManager !== 'yarn-classic');
119118

120119
const dir = test.info().outputDir;
@@ -128,9 +127,9 @@ test('should generate in the root of yarn workspaces', async ({ run, packageMana
128127
for (const pkg of ['foo', 'bar']) {
129128
const packageDir = path.join(dir, 'packages', pkg);
130129
fs.mkdirSync(packageDir, { recursive: true });
131-
childProcess.execSync(`yarn init -y`, { cwd: packageDir });
130+
await exec(`yarn`, ['init', '-y'], { cwd: packageDir });
132131
}
133-
childProcess.execSync(`yarn install`, { cwd: dir, stdio: 'inherit', env: { ...process.env, YARN_ENABLE_IMMUTABLE_INSTALLS: 'false', YARN_ENABLE_HARDENED_MODE: '0' } });
132+
await exec(`yarn`, ['install'], { cwd: dir, env: { ...process.env, YARN_ENABLE_IMMUTABLE_INSTALLS: 'false', YARN_ENABLE_HARDENED_MODE: '0' } });
134133

135134
await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false });
136135
assertLockFilesExist(dir, packageManager);
@@ -170,14 +169,14 @@ test('should install with "npm i" in GHA when using npm with package-lock disabl
170169
expect(workflowContent).not.toContain('run: npm ci');
171170
});
172171

173-
test('is proper yarn classic', async ({ packageManager }) => {
172+
test('is proper yarn classic', async ({ packageManager, exec }) => {
174173
test.skip(packageManager !== 'yarn-classic');
175-
fs.mkdirSync(test.info().outputDir);
176-
expect(childProcess.execSync('yarn --version', { encoding: 'utf-8', cwd: test.info().outputDir })).toMatch(/^1\./);
174+
const result = await exec('yarn --version', [], { cwd: test.info().outputDir, shell: true });
175+
expect(result.stdout).toMatch(/^1\./);
177176
});
178177

179-
test('is proper yarn berry', async ({ packageManager }) => {
178+
test('is proper yarn berry', async ({ packageManager, exec }) => {
180179
test.skip(packageManager !== 'yarn-berry');
181-
fs.mkdirSync(test.info().outputDir);
182-
expect(childProcess.execSync('yarn --version', { encoding: 'utf-8', cwd: test.info().outputDir })).toMatch(/^4\./);
180+
const result = await exec('yarn --version', [], { cwd: test.info().outputDir, shell: true });
181+
expect(result.stdout).toMatch(/^4\./);
183182
});

0 commit comments

Comments
 (0)