Skip to content

Commit

Permalink
fix(serenity-bdd): Serenity BDD CLI artifact is configurable for 'ser…
Browse files Browse the repository at this point in the history
…enity run' too
  • Loading branch information
jan-molak committed Feb 12, 2019
1 parent 2b464d5 commit b93fa99
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
38 changes: 20 additions & 18 deletions spec/commands/run.spec.ts
Expand Up @@ -15,21 +15,23 @@ import { logger } from '../../src/logger';

describe('serenity run', () => {

const Default_Arguments = {
cacheDir: defaults.cacheDir,
destination: defaults.reportDir,
features: defaults.featuresDir,
source: defaults.sourceDir,
log: 'info',
},
Verbose_Logging = Object.assign(
{}, Default_Arguments, { log: 'verbose' },
),
Debug_Logging = Object.assign(
const
Default_Arguments = {
artifact: defaults.artifact,
cacheDir: defaults.cacheDir,
destination: defaults.reportDir,
features: defaults.featuresDir,
source: defaults.sourceDir,
log: 'info',
},
Verbose_Logging = Object.assign(
{}, Default_Arguments, { log: 'verbose' },
),
Debug_Logging = Object.assign(
{}, Default_Arguments, { log: 'debug' },
),
Empty_Directory: Directory = {} as any,
Path: string = process.env.PATH;
),
Empty_Directory: Directory = {} as any,
Path: string = process.env.PATH;

let log: winston.MemoryTransportInstance;

Expand Down Expand Up @@ -69,10 +71,10 @@ describe('serenity run', () => {

return expect(run(Default_Arguments)).to.be.eventually.fulfilled
.then(() => {
let first = log.writeOutput[0];
const first = log.writeOutput[0];

expect(first).to.contain('Using Java at:');
expect(log.errorOutput).to.be.empty;
expect(log.errorOutput).to.be.empty; // tslint:disable-line:no-unused-expression
});
});

Expand All @@ -83,7 +85,7 @@ describe('serenity run', () => {

return expect(run(Default_Arguments)).to.be.eventually.rejected
.then(() => expect(log.errorOutput.pop()).to.contain(
'Is Java set up correctly'
'Is Java set up correctly',
));
});

Expand All @@ -110,7 +112,7 @@ describe('serenity run', () => {
it('advises what to do if the jar has not been downloaded yet', () => {
scenario('jar_not_found');

return expect(run({ cacheDir: '.', log: 'info' })).to.be.eventually.rejected
return expect(run({ artifact: defaults.artifact, cacheDir: '.', log: 'info' })).to.be.eventually.rejected
.then(() => expect(log.errorOutput.pop()).to.contain(
'Did you remember to run `serenity update`? Error: Unable to access jarfile'
));
Expand Down
28 changes: 16 additions & 12 deletions src/commands/run.ts
Expand Up @@ -27,6 +27,10 @@ export const builder = {
default: defaults.featuresDir,
describe: 'Source directory containing the Cucumber.js feature files',
},
artifact: {
default: defaults.artifact,
describe: `Serenity BDD CLI artifact to use; You're best off with the default option unless you want to experiment.`,
},
source: {
default: defaults.sourceDir,
describe: 'Source directory containing the Serenity BDD JSON output files',
Expand All @@ -50,7 +54,7 @@ export const handler = (argv: any) =>
.then(findJava)
.then(inform('Using Java at: %s'))
.catch(complain('Is Java set up correctly? %s'))
.then(executeWith(flatten([ '-jar', cliJarIn(argv.cacheDir), argumentsFrom(argv) ])))
.then(executeWith(flatten([ '-jar', cliJarIn(argv.cacheDir, argv.artifact), argumentsFrom(argv) ])))
.catch(complain('%s'))
.then(inform('All done!'));

Expand All @@ -65,20 +69,20 @@ const findJava = () => javaHome.getPath()
throw new Error(`"${ javaFor(os.type()) }" could not be found at JAVA_HOME or on the PATH`);
});

const cliJarIn = (cacheDir: string) => path.resolve(cacheDir, filenameOf(defaults.artifact));
const cliJarIn = (cacheDir: string, artifact: string) => path.resolve(cacheDir, filenameOf(artifact));

const argumentsFrom = (argv: string) => {
const validArguments = [
'destination',
'features',
'issueTrackerUrl',
'jiraProject',
'jiraUrl',
'project',
'source',
],
onlyThoseThatArePresent = arg => !! argv[ arg ],
toCLIParams = arg => [ `--${ arg }`, argv[ arg ] ];
'destination',
'features',
'issueTrackerUrl',
'jiraProject',
'jiraUrl',
'project',
'source',
],
onlyThoseThatArePresent = arg => !! argv[ arg ],
toCLIParams = arg => [ `--${ arg }`, argv[ arg ] ];

return validArguments.filter(onlyThoseThatArePresent).map(toCLIParams);
};
Expand Down

0 comments on commit b93fa99

Please sign in to comment.