Code Monkey home page Code Monkey logo

Comments (2)

m90 avatar m90 commented on June 5, 2024

I think I would like to look into this (in case noone else started yet) as, quite frankly, I know nothing about ESM at all and it starts to get embarassing. Maybe I can use this to get up to speed.

There's one thing I do not fully understand here yet (probably a good demonstration of how I know nothing about ESM):

Assuming someone runs the following command:

mochify ./src/foo.test.js --driver puppeteer --inject-modules

and src/foo.test.js looks like this:

import * as assert from 'assert'
import * as foo from './foo.js'

describe('foo', function () {
  it('does not throw when calling bar', function () {
    assert.doesNotThrow(function () {
      foo.bar()
    })
  })
})

Mochify would then inject (I think?):

<script>/* mocha ... */</script>
<script>/* client ... */</script>
<script type="module">
  /* above test case */
</script>

What I am failing to understand now is the following: how does the test case resolve:

  1. modules like assert or other libraries without bundling
  2. source files like ./foo.js?

Is 1 even possible? Would 2 work out of the box in case users would pass --serve ./src or would this require extra setup to be taken (assuming that inlining the test cases would break import paths)? Would the source document instead need to load the files something like <script src="/foo.test.js" type="module"></script>?

from mochify.js.

mantoni avatar mantoni commented on June 5, 2024

modules like assert or other libraries without bundling

That wouldn't work. There are already other solutions that generate mini-bundles on request. We could pass requested files through a bundler, if one is specified. Not sure here and it might be out of scope for Mochify.

Would the source document instead need to load the files something like <script src="/foo.test.js" type="module"></script>?

This is how I would do it, yes. A server is required anyway to be able to import anything with esm. I guess generating the script tags is all that is needed for now.

from mochify.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.