Skip to content

Commit

Permalink
Closes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodp committed Mar 9, 2019
1 parent fea90b4 commit d68e44a
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 113 deletions.
13 changes: 13 additions & 0 deletions dist/modules/app/AppController.js
Expand Up @@ -23,6 +23,7 @@ const OptionsHandler_1 = require("./OptionsHandler");
const meow = require("meow");
const updateNotifier = require("update-notifier");
const TestResultAnalyzer_1 = require("../testscript/TestResultAnalyzer");
const GuidedConfig_1 = require("./GuidedConfig");
/**
* Application controller
*
Expand All @@ -44,6 +45,15 @@ class AppController {
this.showException(err, options, cli);
return false; // exit
}
if (options.init) {
if (optionsHandler.wasLoaded()) {
cli.newLine(cli.symbolWarning, 'You already have a configuration file.');
}
else {
options = yield (new GuidedConfig_1.GuidedConfig()).prompt(options);
options.saveConfig = true;
}
}
// Save config ?
if (options.saveConfig) {
try {
Expand All @@ -68,6 +78,9 @@ class AppController {
ui.showVersion();
return true;
}
if (options.init) {
return true;
}
const pkg = meowInstance.pkg; // require( './package.json' );
const notifier = updateNotifier({
pkg,
Expand Down
5 changes: 4 additions & 1 deletion dist/modules/app/CliHelp.js
Expand Up @@ -176,8 +176,10 @@ ${chalk_1.default.gray('Plug-in')}
${chalk_1.default.gray('Processing and output')}
--init Init a guided, basic configuration.
--save-config Save/overwrite a configuration file
with the other command line options.
with other command line options.
-b, --verbose Verbose output.
Expand Down Expand Up @@ -291,6 +293,7 @@ ${chalk_1.default.yellowBright('Examples')}
pluginServe: { type: 'string', alias: 'ps' },
pluginList: { type: 'boolean', alias: 'pl' },
// PROCESSING AND OUTPUT
init: { type: 'boolean' },
verbose: { type: 'boolean', alias: 'b' },
failFast: { type: 'boolean', alias: 'ff' },
noSpec: { type: 'boolean', alias: 'np' },
Expand Down
87 changes: 87 additions & 0 deletions dist/modules/app/GuidedConfig.js
@@ -0,0 +1,87 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const inquirer = require("inquirer");
/**
* Guided Concordia configuration.
*/
class GuidedConfig {
prompt(options) {
return __awaiter(this, void 0, void 0, function* () {
const q = new ConcordiaQuestions();
const questions = [
q.directory(),
q.language(),
q.dirScript(),
q.dirResult(),
q.plugin()
];
let r = yield inquirer.prompt(questions);
options.directory = r.directory;
options.language = r.language;
options.dirScript = r.dirScript;
options.dirResult = r.dirResult;
options.plugin = r.plugin;
return options;
});
}
}
exports.GuidedConfig = GuidedConfig;
class ConcordiaQuestions {
// TO-DO: load options dynamically
language() {
return {
type: 'list',
name: 'language',
message: 'Which spoken language do you want to use in specification files?',
choices: [
{ value: 'en', short: 'en', name: 'English (en)' },
{ value: 'pt', short: 'pt', name: 'Portuguese (pt)' }
]
};
}
directory() {
return {
type: 'input',
name: 'directory',
message: 'Where do you store specification files?',
default: './features'
};
}
dirScript() {
return {
type: 'input',
name: 'dirScript',
message: 'Where do you want to save generated test scripts?',
default: './test'
};
}
dirResult() {
return {
type: 'input',
name: 'dirResult',
message: 'Where do you want to save logs, screenshots, and report files?',
default: './output'
};
}
// TO-DO: load options dynamically
plugin() {
return {
type: 'list',
name: 'plugin',
message: 'Which plug-in do you want to use?',
choices: [
{ value: 'codeceptjs', short: 'codeceptjs', name: 'CodeceptJS with WebDriverIO (web applications)' },
{ value: 'codeceptjs-appium', short: 'codeceptjs-appium', name: 'CodeceptJS with Appium (mobile or desktop applications)' }
]
};
}
}
;
6 changes: 5 additions & 1 deletion dist/modules/app/Options.js
Expand Up @@ -35,6 +35,7 @@ class Options {
'pluginUninstall',
'pluginServe',
// Processing
'init',
'saveConfig',
// Randomic generation
'isGeneratedSeed',
Expand Down Expand Up @@ -67,7 +68,9 @@ class Options {
this.pluginUninstall = false; // uninstall an available plug-in
this.pluginServe = false; // start the test server of a plug-in
// PROCESSING
/** Whether is desired to save/overwrite a configuration file */
/** Whether it is wanted to execute a guided configuration */
this.init = false;
/** Whether it is desired to save/overwrite a configuration file */
this.saveConfig = false;
/** Verbose output */
this.verbose = false;
Expand Down Expand Up @@ -322,6 +325,7 @@ class Options {
this.pluginServe = true;
}
// PROCESSING
this.init = TypeChecking_1.isDefined(obj.init);
this.saveConfig = TypeChecking_1.isDefined(obj.saveConfig);
this.verbose = TypeChecking_1.isDefined(obj.verbose);
this.stopOnTheFirstError = true === obj.failFast || true === obj.stopOnTheFirstError;
Expand Down
10 changes: 8 additions & 2 deletions dist/modules/app/OptionsHandler.js
Expand Up @@ -32,6 +32,10 @@ class OptionsHandler {
get() {
return this._options;
}
/** Sets the current options */
set(options) {
this._options = options;
}
/** Returns true whether the options were already loaded. */
wasLoaded() {
return this._wasLoaded;
Expand All @@ -47,8 +51,7 @@ class OptionsHandler {
options.import(optionsInfo.config);
// Update seed
this.updateSeed(options, this._cli);
// Save
this._wasLoaded = true;
// Save loaded parameters
this._cfgFilePath = optionsInfo.filepath; // may be null
this._options = options;
return options;
Expand Down Expand Up @@ -102,6 +105,9 @@ class OptionsHandler {
// some argument to `optionsFromConfigFile`.
const cliOptions = this.optionsFromCLI();
const cfg = yield this.optionsFromConfigFile();
if (!!cfg) {
this._wasLoaded = true;
}
const cfgFileOptions = !cfg ? {} : cfg.config;
const finalObj = Object.assign(cfgFileOptions, cliOptions);
return { config: finalObj, filepath: !cfg ? null : cfg.filepath };
Expand Down
16 changes: 16 additions & 0 deletions modules/app/AppController.ts
Expand Up @@ -19,6 +19,7 @@ import * as meow from 'meow';
import * as updateNotifier from 'update-notifier';
import { AbstractTestScript } from '../testscript/AbstractTestScript';
import { TestResultAnalyzer } from '../testscript/TestResultAnalyzer';
import { GuidedConfig } from './GuidedConfig';

/**
* Application controller
Expand All @@ -35,13 +36,24 @@ export class AppController {

const optionsHandler = new OptionsHandler( appPath, processPath, cli, meowInstance );
let options: Options;

// Load options
try {
options = await optionsHandler.load();
} catch ( err ) {
this.showException( err, options, cli );
return false; // exit
}

if ( options.init ) {
if ( optionsHandler.wasLoaded() ) {
cli.newLine( cli.symbolWarning, 'You already have a configuration file.' );
} else {
options = await ( new GuidedConfig() ).prompt( options );
options.saveConfig = true;
}
}

// Save config ?
if ( options.saveConfig ) {
try {
Expand Down Expand Up @@ -72,6 +84,10 @@ export class AppController {
return true;
}

if ( options.init ) {
return true;
}

const pkg = meowInstance.pkg; // require( './package.json' );
const notifier = updateNotifier(
{
Expand Down
5 changes: 4 additions & 1 deletion modules/app/CliHelp.ts
Expand Up @@ -180,8 +180,10 @@ ${chalk.gray('Plug-in')}
${chalk.gray('Processing and output')}
--init Init a guided, basic configuration.
--save-config Save/overwrite a configuration file
with the other command line options.
with other command line options.
-b, --verbose Verbose output.
Expand Down Expand Up @@ -306,6 +308,7 @@ ${chalk.yellowBright('Examples')}
pluginList: { type: 'boolean', alias: 'pl' },

// PROCESSING AND OUTPUT
init: { type: 'boolean' },

verbose: { type: 'boolean', alias: 'b' },
failFast: { type: 'boolean', alias: 'ff' },
Expand Down
88 changes: 88 additions & 0 deletions modules/app/GuidedConfig.ts
@@ -0,0 +1,88 @@
import * as inquirer from 'inquirer';
import { Options } from './Options';

/**
* Guided Concordia configuration.
*/
export class GuidedConfig {

async prompt( options: Options ): Promise< Options > {

const q = new ConcordiaQuestions();

const questions = [
q.directory(),
q.language(),
q.dirScript(),
q.dirResult(),
q.plugin()
];

let r = await inquirer.prompt( questions );

options.directory = r.directory;
options.language = r.language;
options.dirScript = r.dirScript;
options.dirResult = r.dirResult;
options.plugin = r.plugin;

return options;
}
}

class ConcordiaQuestions {

// TO-DO: load options dynamically
language(): object {
return {
type: 'list',
name: 'language',
message: 'Which spoken language do you want to use in specification files?',
choices: [
{ value: 'en', short: 'en', name: 'English (en)' },
{ value: 'pt', short: 'pt', name: 'Portuguese (pt)' }
]
};
}

directory(): object {
return {
type: 'input',
name: 'directory',
message: 'Where do you store specification files?',
default: './features'
};
}

dirScript(): object {
return {
type: 'input',
name: 'dirScript',
message: 'Where do you want to save generated test scripts?',
default: './test'
};
}

dirResult(): object {
return {
type: 'input',
name: 'dirResult',
message: 'Where do you want to save logs, screenshots, and report files?',
default: './output'
};
}

// TO-DO: load options dynamically
plugin(): object {
return {
type: 'list',
name: 'plugin',
message: 'Which plug-in do you want to use?',
choices: [
{ value: 'codeceptjs', short: 'codeceptjs', name: 'CodeceptJS with WebDriverIO (web applications)' },
{ value: 'codeceptjs-appium', short: 'codeceptjs-appium', name: 'CodeceptJS with Appium (mobile or desktop applications)' }
]
};
}

};
6 changes: 5 additions & 1 deletion modules/app/Options.ts
Expand Up @@ -36,6 +36,7 @@ export class Options {
'pluginServe',

// Processing
'init',
'saveConfig',

// Randomic generation
Expand Down Expand Up @@ -76,7 +77,9 @@ export class Options {

// PROCESSING

/** Whether is desired to save/overwrite a configuration file */
/** Whether it is wanted to execute a guided configuration */
public init: boolean = false;
/** Whether it is desired to save/overwrite a configuration file */
public saveConfig: boolean = false;
/** Verbose output */
public verbose: boolean = false;
Expand Down Expand Up @@ -395,6 +398,7 @@ export class Options {

// PROCESSING

this.init = isDefined( obj.init );
this.saveConfig = isDefined( obj.saveConfig );
this.verbose = isDefined( obj.verbose );
this.stopOnTheFirstError = true === obj.failFast || true === obj.stopOnTheFirstError;
Expand Down

0 comments on commit d68e44a

Please sign in to comment.