File tree Expand file tree Collapse file tree 7 files changed +83
-15
lines changed Expand file tree Collapse file tree 7 files changed +83
-15
lines changed Original file line number Diff line number Diff line change 1+ var fs = require ( 'fs' ) ;
12var path = require ( 'path' ) ;
23
4+ var ts = require ( 'typescript' ) ;
5+
36var pattern = 'test/**/*.ts' ;
47var packageData = require ( path . join ( process . cwd ( ) , 'package.json' ) ) ;
58
@@ -10,7 +13,34 @@ if (packageData &&
1013 pattern = testDir + ( ( testDir . lastIndexOf ( '/' , 0 ) === 0 ) ? '' : '/' ) + '**/*.ts' ;
1114}
1215
16+ var compilerOptions = findAndParseTsConfig ( process . cwd ( ) ) ;
17+
1318require ( './index' ) ( {
1419 cwd : process . cwd ( ) ,
15- pattern : pattern
20+ pattern : pattern ,
21+ compilerOptions : compilerOptions
1622} ) ;
23+
24+ function findAndParseTsConfig ( cwd ) {
25+ var tsconfigPath = ts . findConfigFile ( process . cwd ( ) ) ;
26+ if ( ! tsconfigPath ) {
27+ return null ;
28+ }
29+
30+ var compilerOptions = null ;
31+ var parsed = ts . parseConfigFileTextToJson ( tsconfigPath , fs . readFileSync ( tsconfigPath , 'utf8' ) ) ;
32+ if ( parsed . error ) {
33+ throw new Error ( parsed . error . messageText ) ;
34+ }
35+
36+ if ( ! parsed . config || ! parsed . config . compilerOptions ) {
37+ return null ;
38+ }
39+
40+ var converted = ts . convertCompilerOptionsFromJson ( parsed . config . compilerOptions , process . cwd ( ) ) ;
41+ if ( converted . errors && converted . errors . length > 0 ) {
42+ var msg = converted . errors . map ( function ( e ) { return e . messageText } ) . join ( ', ' ) ;
43+ throw new Error ( msg ) ;
44+ }
45+ return converted . options ;
46+ }
Original file line number Diff line number Diff line change @@ -9,10 +9,7 @@ var TypeScriptSimple = require('typescript-simple').TypeScriptSimple;
99function espowerTypeScript ( options ) {
1010 var separator = ( options . pattern . lastIndexOf ( '/' , 0 ) === 0 ) ? '' : '/' ;
1111 var pattern = options . cwd + separator + options . pattern ;
12- // TODO: load tsconfig.json
13- var tsconfig = options . tsconfig || { } ;
14- var compilerOptions = tsconfig . compilerOptions || { } ;
15- var tss = new TypeScriptSimple ( compilerOptions , false ) ;
12+ var tss = new TypeScriptSimple ( options . compilerOptions , false ) ;
1613
1714 require . extensions [ '.ts' ] = function ( localModule , filepath ) {
1815 var result = tss . compile ( fs . readFileSync ( filepath , 'utf-8' ) ) ;
Original file line number Diff line number Diff line change 2828 "dependencies" : {
2929 "espower-source" : " ^1.0.0" ,
3030 "minimatch" : " ^3.0.0" ,
31+ "typescript" : " 1.8.0-dev.20151106" ,
3132 "typescript-simple" : " ^3.0.2"
3233 }
3334}
Original file line number Diff line number Diff line change 1+ import hello from './lib/hello' ;
2+
3+ let assert = require ( 'power-assert' ) ;
4+
5+ class Person {
6+ constructor ( public name : string , public age : number ) {
7+ }
8+ getAge ( ) : string {
9+ return this . age ;
10+ }
11+ }
12+
13+ describe ( 'Person' , ( ) => {
14+ let alice = new Person ( 'alice' , 3 ) ;
15+ let bob = new Person ( 'bob' , 5 ) ;
16+ it ( '#getAge' , ( ) => {
17+ assert ( alice . getAge ( ) === 3 )
18+ } )
19+ it ( '#name' , ( ) => {
20+ assert ( alice . name === 'alice' )
21+ } )
22+ // failed
23+ it ( '#mistake' , ( ) => {
24+ assert ( alice . name === bob . name )
25+ } )
26+ // failed
27+ it ( 'hello' , ( ) => {
28+ assert ( hello ( ) === 'whoa!' ) ;
29+ } ) ;
30+ } )
Original file line number Diff line number Diff line change 1- import hello from './lib/hello' ;
1+ // Run with Node.js v5+
2+
3+ 'use strict' ;
24
35let assert = require ( 'power-assert' ) ;
46
@@ -14,17 +16,17 @@ describe('Person', () => {
1416 let alice = new Person ( 'alice' , 3 ) ;
1517 let bob = new Person ( 'bob' , 5 ) ;
1618 it ( '#getAge' , ( ) => {
17- assert ( alice . getAge ( ) === 3 )
18- } )
19+ assert ( alice . getAge ( ) === 3 ) ;
20+ } ) ;
1921 it ( '#name' , ( ) => {
20- assert ( alice . name === 'alice' )
21- } )
22+ assert ( alice . name === 'alice' ) ;
23+ } ) ;
2224 // failed
2325 it ( '#mistake' , ( ) => {
24- assert ( alice . name === bob . name )
25- } )
26+ assert ( alice . name === bob . name ) ;
27+ } ) ;
2628 // failed
27- it ( 'hello ' , ( ) => {
28- assert ( hello ( ) === 'whoa!' ) ;
29+ it ( 'arrow function ' , ( ) => {
30+ assert ( alice . name === ( ( ) => 1 ) ) ;
2931 } ) ;
30- } )
32+ } ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
13let assert = require ( 'power-assert' )
24let expect = require ( 'expect.js' )
35
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "target" : " ES5" ,
4+ "noImplicitAny" : true
5+ }
6+ }
You can’t perform that action at this time.
0 commit comments