Giter VIP home page Giter VIP logo

mocha-es6-modules's Introduction

Mocha ES6 modules example

An example of running Mocha tests as a native ES6 modules in a browser.

  • If browser supports ES6 modules — the are used. 
  • If browser does not support ES6 modules — the page fallbacks to bundled script.

You can check it online in your browser.

With ES modules (Chrome >= 62):

Mocha tests With ES modules

Without ES modules (Firefox 57):

Mocha tests Without ES modules

Run locally

  1. Clone the repo:
    git clone https://github.com/vitalets/mocha-es6-modules.git
    cd mocha-es6-modules
  2. Install dependencies:
    npm install
  3. Build non-es6 version:
    npm run build
  4. Start local http server:
    npm run server
  5. Open http://localhost:8000 in browser.

mocha-es6-modules's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mocha-es6-modules's Issues

Update this

Could you update this and the blog article ? Many things has changed since 2017.
I try something similar of what you did, but using parcel to bundle the tests and launch on the browser.

Is a web server required?

Hi @vitalets, I just cloned this repo and tried to open index.html in my browser. Everything failed because none of the javascript files were allowed to be downloaded due to CORS. I don't understand how this could be useful if I need to set up a web server in order to run the tests. How did you get around this?

As long as I import a node module it fails to work

First of all, your article and example is very helpful. Thank you!

But as long as I import a node module, as any "real" project will do, it fails to work. For example I add

import debug from 'debug' to sum.js then I will get the error

Uncaught TypeError: Failed to resolve module specifier "debug". Relative references must start with either "/", "./", or "../".

Any idea how can I fix it ? The last resort of course will be using webpack to bundle them into a single file, but I was hoping if there is any easy solution without bundling.

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.