Add more 6to5 specs

This commit is contained in:
Kevin Sawicki 2015-02-02 13:29:20 -08:00
parent c7b206f5ca
commit f9f7cf6d34
5 changed files with 48 additions and 27 deletions

View File

@ -1,26 +1,41 @@
{create6to5VersionAndOptionsDigest} = require '../src/6to5' to5 = require '../src/6to5'
crypto = require 'crypto' crypto = require 'crypto'
describe "::create6to5VersionAndOptionsDigest", -> describe "6to5 transpiler support", ->
it "returns a digest for the library version and specified options", -> describe "::create6to5VersionAndOptionsDigest", ->
defaultOptions = it "returns a digest for the library version and specified options", ->
blacklist: [ defaultOptions =
'useStrict' blacklist: [
] 'useStrict'
experimental: true ]
optional: [ experimental: true
'asyncToGenerator' optional: [
] 'asyncToGenerator'
reactCompat: true ]
sourceMap: 'inline' reactCompat: true
version = '3.0.14' sourceMap: 'inline'
shasum = crypto.createHash('sha1') version = '3.0.14'
shasum.update('6to5-core', 'utf8') shasum = crypto.createHash('sha1')
shasum.update('\0', 'utf8') shasum.update('6to5-core', 'utf8')
shasum.update(version, 'utf8') shasum.update('\0', 'utf8')
shasum.update('\0', 'utf8') shasum.update(version, 'utf8')
shasum.update('{"blacklist": ["useStrict",],"experimental": true,"optional": ["asyncToGenerator",],"reactCompat": true,"sourceMap": "inline",}') shasum.update('\0', 'utf8')
expectedDigest = shasum.digest('hex') shasum.update('{"blacklist": ["useStrict",],"experimental": true,"optional": ["asyncToGenerator",],"reactCompat": true,"sourceMap": "inline",}')
expectedDigest = shasum.digest('hex')
observedDigest = create6to5VersionAndOptionsDigest(version, defaultOptions) observedDigest = to5.create6to5VersionAndOptionsDigest(version, defaultOptions)
expect(observedDigest).toEqual expectedDigest expect(observedDigest).toEqual expectedDigest
describe "when a .js file starts with 'use 6to5';", ->
it "transpiles it using 6to5", ->
transpiled = require('./fixtures/6to5/single-quotes.js')
expect(transpiled(3)).toBe 4
describe 'when a .js file starts with "use 6to5";', ->
it "transpiles it using 6to5", ->
transpiled = require('./fixtures/6to5/double-quotes.js')
expect(transpiled(3)).toBe 4
describe "when a .js file does not start with 'use 6to6';", ->
it "does not transpile it using 6to5", ->
expect(-> require('./fixtures/6to5/invalid.js')).toThrow()

3
spec/fixtures/6to5/double-quotes.js vendored Normal file
View File

@ -0,0 +1,3 @@
"use 6to5";
module.exports = v => v + 1

3
spec/fixtures/6to5/invalid.js vendored Normal file
View File

@ -0,0 +1,3 @@
'use 6to6';
module.exports = v => v + 1

3
spec/fixtures/6to5/single-quotes.js vendored Normal file
View File

@ -0,0 +1,3 @@
'use 6to5';
module.exports = v => v + 1

View File

@ -90,10 +90,7 @@ create6to5VersionAndOptionsDigest = (version, options) ->
shasum.digest('hex') shasum.digest('hex')
cacheDir = path.join(fs.absolute('~/.atom'), 'compile-cache') cacheDir = path.join(fs.absolute('~/.atom'), 'compile-cache')
jsCacheDir = path.join( jsCacheDir = path.join(cacheDir, create6to5VersionAndOptionsDigest(to5.version, defaultOptions), 'js')
cacheDir,
create6to5VersionAndOptionsDigest(to5.version, defaultOptions),
'js')
getCachePath = (sourceCode) -> getCachePath = (sourceCode) ->
digest = crypto.createHash('sha1').update(sourceCode, 'utf8').digest('hex') digest = crypto.createHash('sha1').update(sourceCode, 'utf8').digest('hex')