Commit 450c434d authored by Jakob Moser's avatar Jakob Moser
Browse files

Start adding clear after verify

parent cebfd8f0
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -246,6 +246,8 @@ class ExerciseExecutionContext {
        // if no command is provided, directly start with a resolved promise.
        const commandPromise = command ? runCommand(command) : Promise.resolve()
        const verifyHandler = this._verifyHandler
        // TODO This won't work if the user is already retrying the exercise, because then the public clear API is disabled
        const clear = this.clear.bind(this)

        return {
            /**
@@ -260,7 +262,7 @@ class ExerciseExecutionContext {
             */
            hasOutput(param) {
                // Wait until the VM has processed the input and written some output to the terminal
                commandPromise.then(() => {
                commandPromise.then(async () => {
                    const terminalContents = getTerminalContents()
                    const latestEntry = terminalContents[terminalContents.length - 1]

@@ -278,6 +280,7 @@ class ExerciseExecutionContext {
                    // !! converts any value to a boolean (not a special operator, just two ! (boolean not) operators in series)
                    const result = !!predicate(latestEntry.output)

                    await clear()
                    verifyHandler(result)
                })
            },
@@ -292,7 +295,7 @@ class ExerciseExecutionContext {
             * @param {Function|String} param String to exactly match, or predicate function
             */
            commandWas(param) {
                commandPromise.then(() => {
                commandPromise.then(async () => {
                    const terminalContents = getTerminalContents()
                    const latestEntry = terminalContents[terminalContents.length - 1]

@@ -304,6 +307,7 @@ class ExerciseExecutionContext {

                    const result = !!predicate(latestEntry.input)

                    await clear()
                    verifyHandler(result)
                })
            }