I'm using the config from my project but would like to run karma just for one specific test script one time. I don't want to have to create a whole new config file just for this case and would prefer just passing in the script I want run (so basically telling karma to use files: ['myTest.js'].
But there don't seem to be any options for that AFAICT in the docs. Why would this be missing? It seems like a fundamental feature IMO.
in karma.conf something like that:
function mergeFilesWithArgv(staticFiles) {
var source = staticFiles, argv = process.argv;
argv.forEach(function (arg) {
var index = arg.indexOf('--check=');
if (index !== -1) {
source.push(arg.substring(8));
}
});
return source;
}
config.set({
...
files: mergeFilesWithArgv([
'js_src/tests/*.test.js'
]),
...
});
use: karma start --check='./path/to/file.js'
or for multiple files: karma start --check='./path/to/file.js' --check='/another/path/to/another/file.js'
Related
I am trying to learn babel. I got the babel-core module working, but I am trying to use .babelrc and it's not doing anything.
Here's my .babelrc file.
{
"plugins":["transform-es3-property-literals"]
}
And here's my code:
var babel = require("babel-core");
var js = `var x = { catch: 4, bar: 7 };`;
var notUsingBabelRc = babel.transform(js,{
plugins: ["transform-es3-property-literals"]
}).code;
var usingBabelRc = babel.transform(js).code
console.log(notUsingBabelRc == usingBabelRc);
//false, but should be true. Adding plugins as an option transforms the code.
console.log(usingBabelRc == js);
//true, but should be false. The code is not changed from its original form.
I have the .babelrc file in the root directory of the project. I also have my script file called using_babelrc.js a the root directory of the project.
Then I call node using_babelrc and I get false true even though I expect true false.
What simple thing am I missing?
The transform function also needs the filename option supplied to start looking for .babelrc files relative to that filename. In your case:
babel.transform(js, {filename: "using_babelrc.js"}).code;
will read the config file in the same folder as using_babelrc.js.
I'm trying to create a report for my scenario, I want to execute some validations and add the retults in a string, then, write this string in a TXT file (for each validation I would like to add the result and execute again till the last item), something like this:
it ("Perform the loop to search for different strings", function()
{
browser.waitForAngularEnabled(false);
browser.get("http://WebSite.es");
//strings[] contains 57 strings inside the json file
for (var i = 0; i == jsonfile.strings.length ; ++i)
{
var valuetoInput = json.Strings[i];
var writeInFile;
browser.wait;
httpGet("http://website.es/search/offers/list/"+valuetoInput+"?page=1&pages=3&limit=20").then(function(result) {
writeInFile = writeInFile + "Validation for String: "+ json.Strings[i] + " Results is: " + expect(result.statusCode).toBe(200) + "\n";
});
if (i == jsonfile.strings.length)
{
console.log("Executions finished");
var fs = require('fs');
var outputFilename = "Output.txt";
fs.writeFile(outputFilename, "Validation of Get requests with each string:\n " + writeInFile, function(err) {
if(err)
{
console.log(err);
}
else {
console.log("File saved to " + outputFilename);
}
});
}
};
});
But when I check my file I only get the first row writen in the way I want and nothing else, could you please let me know what am I doing wrong?
*The validation works properly in the screen for each of string in my file used as data base
**I'm a newbie with protractor
Thank you a lot!!
writeFile documentation
Asynchronously writes data to a file, replacing the file if it already
exists
You are overwriting the file every time, which is why it only has 1 line.
The easiest way would probably (my opinion) be appendFile. It writes to a file without overwriting existing data and will also create the file if it doesnt exist in the first place.
You could also re-read that log file, store that data in a variable, and re-write to that file with the old AND new data included in it. You could also create a writeStream etc.
There are quite a few ways to go about it and plenty of other answers
on SO specifically on those functions that can provide more info.
Node.js Write a line into a .txt file
Node.js read and write file lines
Final note, if you are using Jasmine you can also create a custom jasmine reporter. They have methods that contain exactly what you want (status Pass/Fail, actual vs expected values etc) and it's fairly easy to set up with Protractor
Goal:
Build /src/assets/(theme)/*.scss by passing the parameter in the command line using flag --theme. I solved step one using gulp-utils
function sass() {
// return gulp.src('/src/assets/scss/**/*.scss')
return gulp.src(['src/assets/scss/' + (util.env.theme ? util.env.theme : 'app') + '.scss'])
.pipe($.sourcemaps.init())
.pipe($.sass({
includePaths: PATHS.sass
})
.on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: COMPATIBILITY
}))
// Comment in the pipe below to run UnCSS in production
//.pipe($.if(PRODUCTION, $.uncss(UNCSS_OPTIONS)))
.pipe($.if(PRODUCTION, $.cleanCss({ compatibility: 'ie9' })))
.pipe($.if(!PRODUCTION, $.sourcemaps.write()))
.pipe(gulp.dest(PATHS.dist + '/assets/css'))
.pipe(browser.reload({ stream: true }));
}
Remaining:
gulp build --production --theme folderName1, folderName2, folderName*
Passing multiple theme values --theme folderName1 folderName2 to the same sass() function/task.
This would send folderName to function sass()
function sass() {
// return gulp.src('/src/assets/scss/**/*.scss')
return gulp.src([
'src/assets/scss/folderName1/*.scss',
'src/assets/scss/folderName2/*.scss',
'src/assets/scss/folderName3/*.scss'
])
...
...
}
Would creating an argsList like this SitePoint article discusses work?
Please review your idea. This package looks like solve similar topic
https://www.npmjs.com/package/gulp-sass-themes
You need only group your themes in sub-folder.
From other side gulp.src accepts string and array so you can pass this information from command line.
https://github.com/gulpjs/gulp/blob/master/docs/API.md
One of my colleagues was able to help resolve this issue. Instead of using gulp.utils he was able to use yargs.argv.theme with slipt(,). This allows for a user to pass the --theme param and pass as many comma-separated items as desired.
function sass() {
if (yargs.argv.theme) {
let collection = yargs.argv.theme.split(','),
results = collection.map(item => `./src/assets/scss/${item}/*.scss`);
return gulp.src(results)
.pipe($.sourcemaps.init())
.pipe($.sass({
includePaths: PATHS.sass
})
.on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: COMPATIBILITY
}))
// Comment in the pipe below to run UnCSS in production
//.pipe($.if(PRODUCTION, $.uncss(UNCSS_OPTIONS)))
.pipe($.if(PRODUCTION, $.cleanCss({ compatibility: 'ie9' })))
.pipe($.if(!PRODUCTION, $.sourcemaps.write()))
.pipe(gulp.dest(PATHS.dist + '/assets/css'))
.pipe(browser.reload({ stream: true }));
}
}
I have the following code, which reads what task name I passed to gulp: release or test and decides what task group to load from the files based on that.
var argv = require('yargs').argv;
var group = argv._[0];
var groups = {
"release": ["tasks/release/*.js", , "tasks/release/deps.json"],
"test": ["tasks/test/*.js", "tasks/test/deps.json"]
};
require("gulp-task-file-loader").apply(null, groups[group]);
Isn't there a better way to get the commanded tasks from gulp itself instead of using yargs?
I found a great tutorial about tools for CLI. According to it I should use commander, so I do so. It is much better than yargs. Another possible solution to use process.argv[2] in this case, but it is much better to use a parser in long term.
var program = require("commander");
program.parse(process.argv);
var group = program.args[0];
var groups = {
"release": ["tasks/release/*.js", , "tasks/release/deps.json"],
"test": ["tasks/test/*.js", "tasks/test/deps.json"]
};
require("gulp-task-file-loader").apply(null, groups[group]);
I'm using gulp and gettext, all works well except when I have multiple .po files.
gulp.task('translations', function () {
return gulp.src('app/po/*.po')
.pipe($.gettext.compile())
.pipe($.rename('translations.js'))
.pipe(gulp.dest(dest));
});
I have three .po files: lang1.po, lang2.po and lang3.po, and I only get lang3.po in translations.js. I guess this task is overwriting things. Any suggestions how I can cat everything together into translations.js ?
What you are doing here is:
step 1: compile lang1.po, compile lang2.po, compile lang3.po
step 2: rename lang1.po to translations.js, rename lang2.po to translations.js, rename lang3.po to translations.js
Get the idea?
You probably want to concat instead (using gulp-concat).
gulp.task('translations', function () {
return gulp.src('app/po/*.po')
.pipe($.gettext.compile())
.pipe(concat('translations.js')))
.pipe(gulp.dest(dest));
});
Hope that helps.