$ npm install -g babel-cli
javascript5 롸 변환해주는 Preset.
$ npm install babel-preset-es2015 --save-dev
{
"presets": ["es2015"]
}
$ npm install -g mocha
$ npm install chai --save-dev
chai에 promies 기능 추가
$ npm install chai-as-promised --save-dev
const chai = require('chai');
const chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised); // chai에 promise 기능 추가.
const should = chai.should(); // chai를 should로 사용할 수 있게.
$ npm install gulp --global
$ npm install gulp --save-dev
$ npm install gulp-babel --save-dev
$ npm install gulp-spawn-mocha --save-dev
$ npm install gulp-sourcemaps --save-dev
$ npm install source-map-support --save-dev
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const babel = require('gulp-babel');
const mocha = require('gulp-spawn-mocha');
// babel 처리.
gulp.task('babel', () => {
return gulp.src('src/*.js')
// source map 초기화
.pipe(sourcemaps.init())
// babel compile
.pipe(babel({
// preset 'es2015' :: javascript5로
presets: ['es2015']
}))
// .js.map 생성.
.pipe(sourcemaps.write('./', {sourceRoot: '../src'}))
.pipe(gulp.dest('dist'));
});
// mocha 처리.
gulp.task('mocha', ['babel'], () => {
return gulp.src('test/*-test.js', {read: false})
.pipe(mocha({
// report 종류
R: 'nyan',
// $ mocha --require source-map-support/register
r: 'source-map-support/register'
}));
});
gulp.task('watch', () => {
gulp.watch('{src,test}/*.js', ['mocha']);
});
gulp.task('default', ['mocha', 'watch']);