This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add source client in logs and filtering function for commands
* Adding the ability to click the source lines and stack frame lines * Add command filtering function
- Loading branch information
Showing
9 changed files
with
263 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import filterCommands from "./index" | ||
|
||
const TEST_COMMANDS = [ | ||
{ type: "SEARCHTYPE" }, | ||
{ type: "ADUMMYOBJ", payload: { message: "SEARCHMESSAGE" } }, | ||
{ type: "ADUMMYOBJ", payload: { preview: "SEARCHPREVIEW" } }, | ||
{ type: "ADUMMYOBJ", payload: { name: "SEARCHNAME" } }, | ||
{ type: "ADUMMYOBJ", payload: { path: "SEARCHPATH" } }, | ||
{ type: "ADUMMYOBJ", payload: { triggerType: "SEARCHTRIGGERTYPE" } }, | ||
{ type: "ADUMMYOBJ", payload: { description: "SEARCHDESCRIPTION" } }, | ||
{ type: "ADUMMYOBJ", payload: { request: { url: "SEARCHURL" } } }, | ||
{ type: "log", payload: { debug: "LOGDEBUG" } }, | ||
{ type: "client.intro", payload: { connection: "SEARCHCONNECTION" } }, | ||
] | ||
|
||
const TESTS = [ | ||
{ name: "type", search: "SEARCHTYPE", result: [{ type: "SEARCHTYPE" }] }, | ||
{ | ||
name: "payload.message", | ||
search: "SEARCHMESSAGE", | ||
result: [{ type: "ADUMMYOBJ", payload: { message: "SEARCHMESSAGE" } }], | ||
}, | ||
{ | ||
name: "payload.preview", | ||
search: "SEARCHPREVIEW", | ||
result: [{ type: "ADUMMYOBJ", payload: { preview: "SEARCHPREVIEW" } }], | ||
}, | ||
{ | ||
name: "payload.name", | ||
search: "SEARCHNAME", | ||
result: [{ type: "ADUMMYOBJ", payload: { name: "SEARCHNAME" } }], | ||
}, | ||
{ | ||
name: "payload.path", | ||
search: "SEARCHPATH", | ||
result: [{ type: "ADUMMYOBJ", payload: { path: "SEARCHPATH" } }], | ||
}, | ||
{ | ||
name: "payload.triggerType", | ||
search: "SEARCHTRIGGERTYPE", | ||
result: [{ type: "ADUMMYOBJ", payload: { triggerType: "SEARCHTRIGGERTYPE" } }], | ||
}, | ||
{ | ||
name: "payload.description", | ||
search: "SEARCHDESCRIPTION", | ||
result: [{ type: "ADUMMYOBJ", payload: { description: "SEARCHDESCRIPTION" } }], | ||
}, | ||
{ | ||
name: "payload.request.url", | ||
search: "SEARCHURL", | ||
result: [{ type: "ADUMMYOBJ", payload: { request: { url: "SEARCHURL" } } }], | ||
}, | ||
{ | ||
name: "log => debug", | ||
search: "debug", | ||
result: [{ type: "log", payload: { debug: "LOGDEBUG" } }], | ||
}, | ||
{ | ||
name: "log => warning", | ||
search: "warning", | ||
result: [{ type: "log", payload: { debug: "LOGDEBUG" } }], | ||
}, | ||
{ | ||
name: "log => error", | ||
search: "error", | ||
result: [{ type: "log", payload: { debug: "LOGDEBUG" } }], | ||
}, | ||
{ | ||
name: "clientIntro => connection", | ||
search: "connection", | ||
result: [{ type: "client.intro", payload: { connection: "SEARCHCONNECTION" } }], | ||
}, | ||
{ | ||
name: "multiple results", | ||
search: "ADUMMYOBJ", | ||
result: [ | ||
{ type: "ADUMMYOBJ", payload: { message: "SEARCHMESSAGE" } }, | ||
{ type: "ADUMMYOBJ", payload: { preview: "SEARCHPREVIEW" } }, | ||
{ type: "ADUMMYOBJ", payload: { name: "SEARCHNAME" } }, | ||
{ type: "ADUMMYOBJ", payload: { path: "SEARCHPATH" } }, | ||
{ type: "ADUMMYOBJ", payload: { triggerType: "SEARCHTRIGGERTYPE" } }, | ||
{ type: "ADUMMYOBJ", payload: { description: "SEARCHDESCRIPTION" } }, | ||
{ type: "ADUMMYOBJ", payload: { request: { url: "SEARCHURL" } } }, | ||
], | ||
}, | ||
] | ||
|
||
describe("utils/filterCommands", () => { | ||
TESTS.forEach(test => { | ||
it(`should search in '${test.name}'`, () => { | ||
const result = filterCommands(TEST_COMMANDS, test.search) | ||
|
||
expect(result).toEqual(test.result) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
function path(...searchPath) { | ||
return obj => { | ||
let scaledObj = obj | ||
|
||
for (let i = 0; i < searchPath.length; i++) { | ||
scaledObj = scaledObj[searchPath[i]] | ||
|
||
if (typeof scaledObj === "undefined" || scaledObj === null) return null | ||
} | ||
|
||
return scaledObj | ||
} | ||
} | ||
|
||
const COMMON_MATCHING_PATHS = [ | ||
path("type"), | ||
path("payload", "message"), | ||
path("payload", "preview"), | ||
path("payload", "name"), | ||
path("payload", "path"), | ||
path("payload", "triggerType"), | ||
path("payload", "description"), | ||
path("payload", "request", "url"), | ||
] | ||
|
||
function filterCommands(commands: any[], search: string) { | ||
const trimmedSearch = (search || "").trim() | ||
const searchRegex = new RegExp(trimmedSearch.replace(/\s/, "."), "i") | ||
|
||
const matching = (value: string) => value && typeof value === "string" && searchRegex.test(value) | ||
|
||
return commands.filter( | ||
command => | ||
COMMON_MATCHING_PATHS.filter(c => { | ||
if (matching(c(command))) return true | ||
if ( | ||
command.type === "log" && | ||
(matching("debug") || matching("warning") || matching("error")) | ||
) | ||
return true | ||
if (command.type === "client.intro" && matching("connection")) return true | ||
return false | ||
}).length > 0 | ||
) | ||
} | ||
|
||
export default filterCommands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = function(wallaby) { | ||
return { | ||
files: ["src/**/*.ts", "!src/**/*.test.ts"], | ||
|
||
tests: ["src/**/*.test.ts"], | ||
|
||
compilers: { | ||
"**/*.ts": wallaby.compilers.babel(), | ||
}, | ||
|
||
env: { | ||
type: "node", | ||
runner: "node", | ||
}, | ||
|
||
testFramework: "jest", | ||
} | ||
} |
Oops, something went wrong.