2016-12-14 11 views
1

我需要構建一個開發環境,它將自動編譯,運行測試,然後在./src/./test/中的.ts文件發生變化時運行TSLint,並打印出測試結果和皮棉。當任何文件發生變化時,使用TypeScript和Mocha自動運行測試

./src/*.ts --\ (tsc --watch)   (mocha --watch) 
       |---------------> ./lib/ ---------------> console.log 
./test/*.ts --/  | 
        | (tslint --watch) 
        |--------------------> console.log 

我已經寫了NPM腳本與npm run test只運行一次這個工作流程:

// package.json 
{ 
    "scripts": { 
    "pretest": "tsc", // will compile *.ts in src/ and test/ to lib/ 
    "test": "mocha --reporter spec --full-trace lib/test/tests.js", // run the compiled test file 
    "posttest": "gulp tslint" // run gulp for tslint 
    } 
} 

我寫了一大口的任務看文件更改觸發故宮腳本:

// gulpfile.js 
var exec = require('gulp-exec'); 
gulp.task("watch",() => { 
    gulp.watch(paths.scripts,() => { 
    exec(`npm run test`, { 
     continueOnError: true, 
     pipeStdout: true 
    }) 
    }); 
}); 

我跑gulp watch,但我並沒有顯示在控制檯測試和皮棉的結果。

如何實現我的目標,這將運行TS-編譯,摩卡測試,然後TS-皮棉當任何*.ts文件的變化?

+0

你有'scirpts'一個錯字,它應該是'scripts'。 – mixel

回答

0

這將直接摩卡更容易的測試,你將不得不在你的各種任務更精細的控制。

你可以有以下任務:

gulp.task('compileSrcForWatch', ['compileSrc'],() => gulp.start('test')); 
gulp.task('compileTestForWatch', ['compileTest'],() => gulp.start('test')); 

gulp.task('watchAndTest',() => { 
    gulp.watch(config.inputSourceFiles, ['compileSrcForWatch']); 
    gulp.watch(config.inputTestFiles, ['compileTestForWatch']); 
}); 

我已經創建了整個文件here一個要點。

相關問題