Closed boneskull closed 1 week ago
cc @Uzlopak - is this relevant to your work on canary-in-the-gold-mine (CIGTM) testing?
Closing out as it's been quite a few months without input. Presumably if this is still true, anybody working on the repo's e2e tests will be able to find more specific info & re-file.
As part of PR #4241, I was tweaking a few things in our test helper module, which helps Mocha call itself in a child process for end-to-end testing. It got me thinking a bit...
This is the current situation. I think we can do better:
runMocha
/runMochaAsync
spawnslib/cli/cli.js
and gathers some basic information about the run. Attempts to parse some information from the output. Because of this, usually not safe to captureSTDERR
or make assertions about error-related behavior. No access to child process handle.runMochaJSON
/runMochaJSONAsync
spawnslib/cli/cli.js --reporter=json
and gathers more detailed information, but an error coming out of Mocha (or capturing ofSTDERR
) will cause theJSON.parse()
call to error out, so best used for "happy path" tests. No access to child process handle.invokeMocha
/invokeMochaAsync
spawnsbin/mocha
(which may, in turn, spawn a child process) and provides raw output. The raw output can be subsequently parsed a larunMocha
/runMochaAsync
if Mocha doesn't output something interfering with the regex-based parsing code (getSummary()
). This is best used for testing errors, exceptions, etc, or interacting (non-IPC) with the subprocess.invokeMocha
returns the child process handleinvokeMochaAsync
returns a tuple of the child process handle and thePromise
Some observations:
invokeMochaAsync
is awkward to work with because of its return value.invoke*
)invoke*
STDERR
node
, which onlyinvoke*
supports.STDERR
, we weave it in withSTDOUT
into a single string in the result (output
), which causes parsing issues inrunMocha*
invoke*
invoke*
supports not passing a list of files to testnone of this is super-high-priority, but more obvious, consistent methods would absolutely make things easier for contributors.
if there was a proposal, I think it should be something like:
bin/mocha
, otherwise uselib/cli/cli.js
STDERR
,STDOUT
, & the like; it will return a result which contains each, and a third property which contains the "woven" output. we won't have to concern ourselves with passingstdio
orpipe
or whateverfailed
,passing
,pending
,total
, etc) . If it cannot parse the output, it should not throw an exception, but it should add a property to the result containing an exceptionPromise
unless a callback is supplied.detailed
, will attempt extra parsing; it will force use of--reporter=json
. If this fails, again, an exception should not be thrown but it should be returned in the result object--watch
, and--bail
when running a test file using this function w/o breaking the tests.STDERR
of a child process to the terminal (inherit
, I think?). This should not interfere with capturing ofSTDERR
, which should always happen.DEBUG
env var should not reach a child process.detailed: true
).invokeMochaAsync
test/assertions.js
) would need to be updated to support this new result object. Ideally, this will simplify them quite a bit, because we will only have a single object (a "type" in unexpected parlance) to match; currently we have three (3), corresponding to the return values ofrunMocha
/runMochaJSON
/invokeMocha
, respectively