-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstart.js
94 lines (85 loc) · 3.35 KB
/
start.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const { execSync } = require('child_process')
const { Select } = require('enquirer');
const { join } = require("path");
const { existsSync } = require('fs');
const TEST_MODULE = new Select({
name: 'framework',
message: 'Which test module you want to run?',
choices: ['UI', 'API', 'Mobile']
})
const RUNNER_SERVICE = new Select({
name: 'runMode',
message: 'Where do you want to run your tests?',
choices: ['Local', 'Docker']
})
const UI_TEST_TYPE = new Select({
name: 'runMode',
message: 'Which framework do you want to run?',
choices: ['Mocha', 'Cucumber']
})
const runnerCommand = {
apiRunner: () => { execSync('cd api&&npm run test', { stdio: 'inherit' }) },
mobileRunner: () => { execSync('cd mobile&&npm run test', { stdio: 'inherit' }) },
localMochaRunner: () => execSync('cd web&&npm run test', { stdio: 'inherit' }),
dockerMochaRunner: () => { execSync('cd web&&npm run test:docker', { stdio: 'inherit' }) },
localBDDRunner: () => execSync('cd web&&npm run test:e2e', { stdio: 'inherit' }),
dockerBDDRunner: () => { execSync('cd web&&npm run test:e2e:docker', { stdio: 'inherit' }) }
}
const API_NODE_MODULES_PATH = join(process.cwd(), 'api', 'node_modules');
const MOBILE_NODE_MODULES_PATH = join(process.cwd(), 'mobile', 'node_modules');
const WEB_NODE_MODULES_PATH = join(process.cwd(), 'web', 'node_modules');
const isNodeModuleDoesNotExists = (path) => {
if (!existsSync(path)) {
console.log(`'node_modules' folder is missing!!! Starting installation...`);
return true;
}
else return false;
}
const installerCommand = {
api: () => { execSync('cd api&&npm install', { stdio: 'inherit' }) },
mobile: () => { execSync('cd mobile&&npm install', { stdio: 'inherit' }) },
web: () => execSync('cd web&&npm install', { stdio: 'inherit' }),
}
const nodeModuleInstaller = {
api: () => {
if (isNodeModuleDoesNotExists(API_NODE_MODULES_PATH))
installerCommand.api();
},
mobile: () => {
if (isNodeModuleDoesNotExists(MOBILE_NODE_MODULES_PATH))
installerCommand.mobile();
},
web: () => {
if (isNodeModuleDoesNotExists(WEB_NODE_MODULES_PATH))
installerCommand.web();
}
}
const configRunner = async () => {
const answers = await TEST_MODULE.run();
switch (answers) {
case "API":
nodeModuleInstaller.api();
runnerCommand.apiRunner();
break;
case "Mobile":
nodeModuleInstaller.mobile();
runnerCommand.mobileRunner();
break;
case "UI":
nodeModuleInstaller.web();
const webTestType = await UI_TEST_TYPE.run();
if (webTestType == 'Mocha') {
const mochaRunMode = await RUNNER_SERVICE.run();
if (mochaRunMode == 'Local') { runnerCommand.localMochaRunner() }
else if (mochaRunMode == 'Docker') { runnerCommand.dockerMochaRunner() }
}
else if (webTestType == 'Cucumber') {
const bddRunMode = await RUNNER_SERVICE.run();
if (bddRunMode == 'Local') { runnerCommand.localBDDRunner() }
else if (bddRunMode == 'Docker') { runnerCommand.dockerBDDRunner() }
}
break;
default: throw new Error("Please select option from :: api | web | mobile")
}
}
configRunner()