Skip to content
Snippets Groups Projects
Commit 7e601d48 authored by squidfunk's avatar squidfunk
Browse files

Refactored test filtering via grep CLI option

parent 0bff78cd
No related branches found
No related tags found
No related merge requests found
...@@ -91,8 +91,7 @@ export default (gulp, config, args) => { ...@@ -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
}) })
......
...@@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then ...@@ -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 "$@"
...@@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then ...@@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then
fi fi
# Run command # Run command
`npm bin`/gulp clean $@ `npm bin`/gulp clean "$@"
...@@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then ...@@ -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 "$@"
...@@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then ...@@ -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 "$@"
...@@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then ...@@ -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 "$@"
...@@ -28,4 +28,4 @@ if [[ ! -d `npm bin` ]]; then ...@@ -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 "$@"
...@@ -22,6 +22,14 @@ ...@@ -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) => { ...@@ -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) => { ...@@ -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 */
if (component.capture)
suite.setCaptureElements(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) => { ...@@ -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
} }
...@@ -32,7 +32,7 @@ import spec from "~/tests/visual/helpers/spec" ...@@ -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",
......
...@@ -41,7 +41,7 @@ const open = () => { ...@@ -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",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment