pulsar/spec/babel-spec.coffee

58 lines
2.1 KiB
CoffeeScript
Raw Normal View History

2016-01-13 02:42:44 +03:00
# Users may have this environment variable set. Currently, it causes babel to
# log to stderr, which causes errors on Windows.
# See https://github.com/atom/electron/issues/2033
process.env.DEBUG='*'
path = require 'path'
2016-01-16 01:22:08 +03:00
temp = require('temp').track()
CompileCache = require '../src/compile-cache'
2015-02-18 04:23:58 +03:00
describe "Babel transpiler support", ->
originalCacheDir = null
beforeEach ->
originalCacheDir = CompileCache.getCacheDirectory()
CompileCache.setCacheDirectory(temp.mkdirSync('compile-cache'))
for cacheKey in Object.keys(require.cache)
if cacheKey.startsWith(path.join(__dirname, 'fixtures', 'babel'))
delete require.cache[cacheKey]
afterEach ->
CompileCache.setCacheDirectory(originalCacheDir)
try
temp.cleanupSync()
describe 'when a .js file starts with /** @babel */;', ->
it "transpiles it using babel", ->
transpiled = require('./fixtures/babel/babel-comment.js')
expect(transpiled(3)).toBe 4
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
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
2016-02-06 00:16:38 +03:00
describe 'when a .js file starts with /* @flow */', ->
it "transpiles it using babel", ->
transpiled = require('./fixtures/babel/flow-comment.js')
expect(transpiled(3)).toBe 4
describe "when a .js file does not start with 'use babel';", ->
2015-02-18 04:23:58 +03:00
it "does not transpile it using babel", ->
2017-05-12 06:10:20 +03:00
spyOn(console, 'error')
2015-02-18 04:23:58 +03:00
expect(-> require('./fixtures/babel/invalid.js')).toThrow()
2016-01-13 02:42:44 +03:00
it "does not try to log to stdout or stderr while parsing the file", ->
spyOn(process.stderr, 'write')
spyOn(process.stdout, 'write')
transpiled = require('./fixtures/babel/babel-double-quotes.js')
expect(process.stdout.write).not.toHaveBeenCalled()
expect(process.stderr.write).not.toHaveBeenCalled()