Refactored test filtering via grep CLI option

This commit is contained in:
squidfunk 2017-02-09 17:35:50 +01:00
parent 0bff78cd1b
commit 7e601d485a
10 changed files with 78 additions and 16 deletions

View File

@ -91,8 +91,7 @@ export default (gulp, config, args) => {
/* Start Gemini and return runner upon finish */ /* Start Gemini and return runner upon finish */
return new Gemini(gemini).test(`${config.tests.visual}/suites`, { return new Gemini(gemini).test(`${config.tests.visual}/suites`, {
reporters: [process.env.CI ? "flat" : "html"], reporters: ["flat"].concat(process.env.CI ? [] : ["html"]),
grep: args.grep ? new RegExp(args.grep, "i") : null,
browsers: args.browsers ? [].concat(args.browsers) : null browsers: args.browsers ? [].concat(args.browsers) : null
}) })

View File

@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then
fi fi
# Run command # Run command
`npm bin`/gulp build --clean --optimize --revision $@ `npm bin`/gulp build --clean --optimize --revision "$@"

View File

@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then
fi fi
# Run command # Run command
`npm bin`/gulp clean $@ `npm bin`/gulp clean "$@"

View File

@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then
fi fi
# Run command # Run command
`npm bin`/gulp watch --no-lint $@ `npm bin`/gulp watch --no-lint "$@"

View File

@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then
fi fi
# Run command # Run command
`npm bin`/gulp tests:visual:run --clean $@ `npm bin`/gulp tests:visual:run --clean "$@"

View File

@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then
fi fi
# Run command # Run command
`npm bin`/gulp tests:visual:session $@ `npm bin`/gulp tests:visual:session "$@"

View File

@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then
fi fi
# Run command # Run command
`npm bin`/gulp tests:visual:update $@ `npm bin`/gulp tests:visual:update "$@"

View File

@ -22,6 +22,14 @@
import config from "../config.json" import config from "../config.json"
import path from "path" import path from "path"
import yargs from "yargs"
/* ----------------------------------------------------------------------------
* Configuration and arguments
* ------------------------------------------------------------------------- */
/* Parse arguments from command line */
const args = yargs.argv
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Functions * Functions
@ -61,7 +69,50 @@ const resolve = (breakpoints, expr) => {
} }
/** /**
* Generate a Gemini test suite for the component * Filter a set of test suites using a regular expression
*
* @param {Array.<object>} components - Component specifications
* @param {Array.<string>} parent - Parent test suite names
* @return {boolean} Whether at least one suite was kept
*/
const filter = (components, parent = []) => {
const regexp = new RegExp(args.grep.replace(" ", ".*?"), "i")
return Object.keys(components).reduce((match, name) => {
const component = components[name]
/* Deep-copy current path and call recursive */
const temp = parent.slice(0).concat(name)
const keep = filter(component.suite || {}, temp)
/* Remove all states that do not match the regular expression */
component.states = (component.states || [{ name: "", wait: 0 }]).reduce(
(states, state) => {
const fullname = temp.slice(0)
.concat(state.name.length ? [state.name] : [])
.join(" ")
if (regexp.test(fullname))
states.push(state)
return states
}, [])
/* Keep komponent, if there is at least one state or the component has
matching subsuites, so it needs to be kept */
if (component.states.length || keep) {
if (keep) {
delete component.capture
delete component.break
}
return true
}
/* Otherwise, delete component */
delete components[name]
return match
}, false)
}
/**
* Generate Gemini test suites for the given components
* *
* @param {string} dirname - Directory of the test suite * @param {string} dirname - Directory of the test suite
* @param {Array.<object>} components - Component specifications // TODO: document syntax and specificagtion * @param {Array.<object>} components - Component specifications // TODO: document syntax and specificagtion
@ -81,11 +132,11 @@ const generate = (dirname, components) => {
"_", component.url ? component.url : "")) "_", component.url ? component.url : ""))
/* The capture selector is assumed to exist */ /* The capture selector is assumed to exist */
suite.setCaptureElements(component.capture) if (component.capture)
suite.setCaptureElements(component.capture)
/* Generate a subsuite for every state */ /* Generate a subsuite for every state */
const states = component.states || [{ name: "", wait: 0 }] for (const state of component.states) {
for (const state of states) {
const test = subsuite => { const test = subsuite => {
/* Resolve and apply relevant breakpoints */ /* Resolve and apply relevant breakpoints */
@ -129,10 +180,22 @@ const generate = (dirname, components) => {
} }
} }
/**
* Register Gemini test suites for the given components
*
* @param {string} dirname - Directory of the test suite
* @param {Array.<object>} components - Component specifications
*/
const register = (dirname, components) => {
if (args.grep)
filter(components)
generate(dirname, components)
}
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Exports * Exports
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
export default { export default {
generate register
} }

View File

@ -32,7 +32,7 @@ import spec from "~/tests/visual/helpers/spec"
* The admonition block looks the same on everything above tablet * The admonition block looks the same on everything above tablet
* portrait, so we can save a few test cases. * portrait, so we can save a few test cases.
*/ */
spec.generate(__dirname, { spec.register(__dirname, {
"admonition": { "admonition": {
"url": "/", "url": "/",
"capture": "#default + .admonition", "capture": "#default + .admonition",

View File

@ -41,7 +41,7 @@ const open = () => {
/* /*
* Main navigation * Main navigation
*/ */
spec.generate(__dirname, { spec.register(__dirname, {
"md-nav--primary": { "md-nav--primary": {
"url": "/", "url": "/",
"capture": ".md-nav--primary", "capture": ".md-nav--primary",
@ -84,7 +84,7 @@ spec.generate(__dirname, {
/* Last list item */ /* Last list item */
":last-child": { ":last-child": {
"capture": "capture":
".md-nav--primary > .md-nav__list >" + ".md-nav--primary > .md-nav__list > " +
".md-nav__item:last-child", ".md-nav__item:last-child",
"break": "+@tablet-landscape", "break": "+@tablet-landscape",
"states": [ "states": [