Skip to content

Commit

Permalink
feat: filter scenarios based on label
Browse files Browse the repository at this point in the history
  • Loading branch information
Marie Cruz authored and Marie Cruz committed Oct 23, 2018
1 parent b765a56 commit 377b89b
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
clearDirectories,
fetchRemoteComparisonImages
} from '../comparisonActions';
import filterScenario from '../scenarioFilter';
import validateConfig from '../configValidator';
import Reporter from '../reporter';

Expand All @@ -38,13 +39,19 @@ program
'Select the browser to run your tests on. E.G. chrome, firefox, etc.'
)
.option('c, --config [config]', 'Path to your config')
.option('f, --run [optional]', 'Filter scenarios based on label name')
.option('r, --remote', 'Upload new baseline to remote storage')
.action(async options => {
try {
const config = require(path.resolve(options.config)); // eslint-disable-line import/no-dynamic-require

if (options.browser) config.browser = options.browser;

if (options.run)
filterScenario(config, options.run).then(
scenario => (config.scenarios = scenario)
);

validateConfig(config, options.remote);

logger.info('run', 'Getting snapshots... 📸 ');
Expand All @@ -64,13 +71,19 @@ program
'Select the browser to run your tests on. E.G. chrome, firefox, etc.'
)
.option('c, --config [config]', 'Path to your config')
.option('f, --run [optional]', 'Filter scenarios based on label name')
.option('r, --remote', 'Upload new baseline to remote storage')
.action(async options => {
try {
const config = require(path.resolve(options.config)); // eslint-disable-line import/no-dynamic-require

if (options.browser) config.browser = options.browser;

if (options.run)
filterScenario(config, options.run).then(
scenario => (config.scenarios = scenario)
);

validateConfig(config, options.remote);

createDirectories(fs, config);
Expand All @@ -90,12 +103,19 @@ program
'Select the browser to run your tests on. E.G. chrome, firefox, etc.'
)
.option('c, --config [config]', 'Path to your config')
.option('f, --run [optional]', 'Filter scenarios based on label name')
.option('r, --remote', 'Upload new baseline to remote storage')
.action(async options => {
try {
const config = require(path.resolve(options.config)); // eslint-disable-line import/no-dynamic-require

if (options.browser) config.browser = options.browser;

if (options.run)
filterScenario(config, options.run).then(
scenario => (config.scenarios = scenario)
);

config.remote = options.remote;
validateConfig(config, config.remote);

Expand Down
21 changes: 21 additions & 0 deletions src/scenarioFilter.js
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;
44 changes: 44 additions & 0 deletions src/scenarioFilter.test.js
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);
});
});

0 comments on commit 377b89b

Please sign in to comment.