gulp watch resulting in an endless loop after upgrading to gulp 4 - gulp-watch

I have upgraded my gulpfile.js to gulp 4. gulp dev is working fine. But whenever I am editing any file the reload and inject tasks are entering into an endless loop.
My gulpfile.js:
var gulp = require('gulp'),
sass = require('gulp-sass'),
symlink = require('gulp-symlink'),
jshint = require('gulp-jshint'),
browserSync = require('browser-sync').create(),
concat = require('gulp-concat'),
useref = require('gulp-useref'),
replace = require('gulp-replace'),
templateCache = require('gulp-angular-templatecache'),
gulpif = require('gulp-if'),
gulpUtil = require('gulp-util'),
uglify = require('gulp-uglify'),
minifyCss = require('gulp-clean-css'),
merge = require('merge-stream'),
clean = require('gulp-clean'),
inject = require('gulp-inject'),
svgSprite = require('gulp-svg-sprite'),
postcss = require('gulp-postcss'),
autoprefixer = require('autoprefixer');
webfonts = require('gulp-font');
/* DEV */
gulp.task('dev-serve', function () {
browserSync.init({
server: './'
});
gulp.watch('app/**/*.scss', gulp.parallel('sass'));
gulp.watch('app/**/*.html', gulp.series('inject', 'reload'));
gulp.watch('app/**/*.js', gulp.parallel('inject', 'reload'));
gulp.watch('app/images/svg-sprite/*', gulp.parallel('svg-sprite', 'reload'));
gulp.watch('app/images/**/*', gulp.parallel('reload'));
gulp.watch('app/fonts/*', gulp.parallel('reload'));
});
/* PROD */
gulp.task('prod-serve', function () {
browserSync.init({
server: './www'
});
gulp.watch('app/**/*.scss', gulp.parallel('sass', 'build-html'));
gulp.watch('app/**/*.html', gulp.parallel('inject', 'minify-scripts', 'reload'));
gulp.watch('app/**/*.js', gulp.parallel('inject', 'minify-scripts', 'reload'));
gulp.watch('app/images/**/*', gulp.parallel('copy-images', 'reload'));
gulp.watch('app/fonts/*', gulp.parallel('copy-fonts', 'reload'));
});
// SVG SPRITE
gulp.task('svg-sprite', function () {
var svgPath = 'app/images/svg-sprite/*.svg';
return gulp.src(svgPath)
.pipe(svgSprite({
shape: {
spacing: {
padding: 0
}
},
mode: {
css: {
dest: './',
layout: 'diagonal',
sprite: 'app/images/sprite.svg',
bust: false,
render: {
scss: {
dest: 'app/styles/tools/_sprite.scss',
template: 'app/styles/tools/_sprite-template.tpl'
}
}
}
},
variables: {
mapname: 'icons'
}
}))
.pipe(gulp.dest('./'));
});
// SCSS
gulp.task('sass', function (done) {
gulp.task('sass', function () {
return gulp.src('app/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(concat('style.css'))
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest('app'))
.pipe(browserSync.stream());
});
done();
});
// INJECT
gulp.task('inject', function () {
return gulp.src('app/index.html')
.pipe(inject(gulp.src(['app/**/*.module.js', 'app/**/*.js', '!app/vendor/**/*.js'], {read: false}), {relative: true}))
.pipe(gulp.dest('./app'));
});
// HTML
gulp.task('build-html', function () {
return gulp.src('app/index.html')
.pipe(replace('href="/app/"', 'href="/"')) // replace base href
.pipe(useref())
.pipe(gulpif('*.js', uglify().on('error', gulpUtil.log)))
.pipe(gulpif('*.css', minifyCss()))
.pipe(gulp.dest('www'));
});
// IMAGES
gulp.task('copy-images', function () {
return gulp.src(['app/images/*'])
.pipe(gulp.dest('www/images'));
});
// FONTS
gulp.task('copy-fonts', function () {
return gulp.src(['app/fonts/*'])
.pipe(gulp.dest('www/fonts'));
});
// TEMPLATES
gulp.task('bundle-templates', function () {
return gulp.src(['app/**/*.html', '!app/index.html'])
.pipe(gulpif('*.html', templateCache({module: 'jibbar'})))
.pipe(concat('templates.min.js'))
.pipe(gulp.dest('www/tmp'));
});
// COMPONENTS
gulp.task('bundle-components', function () {
return gulp.src(['app/**/*.module.js', 'app/**/*.js', '!app/vendor/**/*.js'])
.pipe(concat('script.min.js'))
.pipe(gulp.dest('www'));
});
// MERGE TEMPLATES AND COMPONENTS
gulp.task('merge-templates-and-components', gulp.parallel('bundle-templates', 'bundle-components'), function () {
return gulp.src(['www/script.min.js', 'www/tmp/templates.min.js'])
.pipe(concat('script.min.js'))
.pipe(gulp.dest('www'))
});
// MINIFY SCRIPTS
gulp.task('minify-scripts', gulp.parallel('merge-templates-and-components', 'bundle-templates', 'bundle-components'), function () {
return gulp.src('www/script.min.js')
.pipe(uglify().on('error', gulpUtil.log))
.pipe(gulp.dest('www'))
});
// CLEAN TEMP
gulp.task('clean', gulp.parallel('bundle-templates', 'bundle-components', 'merge-templates-and-components'), function () {
return gulp.src('www/tmp', {read: false})
.pipe(clean());
});
// RELOAD BROWSER
gulp.task('reload', gulp.series('inject'), function () {
browserSync.reload();
});
//COPY IFRAME
gulp.task('copy-iframe', function () {
return gulp.src('app/components/builder/iframe/*')
.pipe(gulp.dest('www/app/components/builder/iframe'));
});
//COPY TINYMCE
gulp.task('copy-tinymce', function () {
return gulp.src('app/vendor/tinymce/**/*')
.pipe(gulp.dest('www/app/vendor/tinymce'));
});
//COPY VENDOR FILES
gulp.task('copy-vendor-files', function () {
return gulp.src(['app/vendor/angular.js','app/vendor/bootstrap.css','app/vendor/tooltip.css','app/vendor/jquery.js'])
.pipe(gulp.dest('www/app/vendor'));
});
//COPY APP IMAGES
gulp.task('copy-app-images', function () {
return gulp.src(['app/images/builder-image.svg','app/images/builder-dimensions.svg','app/images/info_icon.svg'])
.pipe(gulp.dest('www/app/images'));
});
gulp.task('dev', gulp.series(
'inject',
'svg-sprite',
'sass',
'dev-serve'
));
gulp.task('prod', gulp.series(
'inject',
'sass',
'copy-iframe',
'copy-tinymce',
'copy-vendor-files',
'copy-app-images',
'build-html',
'copy-images',
'copy-fonts',
'minify-scripts',
'clean',
'prod-serve'
));
The following image shows the endless loop
Can anyone please help me to find out what I am doing wrong here.
Thanks in advance.

