1- const builder = require ( '../../lib/index' )
1+ const Mocha = require ( 'mocha' ) ;
2+ const { exec } = require ( 'child_process' ) ;
3+ const path = require ( 'path' ) ;
4+ const webpack = require ( 'webpack' ) ;
5+ const glob = require ( 'glob-all' ) ;
6+ const rimraf = require ( 'rimraf' ) ;
27
3- builder ( 'build' )
8+ const startTest = function ( ) {
9+ const mocha = new Mocha ( {
10+ timeout : '10000ms' ,
11+ } ) ;
12+
13+ process . chdir ( __dirname ) ; // 切换到当前template-project,否则找不到feflow.json
14+ const builder = require ( '../../lib/index' ) ;
15+ let prodConfig = builder . prodConfig ;
16+ // 修改loader的解析路径,因为没有在travis-ci全局安装feflow,所以需要加入本地路径
17+ prodConfig . resolveLoader . modules = [
18+ 'node_modules' ,
19+ path . resolve ( __dirname , '../../node_modules' ) ,
20+ ] ;
21+
22+ // 清除public目录
23+ rimraf ( './public' , ( ) => {
24+ webpack ( prodConfig , ( err , stats ) => {
25+ if ( err ) {
26+ console . error ( 'webpack配置错误' ) ;
27+ console . error ( err . stack || err ) ;
28+ if ( err . details ) {
29+ console . error ( err . details ) ;
30+ }
31+ return ;
32+ }
33+ console . log ( stats . toString ( 'errors-only' ) ) ;
34+ console . log ( 'webpack compilation completed' )
35+ glob ( './test.js' , ( err , matches ) => {
36+ testFile = matches [ 0 ] ;
37+ mocha . addFile ( testFile ) ;
38+ mocha . run ( ) ;
39+ } ) ;
40+ } ) ;
41+ } ) ;
42+ } ;
43+
44+ startTest ( ) ;
45+
46+ // exec("npm install -D", (error, stdout, stderr) => {
47+ // if (error) {
48+ // console.error(`exec error: ${error}`);
49+ // return;
50+ // }
51+ // console.log(`模板项目依赖安装情况: ${stdout}`);
52+ // console.log(`模板项目依赖安装提示: ${stderr}`);
53+
54+ // });
0 commit comments