Skip to content

Commit

Permalink
fix: Relative --source-dir paths are handled correctly now
Browse files Browse the repository at this point in the history
  • Loading branch information
kumar303 committed Jun 30, 2016
1 parent 6d01415 commit bf266d8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ export class Program {
(resolve) => {
this.yargs.exitProcess(this.shouldExitProgram);
argv = this.yargs.argv;

// Fix up sourceDir. This can hopefully move to option configuration
// soon. See https://github.com/yargs/yargs/issues/535
if (argv.sourceDir) {
argv.sourceDir = path.resolve(argv.sourceDir);
}

cmd = argv._[0];
if (cmd === undefined) {
throw new WebExtError('No sub-command was specified in the args');
Expand Down Expand Up @@ -147,13 +154,15 @@ Example: $0 --help run.
alias: 's',
describe: 'Web extension source directory.',
default: process.cwd(),
normalize: true,
requiresArg: true,
type: 'string',
},
'artifacts-dir': {
alias: 'a',
describe: 'Directory where artifacts will be saved.',
default: path.join(process.cwd(), 'web-ext-artifacts'),
normalize: true,
requiresArg: true,
type: 'string',
},
Expand Down
28 changes: 28 additions & 0 deletions tests/test.program.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,34 @@ describe('program.main', () => {
});
});

it('turns sourceDir into an absolute path', () => {
const fakeCommands = fake(commands, {
build: () => Promise.resolve(),
});
return run(
['build', '--source-dir', '..'], {commands: fakeCommands})
.then(() => {
assert.equal(fakeCommands.build.called, true);
assert.equal(fakeCommands.build.firstCall.args[0].sourceDir,
path.resolve(path.join(process.cwd(), '..')));
});
});

it('normalizes the artifactsDir path', () => {
const fakeCommands = fake(commands, {
build: () => Promise.resolve(),
});
return run(
// Add a double slash to the path, which will be fixed by normalization.
['build', '--artifacts-dir', process.cwd() + path.sep + path.sep],
{commands: fakeCommands})
.then(() => {
assert.equal(fakeCommands.build.called, true);
assert.equal(fakeCommands.build.firstCall.args[0].artifactsDir,
process.cwd() + path.sep);
});
});

});


Expand Down

0 comments on commit bf266d8

Please sign in to comment.