-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better internal configuration handling (#84)
- Loading branch information
1 parent
44a8062
commit 86a9ad9
Showing
5 changed files
with
34 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,34 @@ | ||
import merge from 'lodash.merge'; | ||
const testRunners = {}; | ||
|
||
const testRunners = []; | ||
const testRunnersById = []; | ||
|
||
export function addTestRunner(config) { | ||
const index = testRunners.findIndex( | ||
testRunner => testRunner.name == config.name | ||
); | ||
testRunnersById.push(config); | ||
if (index === -1) { | ||
testRunners.push(config); | ||
function mergeByHostname(target, source) { | ||
if (target[source.hostname]) { | ||
target[source.hostname].setup = [ | ||
...target[source.hostname].setup, | ||
...source.setup | ||
]; | ||
} else { | ||
// Maybe we have multiple testrunners for the same location etc | ||
merge(testRunners[index], config); | ||
target[source.hostname] = { ...source }; | ||
} | ||
} | ||
|
||
export function removeTestRunner(config) { | ||
// Runners need to have uniqie ids. | ||
// First remove the runner | ||
testRunnersById.splice( | ||
testRunnersById.findIndex( | ||
testRunner => testRunner.hostname === config.hostname | ||
), | ||
1 | ||
); | ||
function removeByHostname(hostnameToRemove) { | ||
delete testRunners[hostnameToRemove]; | ||
} | ||
|
||
// Update the merged version | ||
const index = testRunners.findIndex( | ||
testRunner => testRunner.name == config.name | ||
); | ||
let updatedSetup = {}; | ||
for (let testRunner of testRunnersById) { | ||
if ((testRunner.name = config.name)) { | ||
merge(updatedSetup, testRunner); | ||
} | ||
} | ||
export function addTestRunner(config) { | ||
mergeByHostname(testRunners, config); | ||
} | ||
|
||
if (Object.keys(updatedSetup) > 0) { | ||
testRunners[index] = updatedSetup; | ||
} else { | ||
testRunners.splice(index, 1); | ||
} | ||
export function removeTestRunner(config) { | ||
removeByHostname(config.hostname); | ||
} | ||
|
||
export function getTestRunners() { | ||
return testRunners; | ||
return Object.values(testRunners); | ||
} | ||
|
||
export function getTestRunnersConfiguration(name) { | ||
const index = testRunners.findIndex(testRunner => testRunner.name === name); | ||
return testRunners[index]; | ||
return Object.values(testRunners).find( | ||
testRunner => testRunner.name === name | ||
); | ||
} |
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