Skip to content

Instantly share code, notes, and snippets.

@mauvm
Created November 12, 2015 10:51
Show Gist options
  • Star 79 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save mauvm/172878a9646095d03fd7 to your computer and use it in GitHub Desktop.
Save mauvm/172878a9646095d03fd7 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

👍

@egeexyz
Copy link

egeexyz commented Mar 17, 2016

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

@kevgathuku
Copy link

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

@delacruz-dev
Copy link

Kudos for you!

@fishermanswharff
Copy link

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

@happypoulp
Copy link

Thanks a lot!

@jhenaoz
Copy link

jhenaoz commented Jul 5, 2016

Thanks a lot, huge post!

@bildepunkt
Copy link

👍

@moshmage
Copy link

Any luck on getting coverage for this setup ?

@amypellegrini
Copy link

amypellegrini commented Oct 27, 2016

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

@vaidik
Copy link

vaidik commented Mar 13, 2017

Awesomeness!

@nosdoska
Copy link

Works perfectly, thanks!

@lrettig
Copy link

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
Copy link

smasala commented May 5, 2017

Great solution!

@birhanuh
Copy link

Working solution! Thanks!

@erichulburd
Copy link

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
Copy link

wichopy commented Aug 23, 2017

My savior.

@lazarljubenovic
Copy link

How to run watch mode with this setup?

@briancodes
Copy link

briancodes commented Nov 29, 2017

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

@doooby
Copy link

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
Copy link

Fadeoc commented May 17, 2018

Thank you.

@minhnhut1986
Copy link

Awesomeness! Many thanks!

Copy link

ghost commented Aug 10, 2018

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

@oskee121
Copy link

Same as @cladicovr

@captain-yossarian
Copy link

Same as @cladicovr & @oskee121

@GhadeerHaddad
Copy link

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

@MarkMYoung
Copy link

This helped me today. Thank you!

@SerkanSipahi
Copy link

@memememomo
Copy link

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

It may be a problem with Node.js version. I wrote the following and it was resolved.

// import Jasmine from 'jasmine';
const Jasmine = require('jasmine');

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