Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jasmine ES6 run script for use with Babel 6
$ npm install --save babel-cli babel-preset-es2015
$ npm install --save-dev jasmine

.babelrc:

{
  "presets": ["es2015"]
}

package.json:

"scripts": {
  "test": "babel-node spec/run.js"
},
…

spec/run.js:

import Jasmine from 'jasmine'

var jasmine = new Jasmine()
jasmine.loadConfigFile('spec/support/jasmine.json')
jasmine.execute()
@krawaller

This comment has been minimized.

Copy link

commented Jan 15, 2016

Thank you for this, worked perfectly for me! Like you I couldn't quite get Jasmine-ES6 to work, so I was very happy to find your issue there pointing me to this gist. Thank you again! :)

@wiredearp

This comment has been minimized.

Copy link

commented Feb 27, 2016

👍

@egee-irl

This comment has been minimized.

Copy link

commented Mar 17, 2016

Dunno what the heck is wrong with Jasmine-ES6 but, these steps worked for me.

@kevgathuku

This comment has been minimized.

Copy link

commented Apr 30, 2016

You're a lifesaver! Thanks a lot for the script 🚀

@d4nidev

This comment has been minimized.

Copy link

commented May 13, 2016

Kudos for you!

@fishermanswharff

This comment has been minimized.

Copy link

commented May 27, 2016

This is the best way to implement Jasmine specs and ES6. Thanks for this.

@happypoulp

This comment has been minimized.

Copy link

commented Jun 1, 2016

Thanks a lot!

@jhenaoz

This comment has been minimized.

Copy link

commented Jul 5, 2016

Thanks a lot, huge post!

@bildepunkt

This comment has been minimized.

Copy link

commented Sep 30, 2016

👍

@moshmage

This comment has been minimized.

Copy link

commented Oct 16, 2016

Any luck on getting coverage for this setup ?

@amypellegrini

This comment has been minimized.

Copy link

commented Oct 27, 2016

You saved my life or prevented a probable insanity attack <3

@vaidik

This comment has been minimized.

Copy link

commented Mar 13, 2017

Awesomeness!

@dazjavier

This comment has been minimized.

Copy link

commented Apr 26, 2017

Works perfectly, thanks!

@lrettig

This comment has been minimized.

Copy link

commented May 2, 2017

Awesome :) Would it be possible to extend this to support passing command line args into jasmine, e.g., to run an individual spec?

@smasala

This comment has been minimized.

Copy link

commented May 5, 2017

Great solution!

@birhanuh

This comment has been minimized.

Copy link

commented Jun 26, 2017

Working solution! Thanks!

@erichulburd

This comment has been minimized.

Copy link

commented Aug 12, 2017

Anyone else?

var jasmine = new Jasmine();
              ^

TypeError: Jasmine is not a constructor

I also use this with karma:

{
  "scripts": {
    "test-node": "babel-node jasmine.js"
  },
  "pre-commit": [
    "lint",
    "test"
  ],
  "license": "MIT",
  "dependencies": {
    "babel-plugin-module-resolver": "^2.7.1",
    "babel-polyfill": "^6.20.0",
    "babel-preset-latest": "^6.24.1",
    "bootstrap": "^3.3.7",
    "cookie-parser": "^1.4.3",
    "d3": "^4.4.0",
    "ease-component": "1.0.x",
    "ejs": "^2.5.5",
    "espina": "^1.1.1",
    "express": "^4.14.0",
    "firebase": "^3.6.4",
    "flipclock": "^0.7.8",
    "font-awesome": "^4.7.0",
    "i18next": "^4.1.1",
    "i18next-node-fs-backend": "^0.1.3",
    "i18next-xhr-backend": "^1.2.1",
    "immutability-helper": "^2.0.0",
    "jasmine": "^2.7.0",
    "jspdf": "^1.3.2",
    "material-ui": "^0.18.7",
    "morgan": "^1.7.0",
    "node-sass": "^4.5.3",
    "numbro": "^1.9.3",
    "odometer": "^0.4.7",
    "pre-commit": "^1.2.2",
    "prop-types": "^15.5.10",
    "react": "^15.4.1",
    "react-addons-css-transition-group": "^15.4.1",
    "react-addons-test-utils": "^15.6.0",
    "react-collapsible": "^1.2.0",
    "react-css-themr": "^1.6.1",
    "react-dom": "^15.4.1",
    "react-redux": "^4.4.6",
    "react-tabs": "^1.1.0",
    "react-tap-event-plugin": "^2.0.1",
    "react-toolbox": "^1.3.2",
    "redux": "^3.6.0",
    "redux-act": "^1.1.0",
    "redux-loop": "^2.2.2",
    "scroll": "2.0.x",
    "scroll-doc": "0.1.x",
    "serve-favicon": "^2.3.2",
    "superagent": "^3.3.1"
  },
  "devDependencies": {
    "app-module-path": "^2.1.0",
    "autoprefixer": "^6.5.3",
    "babel-cli": "^6.18.0",
    "babel-loader": "^6.2.8",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-preset-react": "^6.16.0",
    "css-loader": "^0.26.1",
    "extract-text-webpack-plugin": "^1.0.1",
    "file-loader": "^0.9.0",
    "jasmine-core": "^2.5.2",
    "karma": "^1.3.0",
    "karma-babel-preprocessor": "^6.0.1",
    "karma-chrome-launcher": "^2.0.0",
    "karma-firefox-launcher": "^1.0.0",
    "karma-jasmine": "^1.1.0",
    "karma-phantomjs-launcher": "^1.0.2",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^1.8.0",
    "postcss-loader": "^1.2.0",
    "sass-loader": "^4.0.2",
    "style-loader": "^0.13.1",
    "url-loader": "^0.5.7",
    "webpack": "^1.13.3",
    "webpack-dev-server": "^1.16.2"
  }
}```
@wichopy

This comment has been minimized.

Copy link

commented Aug 23, 2017

My savior.

@lazarljubenovic

This comment has been minimized.

Copy link

commented Sep 7, 2017

How to run watch mode with this setup?

@briancodes

This comment has been minimized.

Copy link

commented Nov 29, 2017

Hi. Does this command transpile all the ES6 tests that are listed in the config using Babel ?

@doooby

This comment has been minimized.

Copy link

commented Feb 23, 2018

used the library's own startup script to call:
(content of custom runner bin/jasmine:)

#!/usr/bin/env bash
./node_modules/.bin/babel-node ./node_modules/.bin/jasmine $@ --config=spec/support/jasmine.json

now passing arguments works! bin/jasmine -h while path to config conveniently always defined

@Fadeoc

This comment has been minimized.

Copy link

commented May 17, 2018

Thank you.

@minhnhut1986

This comment has been minimized.

Copy link

commented Jun 6, 2018

Awesomeness! Many thanks!

@cladicovr

This comment has been minimized.

Copy link

commented Aug 10, 2018

Anyone else has this issue?
(function (exports, require, module, __filename, __dirname) { import Jasmine from 'jasmine'; ^^^^^^ SyntaxError: Unexpected token import

@oskee121

This comment has been minimized.

Copy link

commented Aug 15, 2018

Same as @cladicovr

@SerhiiBilyk

This comment has been minimized.

Copy link

commented Sep 18, 2018

Same as @cladicovr & @oskee121

@GhadeerHaddad90

This comment has been minimized.

Copy link

commented Dec 28, 2018

how to run the run.js file? and how to run protractor.conf.js file using babel ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.