Skip to content

Commit

Permalink
add tests for getTypesriptConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
kandros committed Jun 10, 2017
1 parent 02647fc commit d70c48a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@types/jest": "^19.2.4",
"@types/lodash": "^4.14.62",
"jest": "^20.0.4",
"mock-fs": "^4.3.0",
"ts-jest": "^20.0.6",
"tslint": "^5.1.0"
},
Expand Down
26 changes: 15 additions & 11 deletions src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ import * as _ from 'lodash'
import { ServerlessFunction } from './types'
import * as path from 'path'

export function makeDefaultTypescriptConfig() {
const defaultTypescriptConfig: ts.CompilerOptions = {
preserveConstEnums: true,
strictNullChecks: true,
sourceMap: true,
target: ts.ScriptTarget.ES5,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
lib: ['lib.es2015.d.ts'],
rootDir: './',
}

return defaultTypescriptConfig
}

export function extractFileNames(functions: { [key: string]: ServerlessFunction }): string[] {
return _.values(functions)
.map(fn => fn.handler)
Expand Down Expand Up @@ -59,15 +73,5 @@ export function getTypescriptConfig(cwd: string): ts.CompilerOptions {
return configParseResult.options
}

const defaultTypescriptConfig: ts.CompilerOptions = {
preserveConstEnums: true,
strictNullChecks: true,
sourceMap: true,
target: ts.ScriptTarget.ES5,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
lib: ['lib.es2015.d.ts'],
rootDir: './',
}

return defaultTypescriptConfig
return makeDefaultTypescriptConfig()
}
11 changes: 11 additions & 0 deletions tests/typescript.getTypescriptConfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {getTypescriptConfig, makeDefaultTypescriptConfig} from '../src/typescript'

describe('getTypescriptConfig', () => {
it(`returns default typescript configuration if the one provided doesn't exist`, () => {
expect(
getTypescriptConfig('/ciaone/my-folder'),
).toEqual(
makeDefaultTypescriptConfig()
)
})
})
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,10 @@ mkdirp@^0.5.1:
dependencies:
minimist "0.0.8"

mock-fs@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-4.3.0.tgz#c2fab8d784283287e9b6ae7538f2dc56c1a05ed7"

ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
Expand Down

0 comments on commit d70c48a

Please sign in to comment.