Skip to content

Commit 5518351

Browse files
author
Myron van Velsen
committed
Merge branch '266-postinstall-moet-correct-gedraaid-worden' into 'main'
Resolve "Postinstall moet correct gedraaid worden." See merge request elgentos/magento2-playwright!38
2 parents 0188873 + 467c8d5 commit 5518351

File tree

5 files changed

+48
-27
lines changed

5 files changed

+48
-27
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_modules/
66
/test-results/
77
/auth-storage/
88
/playwright-report/
9+
/base-tests/
910

1011
#files
1112
/*.config.ts

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,30 @@ npm init -y
5353

5454
3. **Install the test suite package**
5555

56-
Lastly, simply run the command to install the elgentos Magento2 Playwright package, and the installation script will set things up for you! You will be prompted to input values for the `.env` variables, but these also come with default values.
56+
Lastly, simply run the command to install the elgentos Magento2 Playwright package, and the installation script will set things up for you!
5757

5858
```bash
5959
npm install @elgentos/magento2-playwright
6060
```
6161

62+
4. **Generate .env file and add playwright to .gitignore (optional)**
63+
64+
Normally, you should be prompted to provide values for the .env variables during installation.
65+
Each variable also comes with sensible default values.
66+
67+
<mark>⚠️ Due to limitations in how npm runs dependency install scripts, the install.js script is not executed automatically when this package is installed as a dependency.</mark>
68+
69+
If you want to (re)generate the .env file and configure your environment variables, run the following command manually from your playwright root folder:
70+
71+
```bash
72+
node node_modules/@elgentos/magento2-playwright/install.js
73+
```
74+
75+
After running the command, you will be asked:
76+
77+
- Do you want to customize environment variables? (y/N)
78+
- Do you want to add lines to the .gitignore of your project? (y/N)
79+
6280
---
6381

6482
## ⏸️ Before you run

install.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Install {
1111
currentUser = '';
1212
isCi = false;
1313
useDefaults = false;
14-
pathToMagentoRoot = '../../../../../../../../../../'; // default: when installed via npm
14+
pathToMagentoRootGitignore = '../../../../../../../'; // default: when installed via npm
1515
envVars = {};
1616

1717
rulesToAddToIgnore = [
@@ -29,7 +29,7 @@ class Install {
2929
const isLocalDev = fs.existsSync(path.resolve(__dirname, '.git'));
3030

3131
if (isLocalDev) {
32-
this.pathToMagentoRoot = './'; // we're in the root of the dev repo
32+
this.pathToMagentoRootGitignore = './'; // we're in the root of the dev repo
3333
}
3434

3535
this.envVars = {
@@ -51,7 +51,6 @@ class Install {
5151
'MAGENTO_COUPON_CODE_WEBKIT': { default: 'WEBKIT321' }
5252
}
5353

54-
5554
this.rl = readline.createInterface({
5655
input: process.stdin,
5756
output: process.stdout
@@ -61,25 +60,28 @@ class Install {
6160
}
6261

6362
async init() {
63+
await this.setEnvVariables();
64+
await this.appendToGitIgnore();
6465

65-
console.log(this.envVars);
66-
67-
68-
// Check if user
69-
if (!this.isCi) {
70-
const initialAnswer = await this.askQuestion('Do you want to customize environment variables? (y/N): ');
71-
this.useDefaults = initialAnswer.trim().toLowerCase() !== 'y';
72-
}
66+
console.log('\nInstallation completed successfully!');
67+
console.log('\nFor more information, please visit:');
68+
console.log('https://wiki.elgentos.nl/doc/stappenplan-testing-suite-implementeren-voor-klanten-hCGe4hVQvN');
7369

74-
await this.appendToGitIgnore();
75-
await this.setEnvVariables();
70+
// Close rl when no questions are asked
71+
this.rl.close();
7672
}
7773

7874
async askQuestion(query) {
7975
return new Promise((resolve) => this.rl.question(query, resolve))
8076
}
8177

8278
async setEnvVariables() {
79+
// Check if user
80+
if (!this.isCi) {
81+
const initialAnswer = await this.askQuestion('Do you want to customize environment variables? (y/N): ');
82+
this.useDefaults = initialAnswer.trim().toLowerCase() !== 'y';
83+
}
84+
8385
// Read and update .env file
8486
const envPath = path.join('.env');
8587
let envContent = '';
@@ -93,18 +95,19 @@ class Install {
9395
}
9496

9597
fs.writeFileSync(envPath, envContent);
96-
97-
console.log('\nInstallation completed successfully!');
98-
console.log('\nFor more information, please visit:');
99-
console.log('https://wiki.elgentos.nl/doc/stappenplan-testing-suite-implementeren-voor-klanten-hCGe4hVQvN');
100-
101-
this.rl.close();
10298
}
10399

104100
async appendToGitIgnore() {
101+
if (!this.isCi) {
102+
const initialAnswer = await this.askQuestion('Do you want to add lines to gitignore of your project? (y/N): ');
103+
if (initialAnswer.trim().toLowerCase() !== 'y') {
104+
return;
105+
}
106+
}
107+
105108
console.log('Checking .gitignore and adding lines if necessary...');
106109

107-
const gitignorePath = path.join(this.pathToMagentoRoot, '.gitignore');
110+
const gitignorePath = path.join(this.pathToMagentoRootGitignore, '.gitignore');
108111

109112
// Read existing content if file exists
110113
let existingLines = [];

package-lock.json

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "@elgentos/magento2-playwright",
3-
"version": "2.2.0",
3+
"version": "2.2.2",
44
"author": "elgentos",
55
"license": "ISC",
66
"description": "A Playwright End-To-End (E2E) testing suite for Magento 2 with Hyva that helps you find (potential) issues on your webshop.",
77
"scripts": {
8-
"postinstall": "node build.js && npx playwright install && node install.js",
8+
"postinstall": "node build.js; node install.js; npx playwright install",
99
"translate": "node translate-json.js nl_NL"
1010
},
1111
"dependencies": {

0 commit comments

Comments
 (0)