Skip to content

Commit

Permalink
Uses build.cake as the default script to run
Browse files Browse the repository at this point in the history
  • Loading branch information
ecampidoglio committed Oct 25, 2019
1 parent a0ed1b5 commit ce09535
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
38 changes: 24 additions & 14 deletions __tests__/cake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,36 @@ describe('When running a script successfully using the global Cake tool', () =>
fakeExec.mockReturnValue(Promise.resolve(0));
});

test('it should run the global dotnet-cake tool on the specified script', async () => {
await CakeTool.runScript('build.cake');
test('it should run the global dotnet-cake tool on the default script', async () => {
await CakeTool.runScript();
expect(fakeExec).toBeCalledWith('/usr/bin/dotnet-cake', ['build.cake']);
});

test('it should run the global dotnet-cake tool on the specified script', async () => {
await CakeTool.runScript('script.cake');
expect(fakeExec).toBeCalledWith('/usr/bin/dotnet-cake', ['script.cake']);
});

test('it should run the global dotnet-cake tool with the specified parameters', async () => {
await CakeTool.runScript(
'build.cake',
'script.cake',
undefined,
new CakeArgument('param', 'arg'),
new CakeSwitch("switch"));
expect(fakeExec).toBeCalledWith(
'/usr/bin/dotnet-cake',
['build.cake', '--param=arg', '--switch']);
['script.cake', '--param=arg', '--switch']);
});

test('it should run the global dotnet-cake tool without any invalid parameters', async () => {
await CakeTool.runScript(
'build.cake',
'script.cake',
undefined,
new CakeArgument('', ''),
new CakeSwitch("switch"));
expect(fakeExec).toBeCalledWith(
'/usr/bin/dotnet-cake',
['build.cake', '--switch']);
['script.cake', '--switch']);
});
});

Expand All @@ -81,31 +86,36 @@ describe('When running a script successfully using the local Cake tool', () => {
fakeExec.mockReturnValue(Promise.resolve(0));
});

test('it should run the local dotnet-cake tool on the specified script', async () => {
await CakeTool.runScript('build.cake', new ToolsDirectory('path/to/tool'));
test('it should run the local dotnet-cake tool on the default script', async () => {
await CakeTool.runScript(undefined, new ToolsDirectory('path/to/tool'));
expect(fakeExec).toBeCalledWith('path/to/tool/dotnet-cake', ['build.cake']);
});

test('it should run the local dotnet-cake tool on the specified script', async () => {
await CakeTool.runScript('script.cake', new ToolsDirectory('path/to/tool'));
expect(fakeExec).toBeCalledWith('path/to/tool/dotnet-cake', ['script.cake']);
});

test('it should run the local dotnet-cake tool with the specified parameters', async () => {
await CakeTool.runScript(
'build.cake',
'script.cake',
new ToolsDirectory('path/to/tool'),
new CakeArgument('param', 'arg'),
new CakeSwitch("switch"));
expect(fakeExec).toBeCalledWith(
'path/to/tool/dotnet-cake',
['build.cake', '--param=arg', '--switch']);
['script.cake', '--param=arg', '--switch']);
});

test('it should run the local dotnet-cake tool without any invalid parameters', async () => {
await CakeTool.runScript(
'build.cake',
'script.cake',
new ToolsDirectory('path/to/tool'),
new CakeArgument('', ''),
new CakeSwitch("switch"));
expect(fakeExec).toBeCalledWith(
'path/to/tool/dotnet-cake',
['build.cake', '--switch']);
['script.cake', '--switch']);
});
});

Expand All @@ -119,7 +129,7 @@ describe('When failing to run a script using the global Cake tool', () => {
});

test('it should throw an error containing the exit code', async () => {
await expect(CakeTool.runScript('build.cake')).rejects.toThrowError('-21');
await expect(CakeTool.runScript('script.cake')).rejects.toThrowError('-21');
});
});

Expand All @@ -131,6 +141,6 @@ describe('When failing to run a script using the local Cake tool', () => {
});

test('it should throw an error containing the exit code', async () => {
await expect(CakeTool.runScript('build.cake', new ToolsDirectory())).rejects.toThrowError('-21');
await expect(CakeTool.runScript('script.cake', new ToolsDirectory())).rejects.toThrowError('-21');
});
});
2 changes: 1 addition & 1 deletion lib/cake.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CakeTool {
}
});
}
static runScript(scriptPath, workingDirectory, ...params) {
static runScript(scriptPath = 'build.cake', workingDirectory, ...params) {
return __awaiter(this, void 0, void 0, function* () {
const cakeToolPath = yield CakeTool.resolveCakeToolPath(workingDirectory);
const cakeParams = CakeTool.formatParameters(params);
Expand Down
6 changes: 5 additions & 1 deletion src/cake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export class CakeTool {
}
}

static async runScript(scriptPath: string, workingDirectory?: ToolsDirectory, ...params: CakeParameter[]) {
static async runScript(
scriptPath: string = 'build.cake',
workingDirectory?: ToolsDirectory,
...params: CakeParameter[]
) {
const cakeToolPath = await CakeTool.resolveCakeToolPath(workingDirectory);
const cakeParams = CakeTool.formatParameters(params);
const exitCode = await exec(cakeToolPath, [scriptPath, ...cakeParams]);
Expand Down

0 comments on commit ce09535

Please sign in to comment.