Skip to content

Commit

Permalink
Load included or excluded tests from file too
Browse files Browse the repository at this point in the history
  • Loading branch information
schipiga committed Apr 3, 2018
1 parent 9936d18 commit b86ca1c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -81,6 +81,7 @@ glace [options] [sequence-of-test-files-or-folders]
- `--grep <pattern>, -g` - Filter tests by name or name chunk.
- `--include <sequence>` - Sequence of test name chunks separated by ` | ` in order to choose tests for run.
- `--exclude <sequence>` - Sequence of test name chunks separated by ` | ` in order to exclude tests from run.
- `--precise` - Precise tests inclusion or exclusion (not substring pattern).
- `--report [path]` - Path to reports folder. Default is `cwd/reports`.
- `--dont-clear-report` - Don't clear previous report on tests run.
- `--root-conftest <path>` - Path to root `conftest.js` which will be loaded before all.
Expand Down
22 changes: 18 additions & 4 deletions lib/config.js
Expand Up @@ -108,15 +108,29 @@ if (args.killProcs) {
_.map(args.killProcs.split(","), el => el.trim()));
}

var getFilter = filter => {
var result;
var filePath = path.resolve(U.cwd, filter);
if (fs.existsSync(filePath)) {
result = U.loadJson(filePath);
config.filter.precise = true;
} else {
var split = _.map(filter.split("|"), el => el.trim().toLowerCase());
result = _.filter(split).map(el => {
return { name: el };
});
}
return result;
};

config.filter = U.defVal(config.filter, {});
config.filter.grep = args.g || args.grep;
config.filter.precise = args.precise;
if (args.include) {
config.filter.include = _.filter(
_.map(args.include.split("|"), el => el.trim().toLowerCase()));
config.filter.include = getFilter(args.include);
}
if (args.exclude) {
config.filter.exclude = _.filter(
_.map(args.exclude.split("|"), el => el.trim().toLowerCase()));
config.filter.exclude = getFilter(args.exclude);
}

config.xunit = U.defVal(config.xunit, {});
Expand Down
19 changes: 16 additions & 3 deletions lib/globals/test.js
Expand Up @@ -48,20 +48,23 @@ setLog(); // Set log immediatelly.
*/
var baseTest = (names => {
return (name, opts, fixtures, func) => {
var ctxs;

if (CONF.filter.include) {
var isIncluded = false;
for (var include of CONF.filter.include) {
if (name.toLowerCase().includes(include)) {
if (isFilterMatched(name, include.name)) {
isIncluded = true;
ctxs = include.params;
break;
}
}
if (!isIncluded) return;
}

if (CONF.filter.exclude) {
for (var exclude of CONF.filter.exclude) {
if (name.toLowerCase().includes(exclude)) return;
if (isFilterMatched(name, exclude.name)) return;
}
}

Expand Down Expand Up @@ -154,7 +157,7 @@ var baseTest = (names => {
});
});
};
testFunc();
testFunc(ctxs);
};
})([]);
/**
Expand Down Expand Up @@ -201,4 +204,14 @@ var test = (name, opts, fixtures, func) => {
});
};

var isFilterMatched = (testName, filterName) => {
var result;
if (CONF.filter.precise) {
result = testName.toLowerCase() === filterName;
} else {
result = testName.toLowerCase().includes(filterName);
}
return result;
};

module.exports = test;
5 changes: 5 additions & 0 deletions lib/help.js
Expand Up @@ -53,6 +53,11 @@ module.exports = (d, cb) => {
type: "string",
group: "Core:",
},
"precise": {
describe: d("Precise tests inclusion or exclusion (not substring pattern)."),
type: "boolean",
group: "Core:",
},
"report [path]": {
describe: d("Path to reports folder. Default is 'cwd/reports'."),
type: "string",
Expand Down

0 comments on commit b86ca1c

Please sign in to comment.