Skip to content

Commit

Permalink
HTML Reporter: Fuzzy search using fuzzysort (#1440)
Browse files Browse the repository at this point in the history
* HTML Reporter: Fuzzy search using fuzzysort.
* HTML Reporter: Fuzzy search using fuzzysort (threshold: -10000).
  • Loading branch information
ventuno authored Jun 4, 2020
1 parent f0038b8 commit 474a708
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
59 changes: 59 additions & 0 deletions 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 @@ -57,6 +57,7 @@
"execa": "0.8.0",
"fixturify": "0.3.4",
"fs-extra": "5.0.0",
"fuzzysort": "^1.1.4",
"grunt": "1.0.4",
"grunt-cli": "1.2.0",
"grunt-concurrent": "2.3.1",
Expand All @@ -75,6 +76,7 @@
"proxyquire": "1.8.0",
"requirejs": "2.3.5",
"rollup-plugin-babel": "3.0.2",
"rollup-plugin-commonjs": "^8.0.0",
"rollup-plugin-node-resolve": "^3.4.0",
"semver": "5.4.1"
},
Expand Down
11 changes: 9 additions & 2 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 fuzzysort from "fuzzysort";

const stats = {
passedTests: 0,
Expand Down Expand Up @@ -372,6 +373,8 @@ export function escapeText( s ) {
addEvent( moduleSearch, "focus", searchFocus );
addEvent( moduleSearch, "click", searchFocus );

config.modules.forEach( module => module.namePrepared = fuzzysort.prepare( module.name ) );

label.id = "qunit-modulefilter-search-container";
label.innerHTML = "Module: ";
label.appendChild( moduleSearch );
Expand Down Expand Up @@ -449,8 +452,12 @@ export function escapeText( s ) {
}

function filterModules( searchText ) {
return config.modules
.filter( module => module.name.toLowerCase().indexOf( searchText ) > -1 );
if ( searchText === "" ) {
return config.modules;
}
return fuzzysort
.go( searchText, config.modules, { key: "namePrepared", threshold: -10000 } )
.map( module => module.obj );
}

// Processes module search box input
Expand Down
8 changes: 7 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

var babel = require( "rollup-plugin-babel" );
var resolve = require( "rollup-plugin-node-resolve" );
var commonjs = require( "rollup-plugin-commonjs" );

module.exports = {
format: "iife",
exports: "none",
plugins: [
resolve( { modulesOnly: true } ),
resolve(),
commonjs( {
namedExports: {
"fuzzysort": [ "fuzzysort" ]
}
} ),
babel()
],

Expand Down

0 comments on commit 474a708

Please sign in to comment.