In addition to my comment above, this is probably a problem:
// RELOAD BROWSER
gulp.task('reload', gulp.series('inject'), function () {
browserSync.reload();
});
In your watch statements you call inject and reload, and then in the reload task you call inject first which updates your html files (timestamp if nothing else) and so the html watch is retiggered which calls inject and reload again, etc.
Just use:
// RELOAD BROWSER
gulp.task('reload', function () {
browserSync.reload();
});
and change all your watch's to gulp.series. Since you call reload last there is no need to call inject within the reload task again.
/* PROD */
gulp.task('prod-serve', function () {
browserSync.init({
server: './www'
});
gulp.watch('app/**/*.scss', gulp.series('sass', 'build-html'));
gulp.watch('app/**/*.html', gulp.series('inject', 'minify-scripts', 'reload'));
gulp.watch('app/**/*.js', gulp.series('inject', 'minify-scripts', 'reload'));
gulp.watch('app/images/**/*', gulp.series('copy-images', 'reload'));
gulp.watch('app/fonts/*', gulp.series('copy-fonts', 'reload'));
});
and do the same for your 'dev-serve' task.
[Edit to fix will only run once]
Change to:
// RELOAD BROWSER
gulp.task('reload', gulp.series('inject'), function (done) {
browserSync.reload();
done();
});
Also I'm pretty sure you need to use this form:
// RELOAD BROWSER
//--------------------------------------|
gulp.task('reload', gulp.series('inject', function (done) {
browserSync.reload();
done();
}));
// another ) at the end above too.
See how the last anonymous function is included in the gulp.series call. You need to make that change in quite a few of your tasks.

