From 6abefdc9c9ed2e6e35a2b03e24d5274d27edd4e7 Mon Sep 17 00:00:00 2001 From: Chema Balsas Date: Tue, 30 May 2017 17:22:53 +0200 Subject: [PATCH] Adds jest test:snapshot task --- lib/tasks/test.js | 30 +++++++++++++++++++++++++++++- package.json | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/tasks/test.js b/lib/tasks/test.js index 33aaa18..d286ba8 100644 --- a/lib/tasks/test.js +++ b/lib/tasks/test.js @@ -12,6 +12,9 @@ var mocha = require('gulp-mocha'); var normalizeOptions = require('../options'); var openFile = require('open'); var path = require('path'); +var through = require('through2'); +var jest = require('jest-cli'); + module.exports = function(options) { options = normalizeOptions(options); @@ -20,8 +23,24 @@ module.exports = function(options) { var runSequence = require('run-sequence').use(gulp); + var testSnapshot = function(file, encoding, cb) { + options = Object.assign({}, options, { + config: Object.assign({ + rootDir: file ? file.path : undefined + }, options.config) + }); + + jest.runCLI(options, [options.config.rootDir], (result) => { + if(result.numFailedTests || result.numFailedTestSuites) { + cb(new gutil.PluginError('gulp-jest', { message: 'Tests Failed' })); + } else { + cb(); + } + }); + }; + gulp.task(taskPrefix + 'test', function(done) { - runSequence(taskPrefix + 'test:unit', function() { + runSequence(/*[taskPrefix + 'test:unit', */taskPrefix + 'test:snapshot'/*]*/, function() { done(); }); }); @@ -38,6 +57,15 @@ module.exports = function(options) { }); }); + gulp.task(taskPrefix + 'test:snapshot', options.testDepTasks, function() { + var gulpOpts = { + base: process.cwd() + }; + + return gulp.src('src/__tests__/**/*.js', gulpOpts) + .pipe(through.obj(testSnapshot)); + }); + gulp.task(taskPrefix + 'test:coverage', options.testDepTasks, function(done) { var configFile = 'metal-karma-config/'; configFile += options.noSoy ? 'no-soy-coverage' : 'coverage'; diff --git a/package.json b/package.json index 9d28b90..c395010 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ }, "devDependencies": { "babel-deps": "^2.0.0", + "jest-cli": "^20.0.4", "metal": "^1.0.0-rc", "mocha": "^2.2.5", "mockery": "^1.4.0",