-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: filter scenarios based on label
- Loading branch information
Marie Cruz
authored and
Marie Cruz
committed
Oct 23, 2018
1 parent
b765a56
commit 377b89b
Showing
3 changed files
with
85 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import logger from './logger'; | ||
|
||
const filterScenario = (config, filter) => { | ||
return new Promise(resolve => { | ||
const filteredScenario = Object.values(config.scenarios).filter( | ||
scenario => scenario.label === filter | ||
); | ||
|
||
if (filteredScenario.length === 0) { | ||
logger.info( | ||
'filterConfig', | ||
`❗️ ${filter} not found on your scenarios. Exiting Aye Spy` | ||
); | ||
process.exitCode = 1; | ||
process.exit(); | ||
} | ||
resolve(filteredScenario); | ||
}); | ||
}; | ||
|
||
export default filterScenario; |
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,44 @@ | ||
/* globals jest expect */ | ||
|
||
import filterScenario from './scenarioFilter'; | ||
|
||
describe('Scenario filter', () => { | ||
it('Filters scenario correctly', () => { | ||
const config = { | ||
gridUrl: 'http://selenium.com:4444/wd/hub', | ||
scenarios: [ | ||
{ | ||
url: 'http:/google.com/', | ||
label: 'homepage' | ||
}, | ||
{ | ||
url: 'http://test.com', | ||
label: 'test' | ||
} | ||
] | ||
}; | ||
|
||
filterScenario(config, 'test').then(scenario => { | ||
expect(scenario.length).toBe(1); | ||
}); | ||
}); | ||
|
||
it('Throws an error if scenario is not found', () => { | ||
const config = { | ||
gridUrl: 'http://selenium.com:4444/wd/hub', | ||
scenarios: [ | ||
{ | ||
url: 'http:/google.com/', | ||
label: 'homepage' | ||
}, | ||
{ | ||
url: 'http://test.com', | ||
label: 'test' | ||
} | ||
] | ||
}; | ||
process.exit = jest.fn(); | ||
filterScenario(config, 'lol'); | ||
expect(process.exit.mock.calls.length).toBe(1); | ||
}); | ||
}); |