Related

React APP ReferenceError: require is not defined

Integrating GULP with my React Project. On firing up the project, the following is the error that I face: https://prnt.sc/trw1if
Do check the screenshot above. This is a particular issue that I face.
Do let me know what am I doing wrong here. I've tried different presets for it as well. I am also attaching my GULP file here:
var gulp = require('gulp');
var babel = require('gulp-babel');
var sass = require('gulp-sass');
const imagemin = require('gulp-imagemin');
var concat = require('gulp-concat');
var uglify = require("gulp-uglify");
var browserSync = require("browser-sync").create();
const rollup = require('gulp-better-rollup');
// const babel = require('rollup-plugin-babel');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
gulp.task('jsCompile', function () {
return gulp.src(['src/*.js', 'src/**/*.js', 'src/**/**/*.js'])
.pipe(babel({
presets: ['#babel/preset-react', '#babel/preset-env']
})
.on('error', function (err) {
console.log('[Compilation Error]');
console.log(err.fileName + (err.loc ? `( ${err.loc.line}, ${err.loc.column} ): ` : ': '));
console.log('error Babel: ' + err.message + '\n');
console.log(err.codeFrame);
this.emit('end');
}))
// .pipe(rollup({ plugins: [babel(), resolve(), commonjs()] }, 'umd'))
.pipe(uglify())
.pipe(concat('main.js'))
.pipe(gulp.dest('dist/js'))
.pipe(browserSync.stream())
});
gulp.task('htmlCompile', function () {
return gulp.src(['public/*.html'])
.pipe(gulp.dest('dist/'))
});
gulp.task('sassCompile', function () {
return gulp.src(['src/*.scss', 'src/*.css'])
.pipe(concat('main.css'))
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('dist/css'))
});
gulp.task('imageCompile', function () {
return gulp.src(['src/assets/images/*.jpg', 'src/assets/images/*.png'])
.pipe(imagemin())
.pipe(gulp.dest('dist/assets'))
});
gulp.task('broswerReload', function () {
browserSync.init(["dist/css/*.css", "dist/js/*.js"], {
server: {
baseDir: "./dist"
}
})
});
gulp.task('serve', gulp.parallel('jsCompile', 'htmlCompile', 'imageCompile', 'broswerReload'), function () {
// gulp.watch(['src/*.scss', 'src/*.css'], ['sassCompile']);
gulp.watch('src/*.js', ['jsCompile']);
gulp.watch(['src/assets/images/*.jpg', 'src/assets/images/*.png'], ['imageCompile']);
gulp.watch('public/*.html', ['htmlCompile'])
// gulp.watch('public/*.html', ['htmlCompile']).on('change', browserSync.reload);
});
gulp.task('default', gulp.series('serve'));

Unable to update protractor config at runtime

I am trying to update protractor config on the run time, because spec file are being read from external excel file.
Below is my config:
export let config = {
allScriptsTimeout: RunConfig.allScriptsTimeout,
capabilities: {
browserName: RunConfig.browser
},
directConnect: true,
baseUrl: RunConfig.baseUrl,
framework: RunConfig.framework,
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: RunConfig.defaultTimeoutInterval,
print: function () {
}
},
onPrepare() {
bot.fullScreen();
Xlsx.readExcel();
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
},
beforeLaunch() {
let spec = new Promise((resolve) => {
resolve({
specs: Xlsx.readSpecs()
});
});
},
resultJsonOutputFile: RunConfig.resultFile
}
According to this it should update config in beforeLaunch
==========================
ReadSpec Function
readSpecs() {
fs.readFile(RunConfig.runManager, (err, buf) => {
if(!err && buf) {
let wb = XLSX.read(buf, { type: 'buffer' });
let sheet = wb.Sheets[sheetNames.specs]; //reading specs
let specArr = XLSX.utils.sheet_to_json(sheet);
let spec;
specArr.forEach(element => {
spec.push(element.spec);
});
return spec;
} else {
return [];
}
});
}
I add explanation inline:
XLSX = require('xlsx');
// change readSpecs() to sync style
readSpecs() {
let wb = XLSX.readFile(RunConfig.runManager);
let sheet = wb.Sheets[sheetNames.specs]; //reading specs
let specArr = XLSX.utils.sheet_to_json(sheet);
let spec;
specArr.forEach(element => {
spec.push(element.spec);
});
return spec;
}
export let config = {
// specify value for `specs`, and it require `Xlsx.readSpecs()`
// does not return promise-like object.
specs: Xlsx.readSpecs(),
onPrepare() {
bot.fullScreen();
// you need to move Xlsx.readExcel(); to the top
// when protractor run into onPrepare() function,
// it means protractor runner had accepted your passed-in config
// the runner won't accept any changes to the config once it accepted.
// Xlsx.readExcel();
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: true
}
}));
},
// beforeLaunch() is unnecessary
// beforeLaunch() {
// let spec = new Promise((resolve) => {
// resolve({
// specs: Xlsx.readSpecs()
// });
// });
// },
};
beforeLaunch() can't change the config yet. There is no hooks can change the config before protractor read it. The only way is to give a pre-know value to specs and not allow promise-like value.
If your Xlsx.readExcel() or Xlsx.readSpecs() return promise, you have to use another way to implement it.
You aren't using the local variable spec for anything in the beforeLaunch function. The example in the link you posted is returning the resolved promise. You need to get rid of the local variable and return the promise like this:
beforeLaunch() {
return new Promise((resolve) => {
resolve({
specs: Xlsx.readSpecs()
});
});
}

