Skip to content

Commit ea99935

Browse files
committed
Add support to multiple package managers
1 parent c6c3214 commit ea99935

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+918
-832
lines changed

__tests__/db/database-package-manager.spec.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fs, vol } from 'memfs';
22
import * as path from 'path';
33
import { promisify } from 'util';
44

5-
import { allInstalledDatabases, databasePackageNameFor } from '../../modules/db/database-package-manager';
5+
import { allInstalledDatabases } from '../../modules/db/database-package-manager';
66
import { FSDirSearcher } from '../../modules/util/fs/FSDirSearcher';
77

88
describe( 'database-package-manager', () => {
@@ -34,14 +34,4 @@ describe( 'database-package-manager', () => {
3434
expect( r[ 0 ] ).toEqual( 'json' );
3535
} );
3636

37-
it( 'completes a database name with the package name', () => {
38-
expect( databasePackageNameFor( 'mysql' ) )
39-
.toEqual( 'database-js-mysql' );
40-
} );
41-
42-
it( 'keeps a correct package name', () => {
43-
expect( databasePackageNameFor( 'database-js-mysql' ) )
44-
.toEqual( 'database-js-mysql' );
45-
} );
46-
4737
} );
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { joinDatabasePackageNames, makeDatabasePackageNameFor } from '../../modules/util/package-installation';
2+
3+
describe( 'package-installation', () => {
4+
5+
it( 'completes a database name with the package name', () => {
6+
expect( makeDatabasePackageNameFor( 'mysql' ) ).toEqual( 'database-js-mysql' );
7+
} );
8+
9+
it( 'keeps a correct package name', () => {
10+
expect( makeDatabasePackageNameFor( 'database-js-mysql' ) ).toEqual( 'database-js-mysql' );
11+
} );
12+
13+
it( 'joins multiple package names', () => {
14+
const names = [ 'mysql', 'database-js-json', 'ini' ];
15+
expect( joinDatabasePackageNames( names ) )
16+
.toEqual( 'database-js-mysql database-js-json database-js-ini' );
17+
} );
18+
19+
} );

