Skip to content

Commit 474a708

Browse files
authored
HTML Reporter: Fuzzy search using fuzzysort (#1440)
* HTML Reporter: Fuzzy search using fuzzysort. * HTML Reporter: Fuzzy search using fuzzysort (threshold: -10000).
1 parent f0038b8 commit 474a708

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

package-lock.json

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"execa": "0.8.0",
5858
"fixturify": "0.3.4",
5959
"fs-extra": "5.0.0",
60+
"fuzzysort": "^1.1.4",
6061
"grunt": "1.0.4",
6162
"grunt-cli": "1.2.0",
6263
"grunt-concurrent": "2.3.1",
@@ -75,6 +76,7 @@
7576
"proxyquire": "1.8.0",
7677
"requirejs": "2.3.5",
7778
"rollup-plugin-babel": "3.0.2",
79+
"rollup-plugin-commonjs": "^8.0.0",
7880
"rollup-plugin-node-resolve": "^3.4.0",
7981
"semver": "5.4.1"
8082
},

reporter/html.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { extractStacktrace } from "../src/core/stacktrace";
44
import { now } from "../src/core/utilities";
55
import { window, navigator } from "../src/globals";
66
import "./urlparams";
7+
import fuzzysort from "fuzzysort";
78

89
const stats = {
910
passedTests: 0,
@@ -372,6 +373,8 @@ export function escapeText( s ) {
372373
addEvent( moduleSearch, "focus", searchFocus );
373374
addEvent( moduleSearch, "click", searchFocus );
374375

376+
config.modules.forEach( module => module.namePrepared = fuzzysort.prepare( module.name ) );
377+
375378
label.id = "qunit-modulefilter-search-container";
376379
label.innerHTML = "Module: ";
377380
label.appendChild( moduleSearch );
@@ -449,8 +452,12 @@ export function escapeText( s ) {
449452
}
450453

451454
function filterModules( searchText ) {
452-
return config.modules
453-
.filter( module => module.name.toLowerCase().indexOf( searchText ) > -1 );
455+
if ( searchText === "" ) {
456+
return config.modules;
457+
}
458+
return fuzzysort
459+
.go( searchText, config.modules, { key: "namePrepared", threshold: -10000 } )
460+
.map( module => module.obj );
454461
}
455462

456463
// Processes module search box input

rollup.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
var babel = require( "rollup-plugin-babel" );
44
var resolve = require( "rollup-plugin-node-resolve" );
5+
var commonjs = require( "rollup-plugin-commonjs" );
56

67
module.exports = {
78
format: "iife",
89
exports: "none",
910
plugins: [
10-
resolve( { modulesOnly: true } ),
11+
resolve(),
12+
commonjs( {
13+
namedExports: {
14+
"fuzzysort": [ "fuzzysort" ]
15+
}
16+
} ),
1117
babel()
1218
],
1319

0 commit comments

Comments
 (0)