mochify.js
mochify.js copied to clipboard
--bundle and --consolify don't play well with subfolders
The HTML runner generated using the --consolify
flag does not resolve the relative path to the bundle generated by the --bundle
flag; instead the absolute value is used.
Steps to repro:
Run mochify
over a test suite specifying both a --bundle
and --consolify
flag whose value points to a subfolder (eg: tmp
).
mkdir tmp
mochify --recursive test/ --bundle tmp/tests.js --consolify tmp/runner.html
Expected
- tmp/tests.js is created
- tmp/runner.html is created
- tmp/runner.html resolves the relative path to the javascript bundle and includes it via a script tag (ie:
<script src="./tests.js">
)
Actual
- tmp/tests.js is created
- tmp/runner.html is created
- tmp/runner.html attempts to load the bundle using the exact value passed to the
--bundle
flag (ie:<script src="tmp/tests.js>
)
As mentioned in #141, I was unable to solve this in mochify.js directly as consolify is responsible for writing the bundle (and therefore requires the absolute path for its output).
I can think of a couple of ways to solve this, but both will require a change to consolify's API and mochfy.js's invocation of it.
- Supply the
opts.consolify
value to consolify so it knows where the final html document will be written to; it can then use this to resolve the relative path for populating thescript
tag'ssrc
attribute. - Modify consolify so it doesn't write the bundle to disk but instead writes to to a stream supplied by mochify.
Welcome to any other suggestions you have @mantoni?
@jonnyreeves I think it makes sense to add a -o
/ --outfile
option to consolify. The current behavior could remain as the default. Ideally we can kill the internal wrapper and remove the consolify dependency.
What is the status here? What is left to do in mochify.js?