Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP HTML Reporter: Fuzzy search using fuse #1441

Closed
wants to merge 9 commits into from
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
// Don't transpile modules since Rollup does that
[ "env", { modules: false } ]
],
"plugins": [ "external-helpers" ]
"plugins": [ "external-helpers", "babel-plugin-transform-object-rest-spread" ]
ventuno marked this conversation as resolved.
Show resolved Hide resolved
}
24 changes: 23 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"async": "2.6.0",
"babel-core": "6.26.0",
"babel-plugin-external-helpers": "6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "1.6.1",
"co": "4.6.0",
"commitplease": "3.1.0",
Expand All @@ -57,6 +58,7 @@
"execa": "0.8.0",
"fixturify": "0.3.4",
"fs-extra": "5.0.0",
"fuse.js": "^6.0.0",
"grunt": "1.0.4",
"grunt-cli": "1.2.0",
"grunt-concurrent": "2.3.1",
Expand Down
47 changes: 28 additions & 19 deletions reporter/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { extractStacktrace } from "../src/core/stacktrace";
import { now } from "../src/core/utilities";
import { window, navigator } from "../src/globals";
import "./urlparams";
import Fuse from "fuse.js";

const stats = {
passedTests: 0,
Expand Down Expand Up @@ -334,17 +335,17 @@ export function escapeText( s ) {
return filter;
}

function moduleListHtml() {
function moduleListHtml( modules ) {
var i, checked,
html = "";

for ( i = 0; i < config.modules.length; i++ ) {
if ( config.modules[ i ].name !== "" ) {
checked = config.moduleId.indexOf( config.modules[ i ].moduleId ) > -1;
for ( i = 0; i < modules.length; i++ ) {
if ( modules[ i ].name !== "" ) {
checked = config.moduleId.indexOf( modules[ i ].moduleId ) > -1;
html += "<li><label class='clickable" + ( checked ? " checked" : "" ) +
"'><input type='checkbox' " + "value='" + config.modules[ i ].moduleId + "'" +
"'><input type='checkbox' " + "value='" + modules[ i ].moduleId + "'" +
( checked ? " checked='checked'" : "" ) + " />" +
escapeText( config.modules[ i ].name ) + "</label></li>";
escapeText( modules[ i ].name ) + "</label></li>";
}
}

Expand All @@ -365,6 +366,12 @@ export function escapeText( s ) {
dropDownList = document.createElement( "ul" ),
dirty = false;

const options = {
keys: [ "name" ]
};

const fuse = new Fuse( config.modules, options );

moduleSearch.id = "qunit-modulefilter-search";
moduleSearch.autocomplete = "off";
addEvent( moduleSearch, "input", searchInput );
Expand Down Expand Up @@ -402,7 +409,7 @@ export function escapeText( s ) {
addEvent( commit, "click", applyUrlParams );

dropDownList.id = "qunit-modulefilter-dropdown-list";
dropDownList.innerHTML = moduleListHtml();
dropDownList.innerHTML = moduleListHtml( config.modules );

dropDown.id = "qunit-modulefilter-dropdown";
dropDown.style.display = "none";
Expand Down Expand Up @@ -448,20 +455,22 @@ export function escapeText( s ) {
}
}

function filterModules( searchText ) {
if ( searchText === "" ) {
return config.modules;
}
return fuse.search( searchText ).map( module => module.item );
}

// Processes module search box input
var searchInputTimeout;
function searchInput() {
var i, item,
searchText = moduleSearch.value.toLowerCase(),
listItems = dropDownList.children;

for ( i = 0; i < listItems.length; i++ ) {
item = listItems[ i ];
if ( !searchText || item.textContent.toLowerCase().indexOf( searchText ) > -1 ) {
item.style.display = "";
} else {
item.style.display = "none";
}
}
window.clearTimeout( searchInputTimeout );
searchInputTimeout = window.setTimeout( () => {
var searchText = moduleSearch.value.toLowerCase(),
filteredModules = filterModules( searchText );
dropDownList.innerHTML = moduleListHtml( filteredModules );
}, 200 );
}

// Processes selection changes
Expand Down