diff --git a/.travis.yml b/.travis.yml index e71d76b16..6f2793d32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,5 +17,6 @@ script: - "npm run-script ci-test" - "for resolver in ./resolvers/*; do cd $resolver && npm test && cd ../..; done" -after_success: - - npm run coveralls +# something broke remap-istanbul :-( +# after_success: +# - npm run coveralls diff --git a/appveyor.yml b/appveyor.yml index b1dd612fb..a2859cf6d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,10 +38,8 @@ test_script: - npm --version # Lint - ./node_modules/.bin/eslint ./src - # Compile - - npm run-script pretest # core tests - - ./node_modules/.bin/mocha tests/lib/ --recursive --reporter dot + - ./node_modules/.bin/gulp test # resolver tests - cd .\resolvers\webpack && npm test && cd ..\.. - cd .\resolvers\node && npm test && cd ..\.. diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 000000000..8b4299b01 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,88 @@ +var gulp = require('gulp') + , changed = require('gulp-changed') + , babel = require('gulp-babel') + , mocha = require('gulp-mocha') + , path = require('path') + , glob = require('glob') + , fs = require('fs') + +var SRC = 'src/**/*.js' + , DEST = 'lib' + +gulp.task('src', function () { + return gulp.src(SRC) + .pipe(changed(DEST)) + .pipe(babel()) + .pipe(gulp.dest(DEST)) +}) + +/** + * Delete any file under `dest` that has no corresponding file in `src`. + * I.E. remove generated files that have been orphaned via deletion of their source. + * @param {string} src + * @param {string} dest + * @param {Function} done - callback upon completion + */ +function wipeExtras(src, dest, done) { + // glob into 'lib' and delete whatever isn't there + glob(dest + '/**/*.js', function (err, files) { + if (err) { + done(err); return + } + + function checkFile(index) { + if (index >= files.length) { + done(); return + } + + var libFilename = files[index] + , srcFilename = path.resolve(src, path.relative(path.resolve(dest), libFilename)) + + fs.stat(srcFilename, function (err) { + if (err) { + fs.unlink(libFilename, function () { + checkFile(index + 1) + }) + } else { + checkFile(index + 1) + } + }) + } + + + checkFile(0) + }) +} + +gulp.task('wipe-extras', function (done) { + var unfinished = 2 + function megadone(err) { + if (err) { done(err); return } + if (--unfinished === 0) done() + } + wipeExtras('src', DEST, megadone) + wipeExtras('tests/src', 'tests/lib', megadone) +}) + +gulp.task('prepublish', ['src', 'wipe-extras']) + +gulp.task('tests', function () { + return gulp.src('tests/src/**/*.js') + .pipe(changed('tests/lib')) + .pipe(babel()) + .pipe(gulp.dest('tests/lib')) +}) + +// used externally by Istanbul, too +gulp.task('pretest', ['src', 'tests', 'wipe-extras']) + +gulp.task('test', ['pretest'], function () { + return gulp.src('tests/lib/**/*.js', { read: false }) + .pipe(mocha({ reporter: 'dot' })) + // NODE_PATH=./lib mocha --recursive --reporter dot tests/lib/ +}) + +gulp.task('watch-test', function () { + gulp.watch(SRC, ['test']) + gulp.watch('tests/' + SRC, ['test']) +}) diff --git a/package.json b/package.json index 63fbef759..374167cbf 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,12 @@ "test": "tests" }, "scripts": { - "watch": "babel -d lib/ src/ --watch & mocha --recursive --reporter dot --compilers js:babel/register --watch tests/src/", - "cover": "npm run pretest && NODE_PATH=./lib istanbul cover --dir reports/coverage _mocha tests/lib/ -- --recursive --reporter dot; remap-istanbul -i reports/coverage/coverage.json -o reports/coverage/lcov-report --type html", - "test": "NODE_PATH=./lib mocha --recursive --reporter dot tests/lib/", - "ci-test": "eslint ./src && npm run-script pretest && istanbul cover --report lcovonly --dir reports/coverage _mocha tests/lib/ -- --recursive --reporter dot", + "watch": "NODE_PATH=./lib gulp watch-test", + "cover": "gulp pretest && NODE_PATH=./lib istanbul cover --dir reports/coverage _mocha tests/lib/ -- --recursive -R progress", + "test": "NODE_PATH=./lib gulp test", + "ci-test": "eslint ./src && gulp pretest && istanbul cover --report lcovonly --dir reports/coverage _mocha tests/lib/ -- --recursive --reporter dot", "debug": "NODE_PATH=./lib mocha debug --recursive --reporter dot tests/lib/", - "compile": "rm -rf lib/ && babel -d lib/ src/", - "prepublish": "eslint ./src && npm run compile", - "pretest": "npm run compile && babel -d tests/lib/ tests/src/", + "prepublish": "eslint ./src && gulp prepublish", "coveralls": "remap-istanbul -i reports/coverage/coverage.json -o reports/coverage/lcov.info --type lcovonly && cat ./reports/coverage/lcov.info | coveralls" }, "repository": { @@ -44,6 +42,11 @@ "eslint": ">=1.8.0", "eslint-import-resolver-node": "file:./resolvers/node", "eslint-import-resolver-webpack": "file:./resolvers/webpack", + "glob": "^6.0.2", + "gulp": "^3.9.0", + "gulp-babel": "5.x", + "gulp-changed": "^1.3.0", + "gulp-mocha": "^2.2.0", "istanbul": "^0.4.0", "mocha": "^2.2.1", "redux": "^3.0.4",