Skip to content

Commit

Permalink
feat(serenity-bdd): "serenity-bdd run" command can be configured with…
Browse files Browse the repository at this point in the history
… "--log" to specify the amount
  • Loading branch information
jan-molak committed Aug 27, 2019
1 parent fe7cfca commit 05cd487
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 16 deletions.
3 changes: 3 additions & 0 deletions packages/serenity-bdd/package.json
Expand Up @@ -14,6 +14,9 @@
},
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"bin": {
"serenity-bdd": "bin/serenity-bdd"
},
"keywords": [
"serenity-js",
"tdd",
Expand Down
30 changes: 30 additions & 0 deletions packages/serenity-bdd/resources/logback.config.xml
@@ -0,0 +1,30 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>

<logger name="net.thucydides" level="${LOG_LEVEL:-info}" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>

<logger name="net.serenitybdd" level="${LOG_LEVEL:-info}" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>

<logger name="org.hibernate" level="warn" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>

<logger name="org.littleshoot.proxy" level="warn" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>

<root level="warn">
<appender-ref ref="STDOUT"/>
</root>

</configuration>
5 changes: 0 additions & 5 deletions packages/serenity-bdd/src/cli/bootstrap.ts
Expand Up @@ -31,11 +31,6 @@ export function bootstrap(argv: string[], interceptor?: Interceptor) {
yargs()
.version(require('../../package.json').version)
.demand(1)
.option('log', {
describe: 'log level',
choices: [ 'info', 'verbose', 'debug' ],
default: 'info',
})
.usage('Usage: $0 <command> [options]')
.example('$0 update [options]', 'updates the Serenity jar to the latest version')
.example('$0 remove [options]', 'removes the cache directory and downloaded jars')
Expand Down
15 changes: 13 additions & 2 deletions packages/serenity-bdd/src/cli/commands/run.ts
Expand Up @@ -6,6 +6,7 @@ import { defaults } from '../defaults';
import { GAV } from '../model';
import { Printer } from '../Printer';
import { Complain, InvokeSerenityBDD, SerenityBDDArguments } from '../screenplay';
import { SystemProperties } from '../screenplay/questions/SystemProperties';
import { NotificationReporter, ProgressReporter } from '../stage';

export = {
Expand Down Expand Up @@ -45,14 +46,20 @@ export = {
default: path.basename(process.cwd()),
describe: `Project name to appear in the Serenity reports`,
},
log: {
default: defaults.log,
choices: [ 'warn', 'info', 'debug' ],
describe: `A Logback log level to pass to the Serenity BDD CLI jar`,
},
},
handler: (argv: Argv & WithStage) => {

const
printer = new Printer(process.stdout, process.stderr),
actor = argv.stage.theActorCalled('Serenity/JS'),
artifactGAV = GAV.fromString(argv.artifact),
pathToArtifact = new Path(argv.cacheDir).join(artifactGAV.toPath());
pathToArtifact = new Path(argv.cacheDir).join(artifactGAV.toPath()),
moduleRoot = path.resolve(__dirname, '../../../');

argv.stage.assign(
new NotificationReporter(printer),
Expand All @@ -61,7 +68,11 @@ export = {

return actor.attemptsTo(
InvokeSerenityBDD.at(pathToArtifact)
.with(SerenityBDDArguments.from(argv)),
.withProperties(SystemProperties.from({
'LOG_LEVEL': argv.log,
'logback.configurationFile': path.resolve(moduleRoot, './resources/logback.config.xml'),
}))
.withArguments(SerenityBDDArguments.from(argv)),
)
.catch(error => actor.attemptsTo(
Complain.about(error),
Expand Down
6 changes: 4 additions & 2 deletions packages/serenity-bdd/src/cli/defaults.ts
Expand Up @@ -10,14 +10,16 @@
* @property {string} sourceDir A relative path to the directory where the intermediate Serenity/JS JSON reports have been generated
* @property {string} reportDir A relative path to the directory where the Serenity BDD HTML report should be generated
* @property {string} featuresDir A relative path to the Cucumber.js features directory (if Cucumber is used)
* @property {string} log A Logback log level that Serenity BDD CLI should use (info, warn, debug)
*
* @public
*/
export const defaults = {
artifact: 'net.serenity-bdd:serenity-cli:jar:all:2.1.9',
repository: 'http://jcenter.bintray.com/',
cacheDir: 'cache',
repository: 'https://jcenter.bintray.com/',
cacheDir: 'node_modules/@serenity-js/cache',
sourceDir: 'target/site/serenity',
reportDir: 'target/site/serenity',
featuresDir: 'features',
log: 'warn',
};
Expand Up @@ -28,6 +28,10 @@ export class SerenityBDDArguments extends Question<string[]> {
.filter(key => !! ~ SerenityBDDArguments.Allowed.indexOf(key) && !! this.argv[key])
.map(arg => [`--${ arg }`, this.argv[arg]]));
}

toString() {
return 'Serenity BDD arguments';
}
}

function flatten(list: any[]) {
Expand Down
@@ -0,0 +1,24 @@
import { AnswersQuestions, Question, UsesAbilities } from '@serenity-js/core';
import { Argv } from '../../Argv';

/**
* @package
*/
export class SystemProperties extends Question<string[]> {
static from(argv: Argv) {
return new SystemProperties(argv);
}

constructor(private readonly argv: Argv) {
super();
}

answeredBy(actor: AnswersQuestions & UsesAbilities): string[] {
return Object.keys(this.argv)
.map(arg => `-D${ arg }=${ this.argv[arg] }`);
}

toString() {
return 'system properties';
}
}
Expand Up @@ -13,30 +13,38 @@ export class InvokeSerenityBDD extends Task {
return new InvokeSerenityBDD(pathToArtifact);
}

with(args: Question<string[]>) {
return new InvokeSerenityBDD(this.pathToArtifact, args);
withArguments(args: Question<string[]>) {
return new InvokeSerenityBDD(this.pathToArtifact, args, this.props);
}

withProperties(properties: Question<string[]>) {
return new InvokeSerenityBDD(this.pathToArtifact, this.args, properties);
}

constructor(
private readonly pathToArtifact: Path,
private readonly args: Question<string[]> = Question.about(`no arguments`, actor => []),
private readonly args: Question<string[]> = Question.about(`no arguments`, actor => []),
private readonly props: Question<string[]> = Question.about(`no properties`, actor => []),
) {
super();
}

performAs(actor: PerformsActivities & UsesAbilities & AnswersQuestions): PromiseLike<void> | PromiseLike<any> {

return actor.answer(this.args)
.then(args =>
return Promise.all([
actor.answer(this.args),
actor.answer(this.props),
])
.then(([ args, props ]) =>
actor.attemptsTo(
Check
.whether(FileExists.at(this.pathToArtifact), equals(false))
.andIfSo(TerminateFlow.because(
`I couldn't access the Serenity BDD CLI at ${ this.pathToArtifact.value }. ` +
`Did you remember to run \`serenity-bdd update\`?`,
)),
// todo: check if reports exist ?
Spawn.the(new JavaExecutable(), '-jar', this.pathToArtifact.value, ...args),
// todo: check if reports exist before invoking the jar?
Spawn.the(new JavaExecutable(), ...props, '-jar', this.pathToArtifact.value, ...args),
),
);
}
Expand Down

0 comments on commit 05cd487

Please sign in to comment.