mochify.js icon indicating copy to clipboard operation
mochify.js copied to clipboard

--bundle and --consolify don't play well with subfolders

Open jonny-improbable opened this issue 8 years ago • 3 comments

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>)

jonny-improbable avatar Jul 14 '16 20:07 jonny-improbable

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.

  1. 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 the script tag's src attribute.
  2. 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 avatar Jul 15 '16 13:07 jonnyreeves

@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.

mantoni avatar Jul 15 '16 13:07 mantoni

What is the status here? What is left to do in mochify.js?

mantoni avatar Jun 02 '17 09:06 mantoni