Skip to content

Commit

Permalink
fix: not throw when tsconfig not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Nov 19, 2019
1 parent cd0819a commit 9ec8a18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/models/san-project.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { sep, resolve } from 'path'
import { getDefaultTSConfigPath } from '../parsers/tsconfig'
import { cwd } from 'process'
import { Compiler } from '../models/compiler'
import { SanAppParser } from '../parsers/san-app-parser'
import { Project } from 'ts-morph'
Expand All @@ -8,7 +9,6 @@ import { loadCompilerClassByTarget } from '../loaders/target'

export type SanProjectOptions = {
tsConfigFilePath?: string,
root?: string,
modules?: Modules
}

Expand All @@ -28,10 +28,11 @@ export class SanProject {

constructor ({
tsConfigFilePath = getDefaultTSConfigPath(),
modules = {},
root = tsConfigFilePath.split(sep).slice(0, -1).join(sep)
modules = {}
}: SanProjectOptions = {}) {
this.root = root
this.root = tsConfigFilePath
? tsConfigFilePath.split(sep).slice(0, -1).join(sep)
: cwd()
this.tsConfigFilePath = tsConfigFilePath
this.tsProject = new Project({ tsConfigFilePath })
this.modules = modules
Expand Down
13 changes: 13 additions & 0 deletions test/unit/models/san-project.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SanProject } from '../../../src/models/san-project'

describe('SanProject', function () {
it('should not throw if called with no options', function () {
expect(() => new SanProject()).not.toThrow()
})

it('should not throw if tsConfigFilePath not found', function () {
expect(() => new SanProject({
tsConfigFilePath: null // simulate the case when no tsconfig found
})).not.toThrow()
})
})

0 comments on commit 9ec8a18

Please sign in to comment.