mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
✅ tests for typescript transpiling
This commit is contained in:
1
spec/fixtures/typescript/invalid.ts
vendored
Normal file
1
spec/fixtures/typescript/invalid.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var foo = 123 123; // Syntax error
|
||||
2
spec/fixtures/typescript/valid.ts
vendored
Normal file
2
spec/fixtures/typescript/valid.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var inc = v => v + 1
|
||||
export = inc
|
||||
36
spec/typescript-spec.coffee
Normal file
36
spec/typescript-spec.coffee
Normal file
@@ -0,0 +1,36 @@
|
||||
typescript = require '../src/typescript'
|
||||
crypto = require 'crypto'
|
||||
|
||||
describe "TypeScript transpiler support", ->
|
||||
beforeEach ->
|
||||
jasmine.snapshotDeprecations()
|
||||
|
||||
afterEach ->
|
||||
jasmine.restoreDeprecationsSnapshot()
|
||||
|
||||
describe "::createTypeScriptVersionAndOptionsDigest", ->
|
||||
it "returns a digest for the library version and specified options", ->
|
||||
defaultOptions =
|
||||
target: 1 # ES5
|
||||
module: 'commonjs'
|
||||
sourceMap: true
|
||||
version = '1.4.1'
|
||||
shasum = crypto.createHash('sha1')
|
||||
shasum.update('typescript', 'utf8')
|
||||
shasum.update('\0', 'utf8')
|
||||
shasum.update(version, 'utf8')
|
||||
shasum.update('\0', 'utf8')
|
||||
shasum.update('{"target": 1,"module": "commonjs","sourceMap": true,}')
|
||||
expectedDigest = shasum.digest('hex')
|
||||
|
||||
observedDigest = typescript.createTypeScriptVersionAndOptionsDigest(version, defaultOptions)
|
||||
expect(observedDigest).toEqual expectedDigest
|
||||
|
||||
describe "when there is a .ts file", ->
|
||||
it "transpiles it using typescript", ->
|
||||
transpiled = require('./fixtures/typescript/valid.ts')
|
||||
expect(transpiled(3)).toBe 4
|
||||
|
||||
describe "when the .ts file is invalid", ->
|
||||
it "does not transpile", ->
|
||||
expect(-> require('./fixtures/typescript/invalid.ts')).toThrow()
|
||||
@@ -14,7 +14,7 @@ stats =
|
||||
misses: 0
|
||||
|
||||
defaultOptions =
|
||||
target: 1
|
||||
target: 1 # ES5
|
||||
module: 'commonjs'
|
||||
sourceMap: true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user