dist/modules/app/App.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const JSONTestReporter_1 = require("../report/JSONTestReporter");
1818
const AbstractTestScriptGenerator_1 = require("../testscript/AbstractTestScriptGenerator");
1919
const TestResultAnalyzer_1 = require("../testscript/TestResultAnalyzer");
2020
const fs_1 = require("../util/fs");
21-
const AppOptions_1 = require("./AppOptions");
21+
const app_options_1 = require("./app-options");
2222
/**
2323
* Application facade
2424
*
@@ -30,7 +30,7 @@ class App {
3030
this._path = _path;
3131
this._promisify = _promisify;
3232
}
33-
start(options, ui) {
33+
start(options, listener) {
3434
var _a, _b, _c, _d, _e, _f;
3535
return __awaiter(this, void 0, void 0, function* () {
3636
const fs = this._fs;
@@ -39,48 +39,48 @@ class App {
3939
const fileHandler = new fs_1.FSFileHandler(fs, promisify, options.encoding);
4040
// Load plug-in
4141
let plugin = null;
42-
if (AppOptions_1.hasSomeOptionThatRequiresAPlugin(options) && options.plugin) {
42+
if (app_options_1.hasSomeOptionThatRequiresAPlugin(options) && options.plugin) {
4343
const dirSearcher = new fs_1.FSDirSearcher(fs, promisify);
44-
const pluginManager = new PluginManager_1.PluginManager(ui, new PackageBasedPluginFinder_1.PackageBasedPluginFinder(options.processPath, fileHandler, dirSearcher), fileHandler);
44+
const pluginManager = new PluginManager_1.PluginManager(options.packageManager, listener, new PackageBasedPluginFinder_1.PackageBasedPluginFinder(options.processPath, fileHandler, dirSearcher), fileHandler);
4545
let pluginData = null;
4646
try {
4747
pluginData = yield pluginManager.pluginWithName(options.plugin);
4848
if (!pluginData) {
49-
ui.announcePluginNotFound(options.plugin);
49+
listener.announcePluginNotFound(options.plugin);
5050
return { success: false };
5151
;
5252
}
5353
plugin = yield pluginManager.load(pluginData);
5454
}
5555
catch (err) {
56-
ui.showException(err);
56+
listener.showException(err);
5757
return { success: false };
5858
}
5959
if (!plugin) { // needed?
60-
ui.announcePluginCouldNotBeLoaded(options.plugin);
60+
listener.announcePluginCouldNotBeLoaded(options.plugin);
6161
return { success: false };
6262
;
6363
}
6464
// can continue
6565
}
6666
if (!plugin &&
6767
(options.script || options.run || options.result)) {
68-
ui.announceNoPluginWasDefined();
68+
listener.announceNoPluginWasDefined();
6969
return { success: false };
7070
;
7171
}
7272
// Compile
7373
let hasErrors = false;
7474
let spec = null;
75-
ui.announceOptions(options);
75+
listener.announceOptions(options);
7676
if (options.spec) {
77-
const compiler = new CompilerFacade_1.CompilerFacade(fs, path, promisify, ui, ui);
77+
const compiler = new CompilerFacade_1.CompilerFacade(fs, path, promisify, listener, listener);
7878
try {
7979
[spec,] = yield compiler.compile(options);
8080
}
8181
catch (err) {
8282
hasErrors = true;
83-
ui.showException(err);
83+
listener.showException(err);
8484
}
8585
if (null === spec && options.file.length > 0) {
8686
return { success: !hasErrors };
@@ -118,11 +118,11 @@ class App {
118118
}
119119
catch (err) {
120120
hasErrors = true;
121-
ui.showException(err);
121+
listener.showException(err);
122122
}
123123
const durationMS = Date.now() - startTime;
124-
ui.showGeneratedTestScriptFiles(options.dirScript, generatedTestScriptFiles, durationMS);
125-
ui.showTestScriptGenerationErrors(errors);
124+
listener.showGeneratedTestScriptFiles(options.dirScript, generatedTestScriptFiles, durationMS);
125+
listener.showTestScriptGenerationErrors(errors);
126126
}
127127
}
128128
let executionResult = null;
@@ -147,15 +147,15 @@ class App {
147147
headless: options.headless || undefined,
148148
instances: options.instances || undefined,
149149
};
150-
ui.announceTestScriptExecutionStarted();
150+
listener.announceTestScriptExecutionStarted();
151151
try {
152152
executionResult = yield plugin.executeCode(tseo);
153153
}
154154
catch (err) {
155155
hasErrors = true;
156-
ui.announceTestScriptExecutionError(err);
156+
listener.announceTestScriptExecutionError(err);
157157
}
158-
ui.announceTestScriptExecutionFinished();
158+
listener.announceTestScriptExecutionFinished();
159159
}
160160
if (!hasErrors && (((_c = executionResult === null || executionResult === void 0 ? void 0 : executionResult.total) === null || _c === void 0 ? void 0 : _c.failed) > 0 || ((_d = executionResult === null || executionResult === void 0 ? void 0 : executionResult.total) === null || _d === void 0 ? void 0 : _d.error) > 0)) {
161161
hasErrors = true;
@@ -165,7 +165,7 @@ class App {
165165
if (!executionResult) {
166166
const defaultReportFile = path.join(options.dirResult, yield plugin.defaultReportFile());
167167
if (!fs.existsSync(defaultReportFile)) {
168-
ui.announceReportFileNotFound(defaultReportFile);
168+
listener.announceReportFileNotFound(defaultReportFile);
169169
return { success: false, spec };
170170
}
171171
reportFile = defaultReportFile;
@@ -174,20 +174,20 @@ class App {
174174
reportFile = executionResult.sourceFile;
175175
}
176176
if (reportFile) {
177-
ui.announceReportFile(reportFile);
177+
listener.announceReportFile(reportFile);
178178
try {
179179
executionResult = yield plugin.convertReportFile(reportFile);
180180
}
181181
catch (err) {
182182
hasErrors = true;
183-
ui.showException(err);
183+
listener.showException(err);
184184
}
185185
}
186186
}
187187
if (executionResult) {
188188
try {
189189
const reportedResult = (new TestResultAnalyzer_1.TestResultAnalyzer()).adjustResult(executionResult, abstractTestScripts);
190-
ui.showTestScriptAnalysis(reportedResult);
190+
listener.showTestScriptAnalysis(reportedResult);
191191
// TODO: save report to file
192192
const reporter = new JSONTestReporter_1.JSONTestReporter(fileHandler, path);
193193
yield reporter.report(reportedResult, { directory: options.dirResult, useTimestamp: false });
@@ -198,7 +198,7 @@ class App {
198198
}
199199
catch (err) {
200200
hasErrors = true;
201-
ui.showException(err);
201+
listener.showException(err);
202202
}
203203
}
204204
return { success: !hasErrors, spec };

dist/modules/app/default-options.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
exports.availableEncodings = exports.DEFAULT_DATA_TEST_CASE_COMBINATION = exports.DEFAULT_INVALID_DATA_TEST_CASES_AT_A_TIME = exports.DEFAULT_STATE_COMBINATION = exports.DEFAULT_VARIANT_SELECTION = exports.DEFAULT_IMPORTANCE = exports.DEFAULT_RANDOM_TRIES_TO_INVALID_VALUE = exports.DEFAULT_RANDOM_MAX_STRING_SIZE = exports.DEFAULT_RANDOM_MIN_STRING_SIZE = exports.DEFAULT_TC_INDENTER = exports.DEFAULT_CASE_METHOD = exports.DEFAULT_CASE_UI = exports.DEFAULT_LINE_BREAKER = exports.DEFAULT_ENCODING = exports.DEFAULT_LANGUAGE = exports.DEFAULT_EXTENSION_TEST_CASE = exports.DEFAULT_EXTENSION_FEATURE = exports.DEFAULT_AST_FILE = exports.DEFAULT_CONFIG = exports.DEFAULT_DIR_RESULT = exports.DEFAULT_DIR_SCRIPT = exports.DEFAULT_DIRECTORY = exports.DEFAULT_DIR_LANGUAGE = void 0;
44
const CaseType_1 = require("../util/CaseType");
5-
const CombinationOptions_1 = require("./CombinationOptions");
5+
const combination_options_1 = require("./combination-options");
66
// INTERNAL DIRECTORIES
77
exports.DEFAULT_DIR_LANGUAGE = 'data/';
88
// DIRECTORIES
@@ -28,9 +28,9 @@ exports.DEFAULT_RANDOM_TRIES_TO_INVALID_VALUE = 5; // How many tries it will mak
2828
exports.DEFAULT_IMPORTANCE = 5; // 0..9
2929
// TEST SCENARIO SELECTION AND COMBINATION STRATEGIES
3030
/** @see VariantSelectionOptions */
31-
exports.DEFAULT_VARIANT_SELECTION = CombinationOptions_1.VariantSelectionOptions.SINGLE_RANDOM.toString();
31+
exports.DEFAULT_VARIANT_SELECTION = combination_options_1.VariantSelectionOptions.SINGLE_RANDOM.toString();
3232
/** @see StateCombinationOptions */
33-
exports.DEFAULT_STATE_COMBINATION = CombinationOptions_1.CombinationOptions.SINGLE_RANDOM_OF_EACH.toString();
33+
exports.DEFAULT_STATE_COMBINATION = combination_options_1.CombinationOptions.SINGLE_RANDOM_OF_EACH.toString();
3434
// SELECTION AND COMBINATION STRATEGIES FOR DATA TEST CASES
3535
/**
3636
* How many UI Elements will receive invalid values at a time.
@@ -46,9 +46,9 @@ exports.DEFAULT_STATE_COMBINATION = CombinationOptions_1.CombinationOptions.SING
4646
*
4747
* @see InvalidSpecialOptions
4848
*/
49-
exports.DEFAULT_INVALID_DATA_TEST_CASES_AT_A_TIME = CombinationOptions_1.InvalidSpecialOptions.DEFAULT;
49+
exports.DEFAULT_INVALID_DATA_TEST_CASES_AT_A_TIME = combination_options_1.InvalidSpecialOptions.DEFAULT;
5050
/** @see DataTestCaseCombinationOptions */
51-
exports.DEFAULT_DATA_TEST_CASE_COMBINATION = CombinationOptions_1.CombinationOptions.SHUFFLED_ONE_WISE.toString();
51+
exports.DEFAULT_DATA_TEST_CASE_COMBINATION = combination_options_1.CombinationOptions.SHUFFLED_ONE_WISE.toString();
5252
/**
5353
* Returns available encodings.
5454
*

dist/modules/app/options-importer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports.copyOptions = void 0;
44
const enumUtil = require("enum-util");
55
const path_1 = require("path");
66
const TypeChecking_1 = require("../util/TypeChecking");
7-
const CombinationOptions_1 = require("./CombinationOptions");
7+
const combination_options_1 = require("./combination-options");
88
/**
99
* Copy options
1010
*
@@ -302,15 +302,15 @@ function copyOptions(from, to) {
302302
// }
303303
// TEST SCENARIO SELECTION AND COMBINATION STRATEGIES
304304
if (TypeChecking_1.isString(from.combVariant)) {
305-
if (enumUtil.isValue(CombinationOptions_1.VariantSelectionOptions, from.combVariant)) {
305+
if (enumUtil.isValue(combination_options_1.VariantSelectionOptions, from.combVariant)) {
306306
to.combVariant = from.combVariant;
307307
}
308308
else {
309309
errors.push("Option '--comb-variant' expects another value. See '--help'.");
310310
}
311311
}
312312
if (TypeChecking_1.isString(from.combState)) {
313-
if (enumUtil.isValue(CombinationOptions_1.CombinationOptions, from.combState)) {
313+
if (enumUtil.isValue(combination_options_1.CombinationOptions, from.combState)) {
314314
to.combState = from.combState;
315315
}
316316
else {
@@ -328,15 +328,15 @@ function copyOptions(from, to) {
328328
}
329329
}
330330
else if (TypeChecking_1.isString(from.combInvalid)) {
331-
if (enumUtil.isValue(CombinationOptions_1.InvalidSpecialOptions, from.combInvalid)) {
331+
if (enumUtil.isValue(combination_options_1.InvalidSpecialOptions, from.combInvalid)) {
332332
to.combInvalid = from.combInvalid;
333333
}
334334
else {
335335
errors.push("Option '--comb-invalid' expects another value. See '--help'.");
336336
}
337337
}
338338
if (TypeChecking_1.isString(from.combData)) {
339-
if (enumUtil.isValue(CombinationOptions_1.CombinationOptions, from.combData)) {
339+
if (enumUtil.isValue(combination_options_1.CombinationOptions, from.combData)) {
340340
to.combData = from.combData;
341341
}
342342
else {

dist/modules/app/options-maker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function makeAppOptions(appPath = __dirname, processPath = process.cwd()) {
2929
directory,
3030
dirScript,
3131
dirResult,
32+
packageManager: 'npm',
3233
ignore: [],
3334
file: [],
3435
scriptFile: [],

dist/modules/cli/GuidedConfig.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1111
Object.defineProperty(exports, "__esModule", { value: true });
1212
exports.GuidedConfig = void 0;
1313
const inquirer = require("inquirer");
14+
const package_installation_1 = require("../util/package-installation");
1415
/**
1516
* Guided Concordia configuration.
1617
*/
1718
class GuidedConfig {
18-
prompt() {
19+
/**
20+
*
21+
* @param options Defined options are ignored for prompt and their value is returned.
22+
* @returns
23+
*/
24+
prompt(options) {
1925
return __awaiter(this, void 0, void 0, function* () {
2026
const q = new ConcordiaQuestions();
2127
const questions = [
2228
q.directory(),
2329
q.language(),
2430
q.dirScript(),
2531
q.dirResult(),
26-
q.plugin(),
27-
q.pluginInstall(),
28-
q.databases()
2932
];
30-
return yield inquirer.prompt(questions);
33+
const hasPackageManager = options && !!options.packageManager;
34+
if (!hasPackageManager) {
35+
questions.push(q.packageManager());
36+
}
37+
questions.push(q.plugin());
38+
questions.push(q.pluginInstall());
39+
questions.push(q.databases());
40+
const r = yield inquirer.prompt(questions);
41+
if (hasPackageManager) {
42+
r.packageManager = options.packageManager;
43+
}
44+
return r;
3145
});
3246
}
3347
}
@@ -69,16 +83,41 @@ class ConcordiaQuestions {
6983
default: './output'
7084
};
7185
}
86+
packageManager() {
87+
const choices = package_installation_1.packageManagers().map(tool => ({ value: tool, short: tool, name: tool }));
88+
return {
89+
type: 'list',
90+
name: 'packageManager',
91+
message: 'Which package manager do you want to use?',
92+
choices: choices
93+
};
94+
}
7295
plugin() {
7396
return {
7497
type: 'list',
7598
name: 'plugin',
7699
message: 'Which plug-in do you want to use?',
77100
choices: [
78-
{ value: 'codeceptjs-testcafe', short: 'codeceptjs-testcafe', name: 'CodeceptJS with TestCafé (web applications)' },
79-
{ value: 'codeceptjs-playwright', short: 'codeceptjs-playwright', name: 'CodeceptJS with Playwright (web applications)' },
80-
{ value: 'codeceptjs-webdriverio', short: 'codeceptjs-webdriverio', name: 'CodeceptJS with WebDriverIO (web applications)' },
81-
{ value: 'codeceptjs-appium', short: 'codeceptjs-appium', name: 'CodeceptJS with Appium (mobile or desktop applications)' }
101+
{
102+
value: 'codeceptjs-testcafe',
103+
short: 'codeceptjs-testcafe',
104+
name: 'CodeceptJS with TestCafé (web applications)'
105+
},
106+
{
107+
value: 'codeceptjs-playwright',
108+
short: 'codeceptjs-playwright',
109+
name: 'CodeceptJS with Playwright (web applications)'
110+
},
111+
{
112+
value: 'codeceptjs-webdriverio',
113+
short: 'codeceptjs-webdriverio',
114+
name: 'CodeceptJS with WebDriverIO (web applications)'
115+
},
116+
{
117+
value: 'codeceptjs-appium',
118+
short: 'codeceptjs-appium',
119+
name: 'CodeceptJS with Appium (mobile or desktop applications)'
120+
}
82121
]
83122
};
84123
}

0 commit comments

Comments
 (0)