-
Notifications
You must be signed in to change notification settings - Fork 0
/
postinstallScript.ts
66 lines (57 loc) · 2.1 KB
/
postinstallScript.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const fs = require('fs');
const path = require('path');
// Get the original working directory where `npm install` was run
const projectRoot = process.env.INIT_CWD || process.cwd();
// Define the files and their contents
const filesToCreate = [
{
path: 'tests/features/example.feature',
content: `Feature: Example test
Scenario: Example with google
When I open "https://www.google.com/?hl=en-GB" page
Then If its visible, I "click" the "2" element with "Reject all" "text"
And I "type" "playwright" in the "1" element with "Search" "title"
And I "press" "Enter"
Then I verify that "1" element with "playwright.dev" "text" is "visible"
And I wait "1" seconds
When I go back in the browser
Then I verify if the URL "contains" "https://www.google.com"
When I get a part of the URL based on "www.(.*?).com" regular expression and save it as "websiteNameVariable"
When I "type" "websiteNameVariable"
Then I verify that "1" element with "websiteNameVariable" "text" is "visible"
When I "type" " test with playwright-bdd-wizard finished!"
Then I wait "1.5" seconds
`
},
{
path: 'cucumber.mjs',
content: `export default {
paths: ['tests/**/*.feature'],
import: ['tests/**/*.ts'],
requireModule: ['@exlabs/playwright-bdd-wizard']
}
`
}
];
// Create the files
filesToCreate.forEach(file => {
const filePath = path.join(projectRoot, file.path);
const dir = path.dirname(filePath);
// Ensure the directory exists
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
// Write the file
fs.writeFileSync(filePath, file.content, 'utf8');
});
// Remove tests/example.spec.ts
const exampleSpecPath = path.join(projectRoot, 'tests/example.spec.ts');
if (fs.existsSync(exampleSpecPath)) {
fs.unlinkSync(exampleSpecPath);
}
// Remove tests-examples folder
const testsExamplesPath = path.join(projectRoot, 'tests-examples');
if (fs.existsSync(testsExamplesPath)) {
fs.rmdirSync(testsExamplesPath, { recursive: true });
}
console.log('Sample files created successfully in project root.');