Skip to content

Commit

Permalink
Support full-text search in docs of steps and fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
schipiga committed Mar 13, 2018
1 parent 72dd1a9 commit 3689acb
Show file tree
Hide file tree
Showing 4 changed files with 1,484 additions and 310 deletions.
4 changes: 3 additions & 1 deletion lib/run.js
Expand Up @@ -14,14 +14,16 @@
var fs = require("fs");
var path = require("path");

require("docstring");
var fse = require("fs-extra");
var Mocha = require("mocha");
var U = require("glace-utils");

var CONF = require("./config");
var hacking = require("./hacking");
var tools = require("./tools");

U.docString();

var run = cb => {
resetReport();

Expand Down
75 changes: 35 additions & 40 deletions lib/tools.js
Expand Up @@ -32,32 +32,30 @@ self.listSteps = filter => {
Object.getOwnPropertyNames(SS),
Object.getOwnPropertyNames(Object.getPrototypeOf(SS))
).sort()
.filter(i => i.toLowerCase().includes(filter))
.filter(i => !i.startsWith("_"))
.filter(i => /^\w+$/.test(i))
.filter(i => /^\D/.test(i))
.filter(i => util.isFunction(SS[i]));
.filter(i => /^\D/.test(i));

var i = 0;
for (var s of steps) {
console.log(d(`${++i}. ${s}:`));
console.log(d(` ${SS[s].toString().split("{")[0]}{...}`));
var func = SS[s];

if (!util.isFunction(func)) continue;

var doc = SS[s]
.__doc__
.split("\n")
.map(i => i.trim())
.filter(i => i)
.map(i => ` ${i}`)
.join("\n");
var doc = getDoc(func);
if (!(s.toLowerCase().includes(filter) ||
(doc && doc.toLowerCase().includes(filter)))) continue;

console.log(d(`${++i}. ${s}:`));
console.log(d(` ${func.toString().split("{")[0]}{...}`));

if (doc) {
doc = ` /**\n${doc}\n */`;
console.log(highlight(doc, { language: "js" }));
}
};

if (steps.length === 0) {
if (i === 0) {
console.log("No steps are found".yellow);
};
};
Expand All @@ -67,21 +65,16 @@ self.listTests = filter => {

load();

var conf = require("./config"),
testCase, testCases = [];

for (testCase of conf.testCases) {
if (testCase.name.toLowerCase().includes(filter)) {
testCases.push(testCase);
}
}
var conf = require("./config");

var i = 0;
for (testCase of testCases) {
for (var testCase of conf.testCases) {
if (!testCase.name.toLowerCase().includes(filter)) continue;

console.log(d(`${++i}. ${testCase.name}`));
};

if (testCases.length === 0) {
if (i === 0) {
console.log("No tests are found".yellow);
};
};
Expand All @@ -91,36 +84,38 @@ self.listFixtures = filter => {

load();

var fx, fixtures = [];
for (fx in global) {
if (fx.startsWith("fx") && fx.includes(filter)) {
fixtures.push(fx);
}
}

var i = 0;
for (fx of fixtures) {
console.log(d(`${++i}. ${fx}`));
for (var fx in global) {
if (!fx.startsWith("fx")) continue;

var doc = global[fx]
.__doc__
.split("\n")
.map(i => i.trim())
.filter(i => i)
.map(i => ` ${i}`)
.join("\n");
var doc = getDoc(global[fx]);

if (!(fx.toLowerCase().includes(filter) ||
(doc && doc.toLowerCase().includes(filter)))) continue;

console.log(d(`${++i}. ${fx}`));

if (doc) {
doc = ` /**\n${doc}\n */`;
console.log(highlight(doc, { language: "js" }));
}
};

if (fixtures.length === 0) {
if (i === 0) {
console.log("No fixtures are found".yellow);
};
};

var getDoc = func => {
return func
.__doc__
.split("\n")
.map(i => i.trim())
.filter(i => i)
.map(i => ` ${i}`)
.join("\n");
};

var load = () => {
global.before = () => {};
global.after = () => {};
Expand Down

0 comments on commit 3689acb

Please sign in to comment.