experiment-e2e-generator 1.0.1 ā 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/README.md +3 -3
- package/package.json +1 -1
- package/src/generator.js +28 -11
- package/src/package-updater.js +38 -3
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ npx experiment-e2e-generator
|
|
|
21
21
|
|
|
22
22
|
### Requirements
|
|
23
23
|
|
|
24
|
-
- Node.js >=
|
|
24
|
+
- Node.js >= 18 (required by Playwright 1.40+)
|
|
25
25
|
- Existing `package.json` in project root
|
|
26
26
|
- Project must be an Experiment Framework project
|
|
27
27
|
|
|
@@ -344,8 +344,8 @@ The generator safely updates your `package.json`:
|
|
|
344
344
|
```json
|
|
345
345
|
{
|
|
346
346
|
"devDependencies": {
|
|
347
|
-
"@playwright/test": "
|
|
348
|
-
"playwright": "
|
|
347
|
+
"@playwright/test": "1.40.0",
|
|
348
|
+
"playwright": "1.40.0"
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
351
|
```
|
package/package.json
CHANGED
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:
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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(
|
|
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(
|
|
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'));
|
package/src/package-updater.js
CHANGED
|
@@ -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
|
|
@@ -17,8 +18,8 @@ export async function updatePackageJson(targetDir) {
|
|
|
17
18
|
// Define additions
|
|
18
19
|
const additions = {
|
|
19
20
|
devDependencies: {
|
|
20
|
-
'@playwright/test': '
|
|
21
|
-
'playwright': '
|
|
21
|
+
'@playwright/test': '1.40.0',
|
|
22
|
+
'playwright': '1.40.0',
|
|
22
23
|
},
|
|
23
24
|
scripts: {},
|
|
24
25
|
};
|
|
@@ -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
|
+
}
|