How can in Gulp pass Mocha grep parameter into my task? - mocha.js

I have my gulpfile.coffee
gulp = require 'gulp'
coffeelint = require 'gulp-coffeelint'
mocha = require 'gulp-mocha'
plumber = require 'gulp-plumber'
gutil = require 'gulp-util'
watch = require 'gulp-watch'
handleError = (err) ->
console.error err.message
process.exit 1
gulp.task 'test', ->
gulp.src('test/*-test.*')
.pipe(mocha(reporter: 'spec'))
.on 'error', handleError
I need run gulp test --grep group1, i found options.grep but i don't know how proceed parameter from CLI.

SOLVED: using yargs npm package
gulp = require 'gulp'
coffeelint = require 'gulp-coffeelint'
mocha = require 'gulp-mocha'
plumber = require 'gulp-plumber'
gutil = require 'gulp-util'
watch = require 'gulp-watch'
yargs = require 'yargs'
handleError = (err) ->
console.error err.message
process.exit 1
gulp.task 'test', ->
gulp.src('test/*-test.*')
.pipe(mocha(reporter: 'spec', grep: yargs.argv.grep))
.on 'error', handleError

Related

Gulp sass issue with importing node_modules that start with tilde

I'm converting .scss files to .css through a gulp sass task. The issue is that the base .scss file contains imports that contain other imports. These imports start with
~#angular/material/core/etc/etc
The tilde results in the following error:
events.js:160
throw er; // Unhandled 'error' event
^
Error: node_modules\#covalent\core\chips\_chips-theme.scss
Error: File to import not found or unreadable: ~#angular/material/core/theming/theming.
Parent style sheet: C:/Users/laurensk/Documents/Playground/node_modules/#covalent/core/chips/_chips-theme.scss
on line 1 of node_modules/#covalent/core/chips/_chips-theme.scss
>> #import '~#angular/material/core/theming/theming';
^
There's a custom importer called node-sass-tilde-importer but I am unsure if it's possible to implement this into my gulp sass task.
My code:
var gulp = require("gulp"),
sass = require("gulp-sass");
//var replace = require('gulp-replace');
//var sassGlob = require('gulp-sass-glob');
//var tildeImporter = require('node-sass-tilde-importer');
gulp.task("sass", function () {
return gulp
.src('Styles/theme.scss')
.pipe(sass())
.pipe(gulp.dest('wwwroot/dist'));
});
I've tried replace to replace '~' with './node_modules' but it throws the same error.
Any input would be appreciated!
gulp-sass accept all node-sass properties.
So you just need to configure gulp-sass with the node-sass-tilde-importer importer:
var gulp = require("gulp"),
sass = require("gulp-sass");
var tildeImporter = require('node-sass-tilde-importer');
gulp.task("sass", function () {
return gulp
.src('Styles/theme.scss')
.pipe(sass({
importer: tildeImporter
}))
.pipe(gulp.dest('wwwroot/dist'));
});

Error with gulp-ruby-sass Error: must provide pattern

I'm using Ruby sass with PostCSS. This is my gulp css task.
gulp.task('css', function () {
var processors = [
short,
rucksack,
postcssmodules
];
return gulp.src('./css/src/*.scss')
.pipe(postcss(processors, {syntax: scss}))
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dest'));
});
Error I'm getting
➜ website git:(master) ✗ gulp css
[09:52:08] Using gulpfile ~/my-projects/website/gulpfile.js
[09:52:08] Starting 'css'...
[09:52:08] 'css' errored after 12 ms
[09:52:08] Error: must provide pattern
at new GlobSync (/Users/jitendravyas/my-projects/website/node_modules/glob/sync.js:29:11)
at Function.globSync [as sync] (/Users/jitendravyas/my-projects/website/node_modules/glob/sync.js:24:10)
at /Users/jitendravyas/my-projects/website/node_modules/gulp-ruby-sass/index.js:68:21
at Array.forEach (native)
at gulpRubySass (/Users/jitendravyas/my-projects/website/node_modules/gulp-ruby-sass/index.js:67:10)
at /Users/jitendravyas/my-projects/website/gulpfile.js:48:15
at taskWrapper (/Users/jitendravyas/my-projects/website/node_modules/undertaker/lib/set-task.js:13:15)
at bound (domain.js:287:14)
at runBound (domain.js:300:12)
at asyncRunner (/Users/jitendravyas/my-projects/website/node_modules/async-done/index.js:36:18)
You cannot use gulp-ruby-sass in a .pipe(). Read the docs:
Use gulp-ruby-sass instead of gulp.src to compile Sass files.
You'll have to use sass() before your postcss():
gulp.task('css', function() {
var processors = [
short,
rucksack,
postcssmodules
];
return sass('./css/src/*.scss')
.on('error', sass.logError)
.pipe(postcss(processors))
.pipe(gulp.dest('./dest'));
});

Reload plugin when using `jekyll serve`

I'm developing a Jekyll plugin. When I run the jekyll serve command, site files are regenerated when I change any markdown, html, or plugin files, as expected. The problem I've found is that while markdown/HTML files are regenerated, the plugins themselves are not reloaded. I have to terminate jekyll serve and issue the command again for the plugin changes to go into effect. Is there a way to make it so that the plugins get reloaded automatically when changed?
This is for Jekyll 3.1.2.
Based on the suggestion from #DavidJacquel and the gist I found here, I used Gulp with this gulpfile
'use strict';
var gulp = require('gulp'),
express = require('express'),
spawn = require('child_process').spawn;
var jekyll_file = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
gulp.task('jekyll', () => {
var jekyll = spawn(jekyll_file, ['build', '--incremental']);
var output = '';
jekyll.stdout.on('data', (t) => { output += t; });
jekyll.stderr.on('data', (t) => { output += t; });
jekyll.on('exit', (code) => {
if (code)
console.log(`Jekyll exited with code: ${code}\n${output}`);
else
console.log("Finished Jekyll build");
});
});
gulp.task('serve', () => {
var server = express();
server.use(express.static('_site/'));
server.listen(4000);
});
gulp.task('watch', () => {
gulp.watch(['**/*.html', '**/*.md', '_plugins/*.rb', '!_site/**/*'], ['jekyll']);
});
gulp.task('default', ['jekyll', 'serve', 'watch']);
to get the desired effect. Also created issue here.

Testing with gulp + babel + jasmine on nodejs

I am trying to test my code with gulp-jasmine and gulp-babel:
var gulp = require("gulp"),
jasmine = require("gulp-jasmine"),
babel = require("gulp-babel");
module.exports = function () {
gulp.src(["index.js", "src/**/*.js", "spec/**/*[sS]pec.js"])
.pipe(babel({
"presets": ["es2015"],
"plugins": ["transform-runtime"]
}))
.pipe(jasmine())
};
I got
events.js:141
throw er; // Unhandled 'error' event
^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at D:\creation\software developer\projects\javascript-project-template\node_modules\jasmine\lib\jasmine.js:63:5
at Array.forEach (native)
at Jasmine.loadSpecs (D:\creation\software developer\projects\javascript-project-template\node_modules\jasmine\lib\jasmine.js:62:18)
Any idea about what I am missing? The code appears to break because there are still ES6 keywords used. I am not sure how to fix this.
According to sindresorhus the lib works only on file paths, so I cannot use streams: https://github.com/sindresorhus/gulp-jasmine/issues/60#event-452847672
He suggested this approach instead:
require('babel-core/register');
var gulp = require("gulp"),
jasmine = require("gulp-jasmine");
module.exports = function () {
gulp.src(["index.js", "src/**/*.js", "spec/**/*[sS]pec.js"])
.pipe(jasmine({
includeStackTrace: true
}))
};

jasmine-reporters is not generating any file

i'm using jasmine-reporters to generate a report after protractor finish the tests,
this is my configuration file:
onPrepare: function(){
var jasmineReporters = require('jasmine-reporters');
var capsPromise = browser.getCapabilities();
capsPromise.then(function(caps){
var browserName = caps.caps_.browserName.toUpperCase();
var browserVersion = caps.caps_.version;
var prePendStr = browserName + "-" + browserVersion + "-";
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter("protractor_output", true, true,prePendStr));
});
},
i don't get any error, the reporters installed, but i don't see any file in protractor_output folder.
Any idea what am i doing wrong?
The problem is with the jamsine version:
If you are trying to use jasmine-reporters with Protractor, keep in mind that Protractor is built around Jasmine 1.x. As such, you need to use a 1.x version of jasmine-reporters.
npm install jasmine-reporters#~1.0.0
then the configuration should be:
onPrepare: function() {
// The require statement must be down here, since jasmine-reporters#1.0
// needs jasmine to be in the global and protractor does not guarantee
// this until inside the onPrepare function.
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('xmloutput', true, true)
);
}
If you are on a newer version of the Jasmine Reporter, then the require statement no longer puts the JUnitXmlReporter on the jasmine object, but does put it on the module export. Your setup would then look like this:
onPrepare: function() {
// The require statement must be down here, since jasmine-reporters#1.0
// needs jasmine to be in the global and protractor does not guarantee
// this until inside the onPrepare function.
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmineReporters.JUnitXmlReporter('xmloutput', true, true)
);
}
also you need to verify that xmloutput directory exist!
To complete the answer, if the output is still not generating,
Try adding these configuration line to your protractor exports.config object :
framework: "jasmine2",
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
.......
}

Resources