From 474a70874478173a009c8ec53ef2c3c6f9dfec75 Mon Sep 17 00:00:00 2001 From: ventuno Date: Thu, 4 Jun 2020 09:03:47 -0700 Subject: [PATCH] HTML Reporter: Fuzzy search using fuzzysort (#1440) * HTML Reporter: Fuzzy search using fuzzysort. * HTML Reporter: Fuzzy search using fuzzysort (threshold: -10000). --- package-lock.json | 59 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ reporter/html.js | 11 +++++++-- rollup.config.js | 8 ++++++- 4 files changed, 77 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4e0ad46af..4af7a2586 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2025,6 +2025,12 @@ "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, + "fuzzysort": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/fuzzysort/-/fuzzysort-1.1.4.tgz", + "integrity": "sha512-JzK/lHjVZ6joAg3OnCjylwYXYVjRiwTY6Yb25LvfpJHK8bjisfnZJ5bY8aVWwTwCXgxPNgLAtmHL+Hs5q1ddLQ==", + "dev": true + }, "gaze": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/gaze/-/gaze-1.1.3.tgz", @@ -3091,6 +3097,15 @@ "yallist": "^2.1.2" } }, + "magic-string": { + "version": "0.22.5", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.22.5.tgz", + "integrity": "sha512-oreip9rJZkzvA8Qzk9HFs8fZGF/u7H/gtrE8EN6RjKJ9kh2HlC+yQ2QezifqTZfGyiuAV0dRv5a+y/8gBb1m9w==", + "dev": true, + "requires": { + "vlq": "^0.2.2" + } + }, "map-obj": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz", @@ -3955,6 +3970,44 @@ "rollup-pluginutils": "^1.5.0" } }, + "rollup-plugin-commonjs": { + "version": "8.4.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-8.4.1.tgz", + "integrity": "sha512-mg+WuD+jlwoo8bJtW3Mvx7Tz6TsIdMsdhuvCnDMoyjh0oxsVgsjB/N0X984RJCWwc5IIiqNVJhXeeITcc73++A==", + "dev": true, + "requires": { + "acorn": "^5.2.1", + "estree-walker": "^0.5.0", + "magic-string": "^0.22.4", + "resolve": "^1.4.0", + "rollup-pluginutils": "^2.0.1" + }, + "dependencies": { + "estree-walker": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.5.2.tgz", + "integrity": "sha512-XpCnW/AE10ws/kDAs37cngSkvgIR8aN3G0MS85m7dUpuK2EREo9VJ00uvw6Dg/hXEpfsE1I1TvJOJr+Z+TL+ig==", + "dev": true + }, + "rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", + "dev": true, + "requires": { + "estree-walker": "^0.6.1" + }, + "dependencies": { + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + } + } + } + } + }, "rollup-plugin-node-resolve": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-3.4.0.tgz", @@ -4659,6 +4712,12 @@ "extsprintf": "^1.2.0" } }, + "vlq": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/vlq/-/vlq-0.2.3.tgz", + "integrity": "sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==", + "dev": true + }, "websocket-driver": { "version": "0.7.3", "resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.3.tgz", diff --git a/package.json b/package.json index 935492623..1fac32735 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" }, diff --git a/reporter/html.js b/reporter/html.js index b3c3a321f..708c7a113 100644 --- a/reporter/html.js +++ b/reporter/html.js @@ -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, @@ -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 ); @@ -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 diff --git a/rollup.config.js b/rollup.config.js index cf428b14f..c12736181 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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() ],