why browsersync reload multiple times whe a file is changed?

I have a project with angularjs. All the environment is set under nodejs with gulp and bower dependencies.
I have a problem: every time a file is changed, the browser reloads multiple times.
So, I think is problem is related to the browsersync configuration, how I can fix it?
// ////////////////////////////////////////////////
//
// EDIT CONFIG OBJECT BELOW !!!
//
// jsConcatFiles => list of javascript files (in order) to concatenate
// buildFilesFoldersRemove => list of files to remove when running final build
// // //////////////////////////////////////////////
var config = {
jsConcatFilesApi: [
'./js/initapp/*.js',
'./js/services/*.js',
'./js/charts/*.js',
],
jsConcatFilesNavigation: [
'./js/navigation/**/*.js',
],
buildFilesFoldersRemove:[
'./build/scss/',
'./build/js/!(*.min.js)',
'./build/bower.json',
'./build/node_modules/',
'./build/gulpfile.js',
'./build/package.json',
'./build/maps/',
'./build/readme.md'
]
};
// ////////////////////////////////////////////////
// Required taskes
// gulp build
// bulp build:serve
// // /////////////////////////////////////////////
var gulp = require('gulp'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('gulp-autoprefixer'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
del = require('del');
// ////////////////////////////////////////////////
// Log Errors
// // /////////////////////////////////////////////
function errorlog(err){
console.error(err.message);
this.emit('end');
}
// ////////////////////////////////////////////////
// Scripts Tasks
// ///////////////////////////////////////////////
gulp.task('scriptsApi', function() {
return gulp.src(config.jsConcatFilesApi)
.pipe(sourcemaps.init())
.pipe(concat('temp.js'))
.pipe(uglify())
.on('error', errorlog)
.pipe(rename('d3AcnaDane.min.js'))
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('./js/min/'))
.pipe(reload({stream:true}));
});
gulp.task('scriptsNavigation', function() {
return gulp.src(config.jsConcatFilesNavigation)
.pipe(sourcemaps.init())
.pipe(concat('temp.js'))
.pipe(uglify())
.on('error', errorlog)
.pipe(rename('navigationAcnaDane.min.js'))
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('./js/min/'))
.pipe(reload({stream:true}));
});
// ////////////////////////////////////////////////
// Styles Tasks
// ///////////////////////////////////////////////
gulp.task('styles', function() {
gulp.src('scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}))
.on('error', errorlog)
.pipe(autoprefixer({
browsers: ['last 3 versions'],
cascade: false
}))
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('css'))
.pipe(reload({stream:true}));
});
// ////////////////////////////////////////////////
// HTML Tasks
// // /////////////////////////////////////////////
gulp.task('html', function(){
gulp.src('**/*.html')
.pipe(reload({stream:true}));
});
// ////////////////////////////////////////////////
// Browser-Sync Tasks
// // /////////////////////////////////////////////
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: "./"
}
});
});
// task to run build server for testing final app
gulp.task('build:serve', function() {
browserSync({
server: {
baseDir: "./"
}
});
});
// ////////////////////////////////////////////////
// Build Tasks
// // /////////////////////////////////////////////
// clean out all files and folders from build folder
gulp.task('build:cleanfolder', function (cb) {
del([
'./build/**'
], cb);
});
// task to create build directory of all files
gulp.task('build:copy',function(){
return gulp.src('./**/*/')
.pipe(gulp.dest('./build/'));
});
// task to removed unwanted build files
// list all files and directories here that you don't want included
gulp.task('build:remove', function (cb) {
del(config.buildFilesFoldersRemove, cb);
});
gulp.task('build', ['build:copy', 'build:remove']);
// ////////////////////////////////////////////////
// Watch Tasks
// // /////////////////////////////////////////////
gulp.task ('watch', function(){
gulp.watch('scss/**/*.scss', ['styles']);
gulp.watch('js/**/*.js', ['scriptsApi']);
gulp.watch('js/**/*.js', ['scriptsNavigation']);
gulp.watch('**/*.html', ['html']);
});
gulp.task('default', ['scriptsApi','scriptsNavigation', 'styles', 'html', 'browser-sync', 'watch']);

