I want to use lodash functions in my protractor spec, I'm using _.forEach() to fill a form with values.
How do I get lodash into my protractor script so that I can use it?
I'm not asking how to use it in my app, but in the actual running protractor scripts
You can use the native Array.forEach(). If you need lodash do this:
Get the node dependency.
npm install lodash --save-dev
Then use it in your test.
var _ = require('lodash');
describe('foo', function() {
it('should do stuff', function() {
_.each();
});
})
Related
There are other questions on stackoverflow about this topic, but not the one I was hoping for.
Here is a simplified version of my gulpfile.js
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('css', function() {
gulp.src('site/scss/style.scss')
.pipe(sass())
.pipe(gulp.dest('assets/css'))
});
gulp.task('watch', function() {
gulp.watch('site/scss/**/*.scss', ['css']);
});
I can do this successfully:
gulp watch
Now I want to be able to do something like this in my terminal command line:
gulp watch my-domain-name
or
gulp watch my-other-domain
My gulpfile would in my mind look something like this:
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('css', function(name) {
gulp.src('site/scss/style.scss')
.pipe(sass())
.pipe(gulp.dest('assets/css'))
});
gulp.task('watch', function(name) {
gulp.watch('site/scss/**/*.scss', ['css', name]);
});
I try to send name around as a variable of my watch task. In my case it would be my-domain-name or my-other-domain depending on what I write in my terminal.
How can I send a parameter from the terminal to the watch task and then over to the css task?
There are a number of sources for passing parameters from the command line to gulp. See:
https://www.sitepoint.com/pass-parameters-gulp-tasks/
https://github.com/gulpjs/gulp/blob/master/docs/recipes/pass-arguments-from-cli.md
The official recipe uses
minimist an extremely popular package.
So with these approaches you would not be passing the command line args directly to the watch task, but rather to an object that can be accessed by any task.
And it look like gulp-param may do exactly what you want, directly injecting command line args into each task's callback function.
According to this it's possible to compile susy install from Ruby with Gulp.
But is it possible to use gulp-sass instead of gulp-compass or gulp-ruby-sass because of performance and deprecation ?
Actually I use this in my gulpfile.js:
gulpfile
var gulp = require('gulp');
// Include plugins
var plugins = require('gulp-load-plugins')();
// Variables de chemins
var source = './sass/**/*.scss'; // dossier de travail
var destination = './css/'; // dossier à livrer
gulp.task('sasscompil', function () {
return gulp.src(source)
.pipe(plugins.sass({
outputStyle: 'compressed',
includePaths: ['/home/webmaster/vendor/bundle/gems/susy-2.2.2/sass']
}).on('error', sasscompil.logError))
.pipe(plugins.csscomb())
.pipe(plugins.cssbeautify({indent: ' '}))
.pipe(plugins.autoprefixer())
.pipe(gulp.dest(destination + ''));
});
But the error log doesn't work because sasscompil isn't define.
Then I need to give the path for all ex-compass includes like susy, sassy-button,etc..
is it possible to give a global path for gems ?
other thing, do I install gulp plugins despite of using gulp-load-plugins ? because gulp doesn't find plugins if I don't do that.
Thanks
You need to change sasscompil.logError to plugins.sass.logError
such that
gulpfile.js
gulp.task('sasscompil', function () {
return gulp.src(source)
.pipe(plugins.sass({
outputStyle: 'compressed',
includePaths: ['/home/webmaster/vendor/bundle/gems/susy-2.2.2/sass']
}).on('error', plugins.sass.logError))
...
});
gulp-sass doc:
Pass in options just like you would for node-sass; they will be passed along just as if you were using node-sass. Except for the data option which is used by gulp-sass internally. Using the file option is also unsupported and results in undefined behaviour that may change without notice.
example
gulp.task('sass', function () {
return gulp.src('./sass/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
I am new in jasmine testing and I have searched the test case example for requestAnimationFrame in jasmine document, but I couldn't find it.
I found this plugin to create mock requestAnimationFrame, but I need to use jasmine inbuilt option to test requestAnimationFrame.
Is there any option to test the requestAnimationFrame with jasmine using inbuilt functionalities?
Use setTimeout() and done():
it("Spec with requestAnimationFrame", (done) => {
window.requestAnimationFrame(() => {
// Do something testable here
});
setTimeout(function() {
// Verify testable values here
done();
}, 200);
});
I need to perform after mix.less ('app.less') automatically reloads the page. What would not press each time F5
gulpfile.js
var elixir = require('laravel-elixir');
/*
|--------------------------------------------------------------------------
| Elixir Asset Management
|--------------------------------------------------------------------------
|
| Elixir provides a clean, fluent API for defining some basic Gulp tasks
| for your Laravel application. By default, we are compiling the Less
| file for our application, as well as publishing vendor resources.
|
*/
elixir(function(mix) {
mix.less('app.less');
mix.copy('resources/assets/vendor/bootstrap-switch/dist', 'public/packages/bootstrap-switch');
});
Is it possible to use it as a gulp browser-sync ?
I’m afraid there is no way to use livereload with elixir yet.
I suggest you to quite using elixir and start using all the freedom of general versatile gulp plugins.
My recipe for live reload with Livereload:
Install Livereload plugin for Chrome
Enable it pressing its button in Chrome’s toolbar
Install gulp-modules:
npm install gulp gulp-plumber gulp-connect gulp-sass --save-dev
Create simple gulpfile (with livereload of *.scss files only) like
below.
run gulp
Example of gulpfile.js
'use strict';
var
gulp = require('gulp'),
plumber = require('gulp-plumber'),
connect = require('gulp-connect'),
sass = require('gulp-sass');
gulp.task('sass', function () {
return gulp.src('public/css/*.sass')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('public/css'));
});
gulp.task('watch', ['sass'], function () {
gulp.watch(['resources/assets/sass/*.scss'],
function (e) {
gulp.src(e.path)
.pipe(plumber())
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('public/css'))
;
}
);
gulp.watch(['public/css/*.css',],
function (e) {
gulp.src(e.path)
.pipe(connect.reload())
;
}
);
});
gulp.task('server', ['watch'], function () {
connect.server({
root: 'public',
livereload: true
});
});
gulp.task('default', ['server']);
First install a plugin called laravel-elixir-livereload with
npm install --save-dev laravel-elixir-livereload
After that in your gulpfile.js write this:
var elixir = require('laravel-elixir');
require('laravel-elixir-livereload');
elixir( function(mix) {
mix.less('app.less')
.livereload();
});
Finally run
gulp watch
Documentation https://www.npmjs.com/package/laravel-elixir-livereload
You can use browsersync() without installing anything if you have Elixir 3.3 and Homestand
Run first: $ php artisan serve --host=0
On your gulpfile.js: mix.browserSync({proxy: 'localhost:8000'});
You can use the laravel-elixir-browsersync-official plugin.
Your gulpfile.js should look like this:
const elixir = require('laravel-elixir');
elixir((mix) => {
mix.less('app.less')
.copy('resources/assets/vendor/bootstrap-switch/dist', 'public/packages/bootstrap-switch')
.browserSync({
proxy: 'your-project.url'
})
});
I have a Yeoman webapp project, where I've added socket.io-client using bower.
Everything works fine when I run the webapp with grunt server. But when I build it with grunt build, I get the following error:
Uncaught TypeError: Cannot call method 'push' of undefined
By enabling source maps in Gruntfile.js (generateSourceMaps: true), I managed to track down the source of the error in socket.io.js:
/**
* Add the transport to your public io.transports array.
*
* #api private
*/
io.transports.push('websocket');
What could make io.transports become undefined after running grunt build?
UPDATE:
Probably worth telling that I use RequireJS and it's configured like this:
require.config({
paths: {
jquery: '../bower_components/jquery/jquery',
// ...
// socket.io: Try the node server first
'socket.io': ['/socket.io/socket.io', '../bower_components/socket.io-client/dist/socket.io'],
},
shim: {
// Export io object: https://gist.github.com/guerrerocarlos/3651490
'socket.io': {
exports: 'io'
}
}
});
require(['jquery', 'socket.io'], function ($, io) {
'use strict';
// ...
});
You should only have the socket.io-client defined in the paths:
paths: {
'jquery': '../bower_components/jquery/jquery',
'socket.io': '../bower_components/socket.io-client/dist/socket.io'
},
Also you should not set the io parameter (it is set globally) (or use something else like sio)
require(['jquery', 'socket.io'], function ($) {
'use strict';
// ...
});