-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add support for asynchronous assertions through logging #118
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
lib/doctest.mjs
Outdated
'const ' + logFunction + ' = channel => value => {', | ||
' __doctest.logMediator.emit ({channel, value});', | ||
'};', |
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.
I think this is our first use of arrow functions. Should we also use () => {}
in place of function() {}
a few lines above?
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.
Oh. Perhaps I should use a regular function.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
value: value | ||
}); | ||
output ($test); | ||
if (!$test[OUTPUT].some (isStandardOutput)) { |
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 if statement actually describes another state in our state machine implicitly. It would not have to be there if we had two separate states for logging: SYNC_LOG
and ASYNC_LOG
. While the state machine is in SYNC_LOG
, it allows transitions to the OUTPUT
state, but while it's in ASYNC_LOG
it only allows transitions to itself or CLOSED
.
It might be nicer to implement it like that.
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.
The valid state transitions would then be something like:
CLOSED -> CLOSED
CLOSED -> OPEN
OPEN -> INPUT
INPUT -> INPUT
INPUT -> MORE_INPUT
INPUT -> SYNC_LOG
INPUT -> OUTPUT
INPUT -> ASYNC_LOG
INPUT -> CLOSED
MORE_INPUT -> MORE_INPUT
MORE_INPUT -> SYNC_LOG
MORE_INPUT -> OUTPUT
MORE_INPUT -> ASYNC_LOG
MORE_INPUT -> CLOSED
SYNC_LOG -> SYNC_LOG
SYNC_LOG -> MORE_SYNC_LOG
SYNC_LOG -> OUTPUT
SYNC_LOG -> ASYNC_LOG
SYNC_LOG -> INPUT
SYNC_LOG -> CLOSED
MORE_SYNC_LOG -> SYNC_LOG
MORE_SYNC_LOG -> MORE_SYNC_LOG
MORE_SYNC_LOG -> OUTPUT
MORE_SYNC_LOG -> ASYNC_LOG
MORE_SYNC_LOG -> INPUT
MORE_SYNC_LOG -> CLOSED
OUTPUT -> MORE_OUTPUT
OUTPUT -> ASYNC_LOG
OUTPUT -> INPUT
OUTPUT -> CLOSED
MORE_OUTPUT -> MORE_OUTPUT
MORE_OUTPUT -> ASYNC_LOG
MORE_OUTPUT -> INPUT
MORE_OUTPUT -> CLOSED
ASYNC_LOG -> ASYNC_LOG
ASYNC_LOG -> MORE_ASYNC_LOG
ASYNC_LOG -> INPUT
ASYNC_LOG -> CLOSED
MORE_ASYNC_LOG -> ASYNC_LOG
MORE_ASYNC_LOG -> MORE_ASYNC_LOG
MORE_ASYNC_LOG -> INPUT
MORE_ASYNC_LOG -> CLOSED
I just took a shower and regained my sanity. The now blindingly obvious solution is to parse only the words provided on the CLI. It solves the "how should our regex be" issue, and regains our backwards compat: No |
73ee48e
to
e0df4bd
Compare
For full history see 73ee48e.
The idea
Tests can use
channel (value)
to produce additional output besides the return value of the expression:Doctest asserts that all output channels produce their output in the expected order, on the expected channel. In the above example, we even assert that
[stdout]: 2
was produced asynchronously (afterundefined
was returned from the expression).The philosophy is that the code example will contain exactly that which the Node REPL would when run with:
TODO
run
functionFeedback
Tests
--log-function
option was not given