This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate the task runner and the command line parser (#25)
* remove conditionl require in runner add tasks module to load all tasks, throw if task does not exist * change task signatures and action handlers - tasks get plugin, run, and an options object - action handler controls what goes into each task - taskRunner wrapper moves the command object to the first argument * change test command signature allow files to be passed in, and pass all options to test:server and test:browser * simplify the task runner * fix typo in unknownOptions * expose the task runner as the module's main this way tasks can be run programatically without going through a cli parser * add tests for task runner * remove file passing for testAll * add serverTestPaths to the plugin config useful for overriding the value via a config file * [config] plugin.serverTestPaths -> plugin.serverTestPatterns
- Loading branch information
Showing
12 changed files
with
97 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
var pluginConfig = require('./plugin_config'); | ||
var tasks = require('./tasks'); | ||
|
||
module.exports = function run(name) { | ||
var action = require('../tasks/' + name); | ||
return function () { | ||
// call the action function with the plugin, then all | ||
// renaining arguments from commander | ||
var plugin = pluginConfig(); | ||
var args = [].slice.apply(arguments); | ||
module.exports = function run(name, options) { | ||
var action = tasks[name]; | ||
if (!action) throw new Error('Invalid task: "' + name + '"'); | ||
|
||
action.apply(null, [plugin, run].concat(args)); | ||
}; | ||
var plugin = pluginConfig(); | ||
action(plugin, run, options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*eslint-env jest*/ | ||
|
||
const testTask = jest.fn(); | ||
const plugin = { id: 'testPlugin' }; | ||
|
||
jest.mock('./plugin_config', () => () => plugin); | ||
jest.mock('./tasks', () => { | ||
return { testTask }; | ||
}); | ||
const run = require('./run'); | ||
|
||
describe('task runner', () => { | ||
beforeEach(() => jest.resetAllMocks()); | ||
|
||
it('throw given an invalid task', function () { | ||
const invalidTaskName = 'thisisnotavalidtasknameandneverwillbe'; | ||
const runner = () => run(invalidTaskName); | ||
|
||
expect(runner).toThrow(/invalid task/i); | ||
}); | ||
|
||
it('runs specified task with plugin and runner', function () { | ||
run('testTask'); | ||
|
||
const args = testTask.mock.calls[0]; | ||
expect(testTask.mock.calls).toHaveLength(1); | ||
expect(args[0]).toBe(plugin); | ||
expect(args[1]).toBe(run); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var buildTask = require('../tasks/build'); | ||
var startTask = require('../tasks/start'); | ||
var testAllTask = require('../tasks/test/all'); | ||
var testBrowserTask = require('../tasks/test/browser'); | ||
var testServerTask = require('../tasks/test/server'); | ||
|
||
module.exports = { | ||
build: buildTask, | ||
start: startTask, | ||
testAll: testAllTask, | ||
testBrowser: testBrowserTask, | ||
testServer: testServerTask, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/*eslint-env jest*/ | ||
const resolve = require('path').resolve; | ||
const fs = require('fs'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = function testAllAction(plugin, run) { | ||
run('test/server')(); | ||
run('test/browser')(); | ||
run('testServer'); | ||
run('testBrowser'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters