pulsar/spec/babel-spec.coffee

65 lines
2.4 KiB
CoffeeScript
Raw Normal View History

2015-02-18 04:23:58 +03:00
babel = require '../src/babel'
crypto = require 'crypto'
2015-02-25 20:37:42 +03:00
grim = require 'grim'
2015-02-18 04:23:58 +03:00
describe "Babel transpiler support", ->
2015-02-25 20:37:42 +03:00
beforeEach ->
jasmine.snapshotDeprecations()
afterEach ->
jasmine.restoreDeprecationsSnapshot()
2015-02-18 04:23:58 +03:00
describe "::createBabelVersionAndOptionsDigest", ->
2015-02-03 00:29:20 +03:00
it "returns a digest for the library version and specified options", ->
defaultOptions =
blacklist: [
'useStrict'
]
experimental: true
optional: [
'asyncToGenerator'
]
reactCompat: true
sourceMap: 'inline'
version = '3.0.14'
shasum = crypto.createHash('sha1')
2015-02-18 04:23:58 +03:00
shasum.update('babel-core', 'utf8')
2015-02-03 00:29:20 +03:00
shasum.update('\0', 'utf8')
shasum.update(version, 'utf8')
shasum.update('\0', 'utf8')
shasum.update('{"blacklist": ["useStrict",],"experimental": true,"optional": ["asyncToGenerator",],"reactCompat": true,"sourceMap": "inline",}')
expectedDigest = shasum.digest('hex')
2015-02-18 04:23:58 +03:00
observedDigest = babel.createBabelVersionAndOptionsDigest(version, defaultOptions)
2015-02-03 00:29:20 +03:00
expect(observedDigest).toEqual expectedDigest
2015-02-18 04:23:58 +03:00
describe "when a .js file starts with 'use babel';", ->
it "transpiles it using babel", ->
transpiled = require('./fixtures/babel/babel-single-quotes.js')
expect(transpiled(3)).toBe 4
2015-02-25 20:37:42 +03:00
expect(grim.getDeprecationsLength()).toBe 0
2015-02-18 04:23:58 +03:00
2015-02-03 00:29:20 +03:00
describe "when a .js file starts with 'use 6to5';", ->
2015-02-25 20:42:49 +03:00
it "transpiles it using babel and adds a pragma deprecation", ->
2015-02-25 20:37:42 +03:00
expect(grim.getDeprecationsLength()).toBe 0
2015-02-18 04:23:58 +03:00
transpiled = require('./fixtures/babel/6to5-single-quotes.js')
expect(transpiled(3)).toBe 4
2015-02-25 20:37:42 +03:00
expect(grim.getDeprecationsLength()).toBe 1
2015-02-18 04:23:58 +03:00
describe 'when a .js file starts with "use babel";', ->
it "transpiles it using babel", ->
transpiled = require('./fixtures/babel/babel-double-quotes.js')
2015-02-03 00:29:20 +03:00
expect(transpiled(3)).toBe 4
2015-02-25 20:37:42 +03:00
expect(grim.getDeprecationsLength()).toBe 0
2015-02-03 00:29:20 +03:00
describe 'when a .js file starts with "use 6to5";', ->
2015-02-25 20:42:49 +03:00
it "transpiles it using babel and adds a pragma deprecation", ->
2015-02-25 20:37:42 +03:00
expect(grim.getDeprecationsLength()).toBe 0
2015-02-18 04:23:58 +03:00
transpiled = require('./fixtures/babel/6to5-double-quotes.js')
2015-02-03 00:29:20 +03:00
expect(transpiled(3)).toBe 4
2015-02-25 20:37:42 +03:00
expect(grim.getDeprecationsLength()).toBe 1
2015-02-03 00:29:20 +03:00
describe "when a .js file does not start with 'use 6to6';", ->
2015-02-18 04:23:58 +03:00
it "does not transpile it using babel", ->
expect(-> require('./fixtures/babel/invalid.js')).toThrow()