Skip to content

Commit d70c48a

Browse files
committed
add tests for getTypesriptConfig
1 parent 02647fc commit d70c48a

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@types/jest": "^19.2.4",
3030
"@types/lodash": "^4.14.62",
3131
"jest": "^20.0.4",
32+
"mock-fs": "^4.3.0",
3233
"ts-jest": "^20.0.6",
3334
"tslint": "^5.1.0"
3435
},

src/typescript.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ import * as _ from 'lodash'
44
import { ServerlessFunction } from './types'
55
import * as path from 'path'
66

7+
export function makeDefaultTypescriptConfig() {
8+
const defaultTypescriptConfig: ts.CompilerOptions = {
9+
preserveConstEnums: true,
10+
strictNullChecks: true,
11+
sourceMap: true,
12+
target: ts.ScriptTarget.ES5,
13+
moduleResolution: ts.ModuleResolutionKind.NodeJs,
14+
lib: ['lib.es2015.d.ts'],
15+
rootDir: './',
16+
}
17+
18+
return defaultTypescriptConfig
19+
}
20+
721
export function extractFileNames(functions: { [key: string]: ServerlessFunction }): string[] {
822
return _.values(functions)
923
.map(fn => fn.handler)
@@ -59,15 +73,5 @@ export function getTypescriptConfig(cwd: string): ts.CompilerOptions {
5973
return configParseResult.options
6074
}
6175

62-
const defaultTypescriptConfig: ts.CompilerOptions = {
63-
preserveConstEnums: true,
64-
strictNullChecks: true,
65-
sourceMap: true,
66-
target: ts.ScriptTarget.ES5,
67-
moduleResolution: ts.ModuleResolutionKind.NodeJs,
68-
lib: ['lib.es2015.d.ts'],
69-
rootDir: './',
70-
}
71-
72-
return defaultTypescriptConfig
76+
return makeDefaultTypescriptConfig()
7377
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {getTypescriptConfig, makeDefaultTypescriptConfig} from '../src/typescript'
2+
3+
describe('getTypescriptConfig', () => {
4+
it(`returns default typescript configuration if the one provided doesn't exist`, () => {
5+
expect(
6+
getTypescriptConfig('/ciaone/my-folder'),
7+
).toEqual(
8+
makeDefaultTypescriptConfig()
9+
)
10+
})
11+
})

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,10 @@ mkdirp@^0.5.1:
15491549
dependencies:
15501550
minimist "0.0.8"
15511551

1552+
mock-fs@^4.3.0:
1553+
version "4.3.0"
1554+
resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-4.3.0.tgz#c2fab8d784283287e9b6ae7538f2dc56c1a05ed7"
1555+
15521556
ms@2.0.0:
15531557
version "2.0.0"
15541558
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"

0 commit comments

Comments
 (0)