@qavajs/create 0.1.0
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/CHANGELOG.MD +12 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/index.js +2 -0
- package/lib/deps.js +33 -0
- package/lib/install.js +199 -0
- package/package.json +37 -0
- package/src/@types/config.d.ts +11 -0
- package/src/@types/yarn-install.d.ts +17 -0
- package/src/deps.ts +41 -0
- package/src/install.ts +206 -0
- package/templates/config.ejs +50 -0
- package/templates/feature.ejs +5 -0
- package/templates/featureApi.ejs +8 -0
- package/templates/memory.ejs +2 -0
- package/templates/po.ejs +9 -0
- package/templates/readme.ejs +27 -0
- package/templates/tsconfig.json +12 -0
- package/tsconfig.json +18 -0
- package/vitest.config.js +16 -0
package/CHANGELOG.MD
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to the "@qavajs/cli" will be documented in this file.
|
|
4
|
+
|
|
5
|
+
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
|
6
|
+
|
|
7
|
+
:rocket: - new feature
|
|
8
|
+
:beetle: - bugfix
|
|
9
|
+
:x: - deprecation
|
|
10
|
+
|
|
11
|
+
## 0.1.0
|
|
12
|
+
- :rocket: implemented initializer
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 @qavajs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/index.js
ADDED
package/lib/deps.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.additionalModules = exports.modules = exports.format = exports.steps = void 0;
|
|
4
|
+
exports.default = [
|
|
5
|
+
'@cucumber/cucumber',
|
|
6
|
+
'@qavajs/memory',
|
|
7
|
+
'@qavajs/cli'
|
|
8
|
+
];
|
|
9
|
+
exports.steps = [
|
|
10
|
+
{ module: 'wdio', packageName: '@qavajs/steps-wdio' },
|
|
11
|
+
{ module: 'playwright', packageName: '@qavajs/steps-playwright' },
|
|
12
|
+
{ module: 'api', packageName: '@qavajs/steps-api' },
|
|
13
|
+
{ module: 'memory', packageName: '@qavajs/steps-memory' },
|
|
14
|
+
{ module: 'files', packageName: '@qavajs/steps-files' },
|
|
15
|
+
{ module: 'sql', packageName: '@qavajs/steps-sql' },
|
|
16
|
+
{ module: 'accessibility', packageName: '@qavajs/steps-accessibility' },
|
|
17
|
+
{ module: 'lighthouse', packageName: '@qavajs/steps-lighthouse' },
|
|
18
|
+
{ module: 'visual testing', packageName: '@qavajs/steps-visual-testing' }
|
|
19
|
+
];
|
|
20
|
+
exports.format = [
|
|
21
|
+
{ module: 'report portal', packageName: '@qavajs/format-report-portal', out: 'report/rp.out' },
|
|
22
|
+
{ module: 'console', packageName: '@qavajs/console-formatter' },
|
|
23
|
+
{ module: 'html', packageName: '@qavajs/html-formatter', out: 'report/report.html' },
|
|
24
|
+
{ module: 'jira xray', packageName: '@qavajs/xray-formatter', out: 'report/xray.out' },
|
|
25
|
+
];
|
|
26
|
+
exports.modules = [
|
|
27
|
+
{ module: 'template', packageName: '@qavajs/template' },
|
|
28
|
+
{ module: 'soft-assertion', packageName: '@qavajs/soft-assertion' },
|
|
29
|
+
];
|
|
30
|
+
exports.additionalModules = [
|
|
31
|
+
{ module: 'wdio service adapter', packageName: '@qavajs/wdio-service-adapter' },
|
|
32
|
+
{ module: 'webstorm adapter', packageName: '@qavajs/webstorm-adapter' },
|
|
33
|
+
];
|
package/lib/install.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const promises_1 = require("fs/promises");
|
|
39
|
+
const fs_extra_1 = require("fs-extra");
|
|
40
|
+
const path_1 = require("path");
|
|
41
|
+
const yarn_install_1 = __importDefault(require("yarn-install"));
|
|
42
|
+
const deps_1 = __importStar(require("./deps"));
|
|
43
|
+
const ejs_1 = require("ejs");
|
|
44
|
+
const inquirer = import('inquirer').then(m => m.default);
|
|
45
|
+
const packs = (deps) => deps.map(({ module }) => module);
|
|
46
|
+
const packages = (moduleList, packageMap) => {
|
|
47
|
+
return moduleList
|
|
48
|
+
.map((module) => {
|
|
49
|
+
const pkg = packageMap.find((p) => p.module === module);
|
|
50
|
+
if (!pkg)
|
|
51
|
+
throw new Error(`${module} module is not found`);
|
|
52
|
+
return pkg.packageName;
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const replaceNewLines = (text) => text.replace(/(\r?\n\r?)+/g, '\n');
|
|
56
|
+
function install() {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const requiredDeps = [...deps_1.default];
|
|
59
|
+
const { prompt } = yield inquirer;
|
|
60
|
+
const answers = yield prompt([
|
|
61
|
+
{
|
|
62
|
+
type: 'list',
|
|
63
|
+
message: 'select module system you want to use:',
|
|
64
|
+
name: 'moduleSystem',
|
|
65
|
+
choices: [
|
|
66
|
+
'CommonJS',
|
|
67
|
+
'ES Modules',
|
|
68
|
+
'Typescript'
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: 'checkbox',
|
|
73
|
+
message: 'select step packages to install:',
|
|
74
|
+
name: 'steps',
|
|
75
|
+
choices: packs(deps_1.steps)
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: 'checkbox',
|
|
79
|
+
message: 'select modules to install:',
|
|
80
|
+
name: 'modules',
|
|
81
|
+
choices: packs(deps_1.modules)
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: 'checkbox',
|
|
85
|
+
message: 'select formatters (reporters) to install:',
|
|
86
|
+
name: 'formats',
|
|
87
|
+
choices: packs(deps_1.format)
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: 'checkbox',
|
|
91
|
+
message: 'select additional modules to install:',
|
|
92
|
+
name: 'additionalModules',
|
|
93
|
+
choices: packs(deps_1.additionalModules)
|
|
94
|
+
},
|
|
95
|
+
]);
|
|
96
|
+
const stepsPackages = packages(answers.steps, deps_1.steps);
|
|
97
|
+
const formatPackages = packages(answers.formats, deps_1.format);
|
|
98
|
+
const modulePackages = packages(answers.modules, deps_1.modules);
|
|
99
|
+
const additionalPackages = packages(answers.additionalModules, deps_1.additionalModules);
|
|
100
|
+
const isTypescript = answers.moduleSystem === 'Typescript';
|
|
101
|
+
const isWdioIncluded = answers.steps.includes('wdio');
|
|
102
|
+
const isPlaywrightIncluded = answers.steps.includes('playwright');
|
|
103
|
+
const isApiIncluded = answers.steps.includes('api');
|
|
104
|
+
//checking if user selected only one browser driver
|
|
105
|
+
if (isPlaywrightIncluded && isWdioIncluded) {
|
|
106
|
+
throw new Error('Please select only one browser driver');
|
|
107
|
+
}
|
|
108
|
+
const isPOIncluded = isWdioIncluded || isPlaywrightIncluded;
|
|
109
|
+
const isTemplateIncluded = answers.modules.includes('template');
|
|
110
|
+
// add ts-node package if module system is typescript
|
|
111
|
+
// put tsconfig
|
|
112
|
+
if (isTypescript) {
|
|
113
|
+
requiredDeps.push('ts-node');
|
|
114
|
+
const tsconfig = yield (0, promises_1.readFile)((0, path_1.resolve)(__dirname, '../templates/tsconfig.json'), 'utf-8');
|
|
115
|
+
yield (0, promises_1.writeFile)(`./tsconfig.json`, tsconfig, 'utf-8');
|
|
116
|
+
}
|
|
117
|
+
const configTemplate = yield (0, promises_1.readFile)((0, path_1.resolve)(__dirname, '../templates/config.ejs'), 'utf-8');
|
|
118
|
+
const configEjs = (0, ejs_1.compile)(configTemplate);
|
|
119
|
+
const stepDefinitionGlob = `step_definition/*.${isTypescript ? 'ts' : 'js'}`;
|
|
120
|
+
const stepsPackagesGlobs = [...stepsPackages].map(p => `node_modules/${p}/index.js`);
|
|
121
|
+
const config = configEjs({
|
|
122
|
+
steps: JSON.stringify([stepDefinitionGlob, ...stepsPackagesGlobs]),
|
|
123
|
+
moduleSystem: answers.moduleSystem,
|
|
124
|
+
modules: JSON.stringify(modulePackages),
|
|
125
|
+
format: JSON.stringify(deps_1.format
|
|
126
|
+
.filter(p => formatPackages.includes(p.packageName))
|
|
127
|
+
.map(p => p.packageName + (p.out ? `:${p.out}` : ''))),
|
|
128
|
+
isWdioIncluded,
|
|
129
|
+
isPlaywrightIncluded,
|
|
130
|
+
isTemplateIncluded
|
|
131
|
+
});
|
|
132
|
+
yield (0, fs_extra_1.ensureDir)('./features');
|
|
133
|
+
yield (0, fs_extra_1.ensureDir)('./memory');
|
|
134
|
+
yield (0, fs_extra_1.ensureDir)('./report');
|
|
135
|
+
yield (0, fs_extra_1.ensureDir)('./step_definition');
|
|
136
|
+
if (isPOIncluded) {
|
|
137
|
+
let poModule;
|
|
138
|
+
if (isWdioIncluded)
|
|
139
|
+
poModule = '@qavajs/po';
|
|
140
|
+
if (isPlaywrightIncluded)
|
|
141
|
+
poModule = '@qavajs/po-playwright';
|
|
142
|
+
if (!poModule)
|
|
143
|
+
throw new Error('No PO module');
|
|
144
|
+
requiredDeps.push(poModule);
|
|
145
|
+
const featureTemplate = yield (0, promises_1.readFile)((0, path_1.resolve)(__dirname, '../templates/feature.ejs'), 'utf-8');
|
|
146
|
+
const featureEjs = (0, ejs_1.compile)(featureTemplate);
|
|
147
|
+
const featureFile = featureEjs();
|
|
148
|
+
yield (0, promises_1.writeFile)('./features/qavajs.feature', replaceNewLines(featureFile), 'utf-8');
|
|
149
|
+
//create page object folder
|
|
150
|
+
yield (0, fs_extra_1.ensureDir)('./page_object');
|
|
151
|
+
const poTemplate = yield (0, promises_1.readFile)((0, path_1.resolve)(__dirname, '../templates/po.ejs'), 'utf-8');
|
|
152
|
+
const poEjs = (0, ejs_1.compile)(poTemplate);
|
|
153
|
+
const poFile = poEjs({
|
|
154
|
+
moduleSystem: answers.moduleSystem,
|
|
155
|
+
poModule
|
|
156
|
+
});
|
|
157
|
+
yield (0, promises_1.writeFile)(`./page_object/index.${isTypescript ? 'ts' : 'js'}`, replaceNewLines(poFile), 'utf-8');
|
|
158
|
+
}
|
|
159
|
+
if (isApiIncluded) {
|
|
160
|
+
const featureTemplate = yield (0, promises_1.readFile)((0, path_1.resolve)(__dirname, '../templates/featureApi.ejs'), 'utf-8');
|
|
161
|
+
const featureEjs = (0, ejs_1.compile)(featureTemplate);
|
|
162
|
+
const featureFile = featureEjs();
|
|
163
|
+
yield (0, promises_1.writeFile)('./features/qavajsApi.feature', replaceNewLines(featureFile), 'utf-8');
|
|
164
|
+
}
|
|
165
|
+
if (isTemplateIncluded) {
|
|
166
|
+
yield (0, fs_extra_1.ensureDir)('./templates');
|
|
167
|
+
}
|
|
168
|
+
yield (0, promises_1.writeFile)(`config.${isTypescript ? 'ts' : 'js'}`, replaceNewLines(config), 'utf-8');
|
|
169
|
+
const memoryTemplate = yield (0, promises_1.readFile)((0, path_1.resolve)(__dirname, '../templates/memory.ejs'), 'utf-8');
|
|
170
|
+
const memoryEjs = (0, ejs_1.compile)(memoryTemplate);
|
|
171
|
+
const memoryFile = memoryEjs({
|
|
172
|
+
moduleSystem: answers.moduleSystem
|
|
173
|
+
});
|
|
174
|
+
yield (0, promises_1.writeFile)(`./memory/index.${isTypescript ? 'ts' : 'js'}`, replaceNewLines(memoryFile), 'utf-8');
|
|
175
|
+
const readmeTemplate = yield (0, promises_1.readFile)((0, path_1.resolve)(__dirname, '../templates/readme.ejs'), 'utf-8');
|
|
176
|
+
const readmeEjs = (0, ejs_1.compile)(readmeTemplate);
|
|
177
|
+
const readmeFile = readmeEjs({
|
|
178
|
+
moduleSystem: answers.moduleSystem
|
|
179
|
+
});
|
|
180
|
+
yield (0, promises_1.writeFile)(`./README.MD`, replaceNewLines(readmeFile), 'utf-8');
|
|
181
|
+
const modulesToInstall = [
|
|
182
|
+
...requiredDeps,
|
|
183
|
+
...stepsPackages,
|
|
184
|
+
...formatPackages,
|
|
185
|
+
...modulePackages,
|
|
186
|
+
...additionalPackages
|
|
187
|
+
];
|
|
188
|
+
console.log('installing packages...');
|
|
189
|
+
console.log(modulesToInstall);
|
|
190
|
+
(0, yarn_install_1.default)({
|
|
191
|
+
deps: modulesToInstall,
|
|
192
|
+
cwd: process.cwd(),
|
|
193
|
+
respectNpm5: true
|
|
194
|
+
});
|
|
195
|
+
console.log('test script:');
|
|
196
|
+
console.log(`npx qavajs run --config config.${isTypescript ? 'ts' : 'js'}`);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
exports.default = install;
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qavajs/create",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "initializer of @qavajs project",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"test": "vitest --coverage run"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"create-qavajs": "./index.js"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"Testing",
|
|
18
|
+
"QA"
|
|
19
|
+
],
|
|
20
|
+
"author": "Alexandr Galichenko",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"ejs": "^3.1.9",
|
|
24
|
+
"fs-extra": "^11.2.0",
|
|
25
|
+
"inquirer": "^9.2.16",
|
|
26
|
+
"typescript": "^5.4.2",
|
|
27
|
+
"yarn-install": "^1.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/ejs": "^3.1.5",
|
|
31
|
+
"@types/fs-extra": "^11.0.4",
|
|
32
|
+
"@types/inquirer": "^9.0.7",
|
|
33
|
+
"@types/node": "^20.11.28",
|
|
34
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
35
|
+
"vitest": "^1.4.0"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'yarn-install' {
|
|
2
|
+
export default function yarnInstall(
|
|
3
|
+
params: {
|
|
4
|
+
deps: string[]
|
|
5
|
+
cwd?: string
|
|
6
|
+
registry?: string
|
|
7
|
+
dev?: boolean
|
|
8
|
+
global?: boolean
|
|
9
|
+
remove?: boolean
|
|
10
|
+
production?: boolean
|
|
11
|
+
respectNpm5?: boolean
|
|
12
|
+
}
|
|
13
|
+
): {
|
|
14
|
+
stderr: string
|
|
15
|
+
status: number
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/deps.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export default [
|
|
2
|
+
'@cucumber/cucumber',
|
|
3
|
+
'@qavajs/memory',
|
|
4
|
+
'@qavajs/cli'
|
|
5
|
+
]
|
|
6
|
+
|
|
7
|
+
export type ModuleDefinition = {
|
|
8
|
+
module: string,
|
|
9
|
+
packageName: string,
|
|
10
|
+
out?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const steps: Array<ModuleDefinition> = [
|
|
14
|
+
{ module: 'wdio', packageName: '@qavajs/steps-wdio' },
|
|
15
|
+
{ module: 'playwright', packageName: '@qavajs/steps-playwright' },
|
|
16
|
+
{ module: 'api', packageName: '@qavajs/steps-api' },
|
|
17
|
+
{ module: 'memory', packageName: '@qavajs/steps-memory' },
|
|
18
|
+
{ module: 'files', packageName: '@qavajs/steps-files' },
|
|
19
|
+
{ module: 'sql', packageName: '@qavajs/steps-sql' },
|
|
20
|
+
{ module: 'accessibility', packageName: '@qavajs/steps-accessibility' },
|
|
21
|
+
{ module: 'lighthouse', packageName: '@qavajs/steps-lighthouse' },
|
|
22
|
+
{ module: 'visual testing', packageName: '@qavajs/steps-visual-testing' }
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
export const format: Array<ModuleDefinition> = [
|
|
26
|
+
{ module: 'report portal', packageName: '@qavajs/format-report-portal', out: 'report/rp.out' },
|
|
27
|
+
{ module: 'console', packageName: '@qavajs/console-formatter' },
|
|
28
|
+
{ module: 'html', packageName: '@qavajs/html-formatter', out: 'report/report.html' },
|
|
29
|
+
{ module: 'jira xray', packageName: '@qavajs/xray-formatter', out: 'report/xray.out' },
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
export const modules: Array<ModuleDefinition> = [
|
|
33
|
+
{ module: 'template', packageName: '@qavajs/template' },
|
|
34
|
+
{ module: 'soft-assertion', packageName: '@qavajs/soft-assertion' },
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
export const additionalModules: Array<ModuleDefinition> = [
|
|
38
|
+
{ module: 'wdio service adapter', packageName: '@qavajs/wdio-service-adapter' },
|
|
39
|
+
{ module: 'webstorm adapter', packageName: '@qavajs/webstorm-adapter' },
|
|
40
|
+
]
|
|
41
|
+
|
package/src/install.ts
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
2
|
+
import { ensureDir } from 'fs-extra';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import yarnInstall from 'yarn-install';
|
|
5
|
+
import deps, {steps, format, modules, additionalModules, ModuleDefinition} from './deps';
|
|
6
|
+
import { compile } from 'ejs';
|
|
7
|
+
const inquirer = import('inquirer').then(m => m.default);
|
|
8
|
+
|
|
9
|
+
type Answers = {
|
|
10
|
+
steps: Array<string>,
|
|
11
|
+
formats: Array<string>,
|
|
12
|
+
modules: Array<string>,
|
|
13
|
+
additionalModules: Array<string>,
|
|
14
|
+
parallel: number,
|
|
15
|
+
moduleSystem: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const packs = (deps: Array<ModuleDefinition>) => deps.map(({module}) => module);
|
|
19
|
+
const packages = (moduleList: Array<string>, packageMap: Array<ModuleDefinition>): Array<string> => {
|
|
20
|
+
return moduleList
|
|
21
|
+
.map((module: string) => {
|
|
22
|
+
const pkg = packageMap.find((p: ModuleDefinition) => p.module === module);
|
|
23
|
+
if (!pkg) throw new Error(`${module} module is not found`);
|
|
24
|
+
return pkg.packageName
|
|
25
|
+
}) as Array<string>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const replaceNewLines = (text: string) => text.replace(/(\r?\n\r?)+/g, '\n');
|
|
29
|
+
|
|
30
|
+
export default async function install(): Promise<void> {
|
|
31
|
+
const requiredDeps = [...deps];
|
|
32
|
+
const { prompt } = await inquirer;
|
|
33
|
+
const answers = await prompt([
|
|
34
|
+
{
|
|
35
|
+
type: 'list',
|
|
36
|
+
message: 'select module system you want to use:',
|
|
37
|
+
name: 'moduleSystem',
|
|
38
|
+
choices: [
|
|
39
|
+
'CommonJS',
|
|
40
|
+
'ES Modules',
|
|
41
|
+
'Typescript'
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'checkbox',
|
|
46
|
+
message: 'select step packages to install:',
|
|
47
|
+
name: 'steps',
|
|
48
|
+
choices: packs(steps)
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: 'checkbox',
|
|
52
|
+
message: 'select modules to install:',
|
|
53
|
+
name: 'modules',
|
|
54
|
+
choices: packs(modules)
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: 'checkbox',
|
|
58
|
+
message: 'select formatters (reporters) to install:',
|
|
59
|
+
name: 'formats',
|
|
60
|
+
choices: packs(format)
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: 'checkbox',
|
|
64
|
+
message: 'select additional modules to install:',
|
|
65
|
+
name: 'additionalModules',
|
|
66
|
+
choices: packs(additionalModules)
|
|
67
|
+
},
|
|
68
|
+
]) as Answers;
|
|
69
|
+
|
|
70
|
+
const stepsPackages: Array<string> = packages(answers.steps, steps);
|
|
71
|
+
const formatPackages: Array<string> = packages(answers.formats, format);
|
|
72
|
+
const modulePackages: Array<string> = packages(answers.modules, modules);
|
|
73
|
+
const additionalPackages: Array<string> = packages(answers.additionalModules, additionalModules);
|
|
74
|
+
|
|
75
|
+
const isTypescript = answers.moduleSystem === 'Typescript';
|
|
76
|
+
const isWdioIncluded = answers.steps.includes('wdio');
|
|
77
|
+
const isPlaywrightIncluded = answers.steps.includes('playwright');
|
|
78
|
+
const isApiIncluded = answers.steps.includes('api');
|
|
79
|
+
//checking if user selected only one browser driver
|
|
80
|
+
if (isPlaywrightIncluded && isWdioIncluded) {
|
|
81
|
+
throw new Error('Please select only one browser driver');
|
|
82
|
+
}
|
|
83
|
+
const isPOIncluded: boolean = isWdioIncluded || isPlaywrightIncluded;
|
|
84
|
+
const isTemplateIncluded: boolean = answers.modules.includes('template');
|
|
85
|
+
|
|
86
|
+
// add ts-node package if module system is typescript
|
|
87
|
+
// put tsconfig
|
|
88
|
+
if (isTypescript) {
|
|
89
|
+
requiredDeps.push('ts-node');
|
|
90
|
+
const tsconfig = await readFile(
|
|
91
|
+
resolve(__dirname, '../templates/tsconfig.json'),
|
|
92
|
+
'utf-8'
|
|
93
|
+
);
|
|
94
|
+
await writeFile(`./tsconfig.json`, tsconfig, 'utf-8');
|
|
95
|
+
}
|
|
96
|
+
const configTemplate: string = await readFile(
|
|
97
|
+
resolve(__dirname, '../templates/config.ejs'),
|
|
98
|
+
'utf-8'
|
|
99
|
+
);
|
|
100
|
+
const configEjs = compile(configTemplate);
|
|
101
|
+
const stepDefinitionGlob = `step_definition/*.${isTypescript ? 'ts' : 'js'}`;
|
|
102
|
+
const stepsPackagesGlobs = [...stepsPackages].map(p => `node_modules/${p}/index.js`);
|
|
103
|
+
const config = configEjs({
|
|
104
|
+
steps: JSON.stringify([stepDefinitionGlob, ...stepsPackagesGlobs]),
|
|
105
|
+
moduleSystem: answers.moduleSystem,
|
|
106
|
+
modules: JSON.stringify(modulePackages),
|
|
107
|
+
format: JSON.stringify(
|
|
108
|
+
format
|
|
109
|
+
.filter(p => formatPackages.includes(p.packageName))
|
|
110
|
+
.map(p => p.packageName + (p.out ? `:${p.out}` : ''))
|
|
111
|
+
),
|
|
112
|
+
isWdioIncluded,
|
|
113
|
+
isPlaywrightIncluded,
|
|
114
|
+
isTemplateIncluded
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
await ensureDir('./features');
|
|
118
|
+
await ensureDir('./memory');
|
|
119
|
+
await ensureDir('./report');
|
|
120
|
+
await ensureDir('./step_definition');
|
|
121
|
+
|
|
122
|
+
if (isPOIncluded) {
|
|
123
|
+
let poModule: string | undefined;
|
|
124
|
+
if (isWdioIncluded) poModule = '@qavajs/po';
|
|
125
|
+
if (isPlaywrightIncluded) poModule = '@qavajs/po-playwright';
|
|
126
|
+
if (!poModule) throw new Error('No PO module');
|
|
127
|
+
requiredDeps.push(poModule);
|
|
128
|
+
const featureTemplate: string = await readFile(
|
|
129
|
+
resolve(__dirname, '../templates/feature.ejs'),
|
|
130
|
+
'utf-8'
|
|
131
|
+
);
|
|
132
|
+
const featureEjs = compile(featureTemplate);
|
|
133
|
+
const featureFile = featureEjs();
|
|
134
|
+
await writeFile('./features/qavajs.feature', replaceNewLines(featureFile), 'utf-8');
|
|
135
|
+
|
|
136
|
+
//create page object folder
|
|
137
|
+
await ensureDir('./page_object');
|
|
138
|
+
const poTemplate: string = await readFile(
|
|
139
|
+
resolve(__dirname, '../templates/po.ejs'),
|
|
140
|
+
'utf-8'
|
|
141
|
+
);
|
|
142
|
+
const poEjs = compile(poTemplate);
|
|
143
|
+
const poFile = poEjs({
|
|
144
|
+
moduleSystem: answers.moduleSystem,
|
|
145
|
+
poModule
|
|
146
|
+
})
|
|
147
|
+
await writeFile(`./page_object/index.${isTypescript ? 'ts' : 'js'}`, replaceNewLines(poFile), 'utf-8');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (isApiIncluded) {
|
|
151
|
+
const featureTemplate: string = await readFile(
|
|
152
|
+
resolve(__dirname, '../templates/featureApi.ejs'),
|
|
153
|
+
'utf-8'
|
|
154
|
+
);
|
|
155
|
+
const featureEjs = compile(featureTemplate);
|
|
156
|
+
const featureFile = featureEjs();
|
|
157
|
+
await writeFile('./features/qavajsApi.feature', replaceNewLines(featureFile), 'utf-8');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (isTemplateIncluded) {
|
|
161
|
+
await ensureDir('./templates');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
await writeFile(`config.${isTypescript ? 'ts' : 'js'}`, replaceNewLines(config), 'utf-8');
|
|
165
|
+
|
|
166
|
+
const memoryTemplate: string = await readFile(
|
|
167
|
+
resolve(__dirname, '../templates/memory.ejs'),
|
|
168
|
+
'utf-8'
|
|
169
|
+
);
|
|
170
|
+
const memoryEjs = compile(memoryTemplate);
|
|
171
|
+
const memoryFile = memoryEjs({
|
|
172
|
+
moduleSystem: answers.moduleSystem
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
await writeFile(`./memory/index.${isTypescript ? 'ts' : 'js'}`, replaceNewLines(memoryFile), 'utf-8');
|
|
176
|
+
|
|
177
|
+
const readmeTemplate: string = await readFile(
|
|
178
|
+
resolve(__dirname, '../templates/readme.ejs'),
|
|
179
|
+
'utf-8'
|
|
180
|
+
);
|
|
181
|
+
const readmeEjs = compile(readmeTemplate);
|
|
182
|
+
const readmeFile = readmeEjs({
|
|
183
|
+
moduleSystem: answers.moduleSystem
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
await writeFile(`./README.MD`, replaceNewLines(readmeFile), 'utf-8');
|
|
187
|
+
|
|
188
|
+
const modulesToInstall = [
|
|
189
|
+
...requiredDeps,
|
|
190
|
+
...stepsPackages,
|
|
191
|
+
...formatPackages,
|
|
192
|
+
...modulePackages,
|
|
193
|
+
...additionalPackages
|
|
194
|
+
];
|
|
195
|
+
console.log('installing packages...');
|
|
196
|
+
console.log(modulesToInstall);
|
|
197
|
+
|
|
198
|
+
yarnInstall({
|
|
199
|
+
deps: modulesToInstall,
|
|
200
|
+
cwd: process.cwd(),
|
|
201
|
+
respectNpm5: true
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
console.log('test script:');
|
|
205
|
+
console.log(`npx qavajs run --config config.${isTypescript ? 'ts' : 'js'}`);
|
|
206
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<% if (moduleSystem === 'CommonJS') {-%>
|
|
2
|
+
<%-`const Memory = require("./memory");`%>
|
|
3
|
+
<% if (isPlaywrightIncluded || isWdioIncluded) {%>
|
|
4
|
+
<%-`const App = require("./page_object");`%>
|
|
5
|
+
<% }%>
|
|
6
|
+
<%-`module.exports = {`%>
|
|
7
|
+
<%-` default: {`%>
|
|
8
|
+
<%-` paths: ["features/**/*.feature"],`%>
|
|
9
|
+
<%-` require: `%><%-steps%>,
|
|
10
|
+
<%-` requireModule: `%><%-modules%>,
|
|
11
|
+
<%-` format: `%><%-format%>,
|
|
12
|
+
<%-` memory: new Memory()`%>,
|
|
13
|
+
<% if (isPlaywrightIncluded || isWdioIncluded) {%>
|
|
14
|
+
<%-` pageObject: new App()`%>,
|
|
15
|
+
<%-` browser: {`%>
|
|
16
|
+
<%-` capabilities: {`%>
|
|
17
|
+
<%-` browserName: `%><% if (isWdioIncluded) {%><%-'"chrome"'%><%} else {%><%-'"chromium"'%><%}%>
|
|
18
|
+
<%-` }`%>
|
|
19
|
+
<%-` },`%>
|
|
20
|
+
<% }%>
|
|
21
|
+
<% if (isTemplateIncluded) {%>
|
|
22
|
+
<%-` templates: ["templates/*.feature"]`%>,
|
|
23
|
+
<% }%>
|
|
24
|
+
<%-` }`%>
|
|
25
|
+
<%-`}`%>
|
|
26
|
+
<% }-%>
|
|
27
|
+
<% if (moduleSystem === 'ES Modules' || moduleSystem === 'Typescript') {-%>
|
|
28
|
+
<%-`import Memory from "./memory`%><% if (moduleSystem === 'ES Modules') {%><%-'/index.js";'%><%} else {%><%-'";'%><%}%>
|
|
29
|
+
<% if (isPlaywrightIncluded || isWdioIncluded) {%>
|
|
30
|
+
<%-`import App from "./page_object`%><% if (moduleSystem === 'ES Modules') {%><%-'/index.js";'%><%} else {%><%-'";'%><%}%>
|
|
31
|
+
<% }-%>
|
|
32
|
+
<%-`export default {`%>
|
|
33
|
+
<%-` paths: ["features/**/*.feature"],`%>
|
|
34
|
+
<% if (moduleSystem === 'ES Modules') {%><%-` import: `%><% } else { %><%-` require: `%><% }-%><%-steps%>,
|
|
35
|
+
<%-` requireModule: `%><%-modules%>,
|
|
36
|
+
<%-` format: `%><%-format%>,
|
|
37
|
+
<%-` memory: new Memory()`%>,
|
|
38
|
+
<% if (isPlaywrightIncluded || isWdioIncluded) {%>
|
|
39
|
+
<%-` pageObject: new App()`%>,
|
|
40
|
+
<%-` browser: {`%>
|
|
41
|
+
<%-` capabilities: {`%>
|
|
42
|
+
<%-` browserName: `%><% if (isWdioIncluded) {%><%-'"chrome"'%><%} else {%><%-'"chromium"'%><%}%>
|
|
43
|
+
<%-` }`%>
|
|
44
|
+
<%-` },`%>
|
|
45
|
+
<% }%>
|
|
46
|
+
<% if (isTemplateIncluded) {%>
|
|
47
|
+
<%-` templates: ["templates/*.feature"]`%>,
|
|
48
|
+
<% }%>
|
|
49
|
+
<%-`}`%>
|
|
50
|
+
<% }%>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Feature: qavajs framework
|
|
2
|
+
|
|
3
|
+
Scenario: Request qavajs site
|
|
4
|
+
When I create 'GET' request 'request'
|
|
5
|
+
And I add 'https://qavajs.github.io/' url to '$request'
|
|
6
|
+
And I send '$request' request and save response as 'response'
|
|
7
|
+
And I parse '$response' body as text
|
|
8
|
+
Then I expect '$response.payload' contains '@qavajs'
|
package/templates/po.ejs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<% if (moduleSystem === 'ES Modules' || moduleSystem === 'Typescript') {-%>
|
|
2
|
+
<%-'import { $, $$, Component } from "'-%><%-poModule%>";
|
|
3
|
+
<%} else {-%>
|
|
4
|
+
<%-'const { $, $$, Component } = require('%>"<%-poModule%>");
|
|
5
|
+
<%}%>
|
|
6
|
+
<% if (moduleSystem === 'ES Modules' || moduleSystem === 'Typescript') {-%><%-'export default '%><%} else {%><%-'module.exports = '%><%}%>class App {
|
|
7
|
+
Body = $("body");
|
|
8
|
+
GetStartedButton = $("a.button[href='/docs/intro']");
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# qavajs
|
|
2
|
+
## Docs
|
|
3
|
+
https://qavajs.github.io/docs/intro
|
|
4
|
+
## Install Modules
|
|
5
|
+
```bash
|
|
6
|
+
npm install
|
|
7
|
+
```
|
|
8
|
+
## Execute Tests
|
|
9
|
+
<%-'```bash'%>
|
|
10
|
+
<% if (moduleSystem === 'Typescript') {-%>
|
|
11
|
+
<%-'npx qavajs run --config config.ts'%>
|
|
12
|
+
<% } else { %>
|
|
13
|
+
<%-'npx qavajs run --config config.js'%>
|
|
14
|
+
<% } %>
|
|
15
|
+
<%-'```'%>
|
|
16
|
+
## Project Structure
|
|
17
|
+
<% if (moduleSystem === 'Typescript') {-%>
|
|
18
|
+
<%-`- [config](./config.ts) - main config`%>
|
|
19
|
+
<% } else { %>
|
|
20
|
+
<%-`- [config](./config.js) - main config`%>
|
|
21
|
+
<% } %>
|
|
22
|
+
- [features](./features) - test cases
|
|
23
|
+
- [memory](./memory) - test data
|
|
24
|
+
- [page_object](./page_object) - page objects
|
|
25
|
+
- [step_definitions](./step_definitions) - project specific step definitions
|
|
26
|
+
- [report](./report) - reports
|
|
27
|
+
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": [
|
|
3
|
+
"src/**/*.ts"
|
|
4
|
+
],
|
|
5
|
+
"exclude": [
|
|
6
|
+
"test/**/*.spec.ts"
|
|
7
|
+
],
|
|
8
|
+
"compilerOptions": {
|
|
9
|
+
"target": "es2016",
|
|
10
|
+
"module": "node16",
|
|
11
|
+
"moduleResolution": "node16",
|
|
12
|
+
"outDir": "./lib",
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"strict": true,
|
|
16
|
+
"skipLibCheck": true
|
|
17
|
+
}
|
|
18
|
+
}
|
package/vitest.config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
coverage: {
|
|
6
|
+
provider: 'v8',
|
|
7
|
+
include: ["src/install.ts"],
|
|
8
|
+
exclude: ["/lib/", "/node_modules/"],
|
|
9
|
+
branches: 0,
|
|
10
|
+
functions: 0,
|
|
11
|
+
lines: 0,
|
|
12
|
+
statements: -10,
|
|
13
|
+
},
|
|
14
|
+
testTimeout: 20000
|
|
15
|
+
}
|
|
16
|
+
})
|