Create a gist now

Instantly share code, notes, and snippets.

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.

Show comment Hide comment
@krawaller

krawaller 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! :)

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.

Show comment Hide comment
@wiredearp

wiredearp Feb 27, 2016

👍

👍

@egee-irl

This comment has been minimized.

Show comment Hide comment
@egee-irl

egee-irl Mar 17, 2016

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

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

@kevgathuku

This comment has been minimized.

Show comment Hide comment
@kevgathuku

kevgathuku Apr 30, 2016

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

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

@danderu

This comment has been minimized.

Show comment Hide comment
@danderu

danderu May 13, 2016

Kudos for you!

danderu commented May 13, 2016

Kudos for you!

@fishermanswharff

This comment has been minimized.

Show comment Hide comment
@fishermanswharff

fishermanswharff May 27, 2016

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

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

@happypoulp

This comment has been minimized.

Show comment Hide comment
@happypoulp

happypoulp Jun 1, 2016

Thanks a lot!

Thanks a lot!

@jhenaoz

This comment has been minimized.

Show comment Hide comment
@jhenaoz

jhenaoz Jul 5, 2016

Thanks a lot, huge post!

jhenaoz commented Jul 5, 2016

Thanks a lot, huge post!

@bildepunkt

This comment has been minimized.

Show comment Hide comment
@bildepunkt

bildepunkt Sep 30, 2016

👍

👍

@moshmage

This comment has been minimized.

Show comment Hide comment
@moshmage

moshmage Oct 16, 2016

Any luck on getting coverage for this setup ?

Any luck on getting coverage for this setup ?

@amypellegrini

This comment has been minimized.

Show comment Hide comment
@amypellegrini

amypellegrini Oct 27, 2016

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

amypellegrini commented Oct 27, 2016

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

@vaidik

This comment has been minimized.

Show comment Hide comment
@vaidik

vaidik Mar 13, 2017

Awesomeness!

vaidik commented Mar 13, 2017

Awesomeness!

@dazjavier

This comment has been minimized.

Show comment Hide comment
@dazjavier

dazjavier Apr 26, 2017

Works perfectly, thanks!

Works perfectly, thanks!

@lrettig

This comment has been minimized.

Show comment Hide comment
@lrettig

lrettig 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?

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

Show comment Hide comment
@smasala

smasala May 5, 2017

Great solution!

smasala commented May 5, 2017

Great solution!

@birhanuh

This comment has been minimized.

Show comment Hide comment
@birhanuh

birhanuh Jun 26, 2017

Working solution! Thanks!

Working solution! Thanks!

@erichulburd

This comment has been minimized.

Show comment Hide comment
@erichulburd

erichulburd 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"
  }
}```

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.

Show comment Hide comment
@wichopy

wichopy Aug 23, 2017

My savior.

wichopy commented Aug 23, 2017

My savior.

@lazarljubenovic

This comment has been minimized.

Show comment Hide comment
@lazarljubenovic

lazarljubenovic Sep 7, 2017

How to run watch mode with this setup?

How to run watch mode with this setup?

@briancodes

This comment has been minimized.

Show comment Hide comment
@briancodes

briancodes Nov 29, 2017

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

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

Show comment Hide comment
@doooby

doooby 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

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

Show comment Hide comment
@Fadeoc

Fadeoc May 17, 2018

Thank you.

Fadeoc commented May 17, 2018

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment