experiment-e2e-generator 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.2",
6
+ "version": "1.0.3",
7
7
  "description": "CLI tool to generate Playwright e2e tests for Experiment Framework projects",
8
8
  "type": "module",
9
9
  "bin": {
package/src/generator.js CHANGED
@@ -3,7 +3,7 @@ import chalk from 'chalk';
3
3
  import { validateProjectDirectory, pathExists } from './utils.js';
4
4
  import { getUserInput, confirmAction } from './prompts.js';
5
5
  import { generateTestFiles, testsDirectoryExists, getGeneratedFilesList } from './file-operations.js';
6
- import { updatePackageJson, isPlaywrightInstalled } from './package-updater.js';
6
+ import { updatePackageJson, isPlaywrightInstalled, installDependencies } from './package-updater.js';
7
7
 
8
8
  /**
9
9
  * Main generator function
@@ -69,21 +69,38 @@ export async function generator() {
69
69
  console.log(chalk.gray(' ℹ No package.json updates needed'));
70
70
  }
71
71
 
72
- // Step 5: Display completion message
72
+ // Step 5: Install dependencies in target project (only Playwright from its package.json)
73
+ let installSucceeded = false;
74
+ if (packageResult.updated) {
75
+ console.log(chalk.blue('\nšŸ“„ Installing Playwright...\n'));
76
+ const installResult = await installDependencies(cwd);
77
+ if (installResult.success) {
78
+ installSucceeded = true;
79
+ console.log(chalk.green(' āœ“ Playwright installed\n'));
80
+ } else {
81
+ console.log(chalk.yellow(` ⚠ ${installResult.error}`));
82
+ console.log(chalk.gray(' Run yarn install or npm install in this directory to install Playwright.\n'));
83
+ }
84
+ }
85
+
86
+ // Step 6: Display completion message
73
87
  console.log(chalk.green.bold('\nāœ“ Test structure generated successfully!\n'));
74
88
 
75
89
  console.log(chalk.blue('Next steps:\n'));
76
- console.log(chalk.white(' 1. Install dependencies:'));
77
- console.log(chalk.gray(' yarn install\n'));
78
-
79
- console.log(chalk.white(' 2. Update test URLs in:'));
90
+ let step = 1;
91
+ if (!installSucceeded && packageResult.updated) {
92
+ console.log(chalk.white(` ${step}. Install dependencies:`));
93
+ console.log(chalk.gray(' yarn install (or npm install)\n'));
94
+ step++;
95
+ }
96
+ console.log(chalk.white(` ${step}. Update test URLs in:`));
80
97
  console.log(chalk.gray(' tests/config/qa-links.config.js\n'));
81
-
82
- console.log(chalk.white(' 3. Customize test selectors in:'));
98
+ step++;
99
+ console.log(chalk.white(` ${step}. Customize test selectors in:`));
83
100
  console.log(chalk.gray(` tests/e2e/${config.experimentName.toLowerCase().replace(/\s+/g, '-')}/${config.experimentName.toLowerCase().replace(/\s+/g, '-')}.spec.js\n`));
84
-
85
- console.log(chalk.white(' 4. Run tests:'));
86
- console.log(chalk.gray(' yarn test:e2e\n'));
101
+ step++;
102
+ console.log(chalk.white(` ${step}. Run tests:`));
103
+ console.log(chalk.gray(' yarn test:e2e (or npm run test:e2e)\n'));
87
104
 
88
105
  console.log(chalk.blue('šŸ“– Documentation:'));
89
106
  console.log(chalk.gray(' https://playwright.dev/docs/intro\n'));
@@ -1,6 +1,7 @@
1
1
  import path from 'path';
2
+ import { spawnSync } from 'child_process';
2
3
  import fs from 'fs-extra';
3
- import { mergePackageJson, formatPackageJson } from './utils.js';
4
+ import { mergePackageJson, formatPackageJson, pathExists } from './utils.js';
4
5
 
5
6
  /**
6
7
  * Update package.json with Playwright dependencies and scripts
@@ -71,3 +72,37 @@ export async function isPlaywrightInstalled(targetDir) {
71
72
  return false;
72
73
  }
73
74
  }
75
+
76
+ /**
77
+ * Detect which package manager the project uses
78
+ * @param {string} targetDir - Target project directory
79
+ * @returns {'yarn' | 'npm'}
80
+ */
81
+ export async function detectPackageManager(targetDir) {
82
+ const hasYarnLock = await pathExists(path.join(targetDir, 'yarn.lock'));
83
+ return hasYarnLock ? 'yarn' : 'npm';
84
+ }
85
+
86
+ /**
87
+ * Install dependencies in the target project (only installs what's in its package.json, e.g. Playwright)
88
+ * @param {string} targetDir - Target project directory
89
+ * @returns {Promise<{success: boolean, error?: string}>}
90
+ */
91
+ export async function installDependencies(targetDir) {
92
+ const packageManager = await detectPackageManager(targetDir);
93
+ const isWindows = process.platform === 'win32';
94
+ const cmd = packageManager === 'yarn' ? 'yarn' : 'npm';
95
+ const args = ['install'];
96
+ const result = spawnSync(cmd, args, {
97
+ cwd: targetDir,
98
+ stdio: 'inherit',
99
+ shell: isWindows,
100
+ });
101
+ if (result.status !== 0) {
102
+ return {
103
+ success: false,
104
+ error: `${packageManager} install failed with exit code ${result.status}`,
105
+ };
106
+ }
107
+ return { success: true };
108
+ }