-
Notifications
You must be signed in to change notification settings - Fork 1
Add console log and outputs #39
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
Conversation
Passes the console log output from the test to the frontend to be displayed for the user in a new output pane.
When a single command results in multiple lines of output, we need to show all these lines to the user.
Makes console log outputs underlined in yellow and errors underlined in red.
@@ -25,7 +25,9 @@ function refresh() { | |||
let IDENTIFIER_MAP = { | |||
highlight, | |||
refresh, | |||
console, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add console as a default available command
package/src/commandParser.js
Outdated
throw Error( | ||
`Error printed to console.error. This error occurred asynchronously, and may have happened before this line was executed.\n\n${consoleLog.arguments[0]}` | ||
); | ||
await delay(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a delay after every command to give the React code time to update and to send logs/errors.
package/src/commandParser.js
Outdated
for (const consoleLog of consoleLogQueue) { | ||
if (!consoleLog.seen) { | ||
consoleLog.seen = true; | ||
|
||
for (const arg of consoleLog.arguments) { | ||
if (consoleLog.method === "error") { | ||
consoleOutputs.push({ | ||
type: "error", | ||
message: `Error printed to console.error. This error occurred asynchronously, and may have happened before this line was executed.\n\n${arg}`, | ||
lineNumber, | ||
}); | ||
} else { | ||
consoleOutputs.push({ | ||
message: String(arg), | ||
type: consoleLog.method, | ||
lineNumber, | ||
}); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get every type of output, note the type and send it to the user.
@@ -61,6 +61,9 @@ export const debuggerSetup = async (fn) => { | |||
consoleLogQueue.push({ method: "log", arguments: arguments }); | |||
return _log.apply(console, arguments); | |||
}; | |||
console.log_without_reporting = function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retain an alias for the original console.log that we can use to output lines only to the console, and not to the user in the UI.
@@ -175,11 +178,7 @@ fastify.post("/command", async (request, reply) => { | |||
html: addStyleLinks( | |||
replaceFilePaths(document.documentElement.innerHTML, manifest) | |||
), | |||
error: output.error && { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer report errors separately, just send consoleOutputs with their type.
} | ||
|
||
.editor-div { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This setup allows each code mirror instance on the page to fill an equal amount of space vertically! Before this we were doing some less than idea layout management with things like calc(50vh - 100px)
@@ -21,12 +31,13 @@ function CommandInput({ setInnerHTML, availableCommands }) { | |||
...existingHistory, | |||
{ | |||
content: "", | |||
errors: [], | |||
consoleOutputs: [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like on the backend, get rid of tracking errors independently and only track the console outputs. Within each output we have a type which can be error
or log
(or potentially info
etc).
wasReset: false, | ||
}, | ||
]; | ||
}); | ||
const [editorValue, setEditorValue] = useState(""); | ||
const [output, setOutput] = useState(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a new output state which is the most recent output from a command.
test-runner/src/CommandInput.js
Outdated
/> | ||
</div> | ||
<h1 className="code-window-titles">Output</h1> | ||
<div className="editor-div"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Show the most recent output
@@ -40,7 +40,7 @@ import { | |||
const completePropertyAfter = ["PropertyName", ".", "?."]; | |||
|
|||
const fixedHeightEditor = EditorView.theme({ | |||
"&": { height: "calc(50vh - 100px)" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we're properly using flexbox we can change this to 100%!
|
||
const errorEffect = StateEffect.define({}); | ||
const errorState = StateField.define({ | ||
const consoleEffect = StateEffect.define({}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename a lot of things from error to console to make them more generic.
}), | ||
sort: true, | ||
}); | ||
if (consoleEffects.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new check plus the line below (148 filter: () => false
) means that we:
- Only update this when the effect update contains a consoleEffect
- Remove all of the existing consoleEffect, and adds them all back
Prior to this we had to make sure to only add the new consoleEffects or else we would double add them. This filter, then add approach is better for our case since we maintain the total list of consoleEffects outside of the editor and pass it in every time.
error: error.message, | ||
}); | ||
}) | ||
.filter((error) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer need this filter because of: https://github.com/mdbenjam/testing-library-visualizer/pull/39/files#r833385524
… into mdbenjam/add-output-view
🎉 This PR is included in version 1.0.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR:
ConsoleLog.mp4