Prevent gulp to minify code on local machine

I started a project with [RDash angular dashboard][1] which using gulp.
this is the first time I work with gulp and the problem is that while I'm working locally I can't debug because it minify css/js/html files.
How can I prevent from gulp to minify while working locally?
Here is what I have on gulpfile.js:
var gulp = require('gulp'),
usemin = require('gulp-usemin'),
wrap = require('gulp-wrap'),
connect = require('gulp-connect'),
watch = require('gulp-watch'),
minifyCss = require('gulp-minify-css'),
minifyJs = require('gulp-uglify'),
concat = require('gulp-concat'),
less = require('gulp-less'),
rename = require('gulp-rename'),
minifyHTML = require('gulp-minify-html');
var paths = {
scripts: 'src/js/**/*.*',
styles: 'src/less/**/*.*',
images: 'src/img/**/*.*',
templates: 'src/templates/**/*.html',
index: 'src/index.html',
bower_fonts: 'src/components/**/*.{ttf,woff,eof,svg}',
};
/**
* Handle bower components from index
*/
gulp.task('usemin', function() {
return gulp.src(paths.index)
.pipe(usemin({
js: [minifyJs(), 'concat'],
css: [minifyCss({keepSpecialComments: 0}), 'concat'],
}))
.pipe(gulp.dest('dist/'));
});
/**
* Copy assets
*/
gulp.task('build-assets', ['copy-bower_fonts']);
gulp.task('copy-bower_fonts', function() {
return gulp.src(paths.bower_fonts)
.pipe(rename({
dirname: '/fonts'
}))
.pipe(gulp.dest('dist/lib'));
});
/**
* Handle custom files
*/
gulp.task('build-custom', ['custom-images', 'custom-js', 'custom-less', 'custom-templates']);
gulp.task('custom-images', function() {
return gulp.src(paths.images)
.pipe(gulp.dest('dist/img'));
});
gulp.task('custom-js', function() {
return gulp.src(paths.scripts)
.pipe(minifyJs())
.pipe(concat('dashboard.min.js'))
.pipe(gulp.dest('dist/js'));
});
gulp.task('custom-less', function() {
return gulp.src(paths.styles)
.pipe(less())
.pipe(gulp.dest('dist/css'));
});
gulp.task('custom-templates', function() {
return gulp.src(paths.templates)
.pipe(minifyHTML())
.pipe(gulp.dest('dist/templates'));
});
/**
* Watch custom files
*/
gulp.task('watch', function() {
gulp.watch([paths.images], ['custom-images']);
gulp.watch([paths.styles], ['custom-less']);
gulp.watch([paths.scripts], ['custom-js']);
gulp.watch([paths.templates], ['custom-templates']);
gulp.watch([paths.index], ['usemin']);
});
/**
* Live reload server
*/
gulp.task('webserver', function() {
connect.server({
root: 'dist',
livereload: true,
port: 8888
});
});
gulp.task('livereload', function() {
gulp.src(['dist/**/*.*'])
.pipe(watch())
.pipe(connect.reload());
});
/**
* Gulp tasks
*/
gulp.task('build', ['usemin', 'build-assets', 'build-custom']);
gulp.task('default', ['build', 'webserver', 'livereload', 'watch']);
You should add gulp-minify and use it as follows:
var minify = require('gulp-minify');
gulp.task('compress', function() {
gulp.src('lib/*.js')
.pipe(minify({
exclude: ['tasks'],
ignoreFiles: ['.combo.js', '-min.js']
}))
.pipe(gulp.dest('dist'))
});
Pass the files that you dont want to minify to the exclude.
In your code, you have specified that you want to minify all of the files here:
gulp.task('usemin', function() {
return gulp.src(paths.index)
.pipe(usemin({
js: [minifyJs(), 'concat'],
css: [minifyCss({keepSpecialComments: 0}), 'concat'],
}))
.pipe(gulp.dest('dist/'));
});
In line
.pipe(usemin({..})
Just dont use this usemin task, and you should be fine

ngDescribe Won't Complete Second Spec

I'm having trouble with a chained spec when using ngDescribe. The second spec never finishes and times out. If I comment out the first spec, the second spec completes successfully. So, I know each spec is valid and works.
Here is the whole test with both specs.
var baseNotes = window.__mocks__['base-data/notes'];
var baseUsers = window.__mocks__['base-data/users'];
var baseDepartments = window.__mocks__['base-data/departments'];
// Create object to describe all the mocks
var mock = {
app: {
// Mock out all required DB functionality
LocalDb: {
'service': {
dbs: [
{
notes: true
}
]
},
'getDbInfo': function($q) {
return $q.when()
},
'allDocs': function($q) {
return $q.when(baseNotes);
},
'putDoc': function($q) {
var note = {};
note._id = 'xyz123';
console.log("Here is the note now");
console.log(note);
return $q.when(note);
}
},
Users: {
getUsers: function($q) {
return $q.when(baseUsers)
}
},
Departments: {
getDepartments: function($q) {
return $q.when(baseDepartments);
}
}
}
};
ngDescribe
({
name: 'Process Generic Notes Requests',
modules: ['app'],
// Must include $rootScope so that deps.step() is available
inject: ['Notes', 'NoteFactory', '$rootScope'],
mock: mock,
tests: function(deps){
beforeEach(function() {
// Preload the service with notes
deps.Notes.notes = baseNotes;
});
it('should refresh notes from db', function(done) {
// remove the notes from the service
deps.Notes.notes = [];
expect(deps.Notes.notes.length).toEqual(0);
deps.Notes.getNotes(true).then(
function(result) {
expect(result.length).toEqual(3);
done();
}
);
deps.step();
});
it('should fetch notes from memory', function(done) {
deps.Notes.getNotes().then(
function(result) {
expect(result.length).toEqual(3);
done();
}
);
deps.step();
});
it('should get specific note', function(done) {
deps.Notes.getNote(baseNotes[0]._id).then(
function(result) {
expect(result._id).toEqual(baseNotes[0]._id);
done();
}
);
deps.step();
});
it('should get last note', function(done) {
deps.Notes.getLastNote().then(
function(result) {
expect(result._id).toEqual('1436880052000-34lekd');
done();
}
);
deps.step();
});
it('should summarize notes', function() {
var summary = deps.Notes.summarizeNotes();
expect(summary.total).toEqual(3);
expect(summary.finished).toEqual(2);
expect(summary.remaining).toEqual(1);
console.log("Done processing summarize at " + Date.now());
});
}
})({
name: 'Process Update Note Requests',
modules: ['app'],
// Must include $rootScope so that deps.step() is available
inject: ['Notes', 'NoteFactory', '$rootScope'],
mock: mock,
tests: function (deps) {
var newNote;
beforeEach(function () {
// Preload the service with notes
deps.Notes.notes = baseNotes;
// Create a new note
newNote = deps.NoteFactory.createNote();
});
it('should save a new note', function (done) {
console.log("Starting save a note at " + Date.now());
console.log("Here is the note about to be saved");
console.log(newNote);
deps.Notes.updateNote(newNote).then(
function (response) {
dump('Response from update note!');
dump(response);
expect(response._id).toEqual('xyz123');
done();
},
function (error) {
dump('Failed to update note!');
dump(error);
expect('good').toEqual('bad');
done();
}
);
deps.step();
});
}
});

Resources