Skip to content

Commit

Permalink
add tests and fix for socketcluster create A-Project-Like-This
Browse files Browse the repository at this point in the history
  • Loading branch information
maarteNNNN committed Jan 19, 2023
1 parent a3bbeff commit d93d318
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class REPLClient {
*/
if (typeof accumulator.execute === 'function' && !currentValue) {
await accumulator.execute.call(this, {
argument: this.camelCaseToKebab(currentValue),
argument: commands[i],
options,
});
if (this.options.interactive) break;
Expand All @@ -368,7 +368,7 @@ class REPLClient {
!accumulator[currentValue].hasOwnProperty('execute')
) {
await accumulator.execute.call(this, {
argument: this.camelCaseToKebab(currentValue),
argument: commands[i],
options,
});
if (this.options.interactive) break;
Expand Down Expand Up @@ -416,7 +416,7 @@ class REPLClient {
*/
if (typeof accumulator.execute === 'function') {
await accumulator.execute.call(this, {
argument: this.camelCaseToKebab(currentValue),
argument: commands[i],
options,
});
break;
Expand Down
47 changes: 47 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,51 @@ describe('REPL Client tests', () => {
.to.be.eql('command is invalid and needs more arguments');
}
});

it('it prevents a project name from translating into camelCase with execute', async () => {
const projectName = 'Pyaterochka-013152-SKU-auditor';
try {
const testCli = await initiateCli(
{ ...exampleOptions },
{
_: ['create', projectName],
},
);

const commands = {
create: {
execute: ({ argument, options }) => {
chai.expect(argument).to.be.eql(projectName);
},
help: 'test this help',
},
};

await testCli.run(commands);
} catch (e) {
chai.expect(e).to.not.throw();
}
});

it("it's unable to pass an argument without execute, that would just be a nested command", async () => {
const projectName = 'Pyaterochka-013152-SKU-auditor';
try {
const testCli = await initiateCli(
{ ...exampleOptions },
{
_: ['create', projectName],
},
);

const commands = {
create: ({ argument, options }) => {},
};

await testCli.run(commands);
} catch (e) {
chai
.expect(e.message)
.to.be.eql('command is invalid and needs more arguments');
}
});
});

0 comments on commit d93d318

Please sign in to comment.