jest: output only ASCII characters in the reports - windows

On a clean node project with Jest 24.9.0, this test suite
test('a test', () => {
expect('foo').toBe('foo');
});
test('b test', () => {
throw 'foo';
});
outputs the following (abbreviated):
√ a test
× b test (1ms)
● b test
The non-ASCII characters, especially the bullet, cause a significant slow-down in an Emacs buffer on Windows 10.
How can I instruct Jest to output only ASCII characters in its decorations?
Jest documentation is silent on the issue; grepping node_modules folder for these characters turned out nothing promising (directly related to Jest).

I tried various reporters, but not to my satisfaction. It's easiest to simply filter the report:
package.json
{
"scripts": {
"test": "jestwrapper"
}
}
bin/jestwrapper
#!/usr/bin/bash
jest 2>&1 | perl -C -Mutf8 -lpe'tr/√✔✓✘✕●/+++xx-/'

Related

Can't get tagging to work with cypress-cucumber-preprocessor

I am currently having issues with using tagging with the cypress-cucumber-preprocessor package. I know that the cypress-tags has been removed and made redundant so I'm trying to set up tagging using the new syntax but to no avail.
Here is my feature:
Feature: duckduckgo.com
Rule: I am on a desktop
Scenario: visiting the frontpage
When I visit <site>
Then I should see a search bar
#google
Examples:
| site |
| google.com |
#duckduckgo
Examples:
| site |
| duckduckgo.com |
And my step definitions:
import { When, Then } from "#badeball/cypress-cucumber-preprocessor";
When(`I visit` + url, () => {
if(url === 'duckduckgo.com') return cy.visit("https://www.duckduckgo.com");
if(url === 'google.com') return cy.visit("https://www.google.com");
});
Then("I should see a search bar", () => {
cy.get("input").should(
"have.attr",
"placeholder",
"Search the web without being tracked"
);
});
When I try to run my tests with npx cypress run --env tags="#google", it gives me an error saying url in my steps definitions isn't defined. What am I doing wrong?
Try to add script with this command in package.json file this way:
"scripts": {
"open:test": "npm run clean:report && cypress open --env configFile=test,TAGS=#test" (or any tag you need)
}
And then use it as:
npn run open:test
The main difference besides rapping it into script is not using quotes, maybe this will help you

Gradle execute a command with spaces and pipe output while running

I am trying to do an Xcode build in Gradle. Requirements:
Some of my arguments have spaces in them.
I want to pipe the output through xcpretty. Otherwise gitlab complains that there is too much output and I can't see any errors toward the end of the build
I don't want to wait for the command to complete before seeing the output. I want to be able to watch it build, like any ci job
Gradle exec{} doesn't seem to let me pipe the output while building. I can save the output to a file but that doesn't let me watch the build
I.e.,
exec {
executable 'xcodebuild'
ext.output = {
return standardOutput.toString()
}
args = [
'archive',
'-project',
"${buildDir}/iPhone/Unity-iPhone.xcodeproj/",
"-archivePath",
"${buildDir}/iPhone/Unity-iPhone.xcarchive",
"-sdk", "iphoneos",
"GCC_GENERATE_DEBUGGING_SYMBOLS=YES",
"DEBUG_INFORMATION_FORMAT=dwarf-with-dsym",
"DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT=NO",
"DWARF_DSYM_FOLDER_PATH=iOS_Dsym",
"DEBUGGING_SYMBOLS=YES",
"DEVELOPMENT_TEAM=RPGSNMH65P",
"CODE_SIGN_IDENTITY=${appleIdentity}",
"CODE_SIGN_STYLE=Manual",
"USYM_UPLOAD_AUTH_TOKEN=${appcenter_login_token}",
"PROVISIONING_PROFILE_SPECIFIER_APP=${provisioningProfile}",
"-configuration", "Release",
"-scheme", "${schemeName}",
"| xcpretty"
]
}
doesn't work
I can't use groovy "xcodebuild ... CODE_SIGN_IDENTITY=${"${appleIdentity}"} ... | xcpretty".execute() because my code signing identity contains spaces and for some reason groovy wants to stick its own quotes into the command string when it finds spaces.
I tried the array execute method but ended up with the same problem.
def cmd = [
'xcodebuild ',
'archive',
'-project',
"${buildDir}/iPhone/Unity-iPhone.xcodeproj/",
"-archivePath",
"${buildDir}/iPhone/Unity-iPhone.xcarchive",
"-sdk", "iphoneos",
"GCC_GENERATE_DEBUGGING_SYMBOLS=YES",
"DEBUG_INFORMATION_FORMAT=dwarf-with-dsym",
"DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT=NO",
"DWARF_DSYM_FOLDER_PATH=iOS_Dsym",
"DEBUGGING_SYMBOLS=YES",
"DEVELOPMENT_TEAM=RPGSNMH65P",
"CODE_SIGN_IDENTITY=${appleIdentity}",
"CODE_SIGN_STYLE=Manual",
"USYM_UPLOAD_AUTH_TOKEN=${appcenter_login_token}",
"PROVISIONING_PROFILE_SPECIFIER_APP=${provisioningProfile}",
"-configuration", "Release",
"-scheme", "${schemeName}"
]
println cmd
def proc = cmd.execute()
... except that it's even harder to debug because I can't see the actual command being executed.
I have found various solutions online but nothing that fits these requirements

`Tslint --fix` does not autofix but instead generates lint problems as console errors

I'm using the Angular starter kit
and I'm trying to get tslint to autofix all my lint problems with the --fix flag.
I'm running the script:
npm run tslint --fix src/**/*.ts
It just generates the same error that I'm already being told about in tslint and not autofixing it:
console output:
ERROR: src/app/app-routing.module.ts[10, 5]: comment must start with a space
ERROR: src/app/app-routing.module.ts[2, 20]: Too many spaces before 'from'
Am I missing something that allows it to implement the changes?
My versions are:
"tslint": "^5.6.0"
"codelyzer": "^3.1.2"
Question: How can I get tslint to implement autofix to my lint errors?
Unfortunately, not all linting violations are auto-fixable. You can see which rules are auto-fixable here by looking for the Has Fixer tag.
My guess is that "comment must start with a space" is governed by the comment-format rule, which is not auto-fixable.
I'm not sure which rule is causing your second error, but it is most likely also not auto-fixable.
Here's a snippet you can run tslint --fix against to verify that some violations are fixed, and others are not.
//no var keyword (comment does not start with space)
var x: string = 'x';
console.log(x);
// array-type
let y: String[] = [];
console.log(y);
// ban-single-arg-parens
['1', '2'].filter((arg) => {
console.log(arg);
});
// semicolon
let z: string = ''
console.log(z);
// no unused variable
let a: string = '';
// trailing comma
let list = ['1', '2', ];
// missing trailing comma
let obj = [
1,
2
];
Rules to include when linting the above file:
"semicolon": [true, "always"],
"trailing-comma": [true, {"multiline": "always", "singleline": "never"}],
"array-type": [true, "array-generic"],
"arrow-parens": [true, "ban-single-arg-parens"],
It's tempting to think that all whitespace errors would be auto-fixable, and perhaps they should be. Sadly, they're not.
Update library tslint and codelyzer to latest.
and then use this command:
tslint --fix src/**/*.ts -t verbose without using npm run
after complete, it will show to you the unfixable problems so you have to fix it manually.
You can also add it to scripts in package.json like this:
"lint-fix": "tslint --fix src/**/*.ts -t verbose"

Jest silently ignores errors

Given the following test.js
var someCriticalFunction = function() {
throw 'up';
};
describe('test 1', () => {
it('is true', () => {
expect(true).toBe(true);
})
});
describe('test 2', () => {
it('is ignored?', () => {
someCriticalFunction();
expect(true).toBe(false);
})
});
Running Jest will output
Using Jest CLI v0.9.2, jasmine2
PASS __tests__/test.js (0.037s)
1 test passed (1 total in 1 test suite, run time 0.795s)
Which pretty much gives you the impression everything is great. So how do I prevent shooting my own foot while writing tests? I just spent an hour writing tests and now I wonder how many of them actually run? Because I will certainly not count all of them and compare with the number in the report.
Is there a way to make Jest fail as loud as possible when an error is thrown as part of the test suite, not the tests itself (like preparation code)? Putting it inside beforeEach doesn't change anything.
This is fixed in 0.9.3 jest-cli https://github.com/facebook/jest/pull/812
Which for some reason is unpublished again (I had it installed minutes ago). So anyway, throwing strings is now caught. You should never throw strings anyway and thanks to my test suite I found one of the last places I actually still threw strings...

Mocha test failing using babel and webpack

So I am using webpack, babel, and mocha here. When I have code like this:
import userImage from '../../images/user.png';
and I build with webpack, userImage results in a string to the path of the file since I am using the file loader for images (requirements call for me not to embed images) however when I try to run my mocha tests using:
./node_modules/.bin/babel-node ./node_modules/.bin/babel-istanbul cover ./node_modules/.bin/_mocha
I get a syntax error:
SyntaxError: /repositories/react-seed/web/app/images/user.png: Unexpected character '�' (1:0)
> 1 | �PNG
| ^
2 |
3 |
I also get this error when removing istanbul. So it seems like it is trying to load the actually image file however can parse it as JavaScript since it is not.
Anyone know a way around this issue?
You can use the --compilers option which allows you to customize the nodejs require system in order to let it understand png files. So :
mocha --compilers png:./mochacfg.js
Or create a file 'test/mocha.opts' containing (better for your needs):
--compilers png:./mochacfg.js
With ./mochacfg.js:
require.extensions['.png'] = function(){ return null; }
This ignores png files (should be ok if you do nothing special with them).
If you want to do something with the image data:
var fs = require('fs');
require.extensions['.png'] = function(module, filepath) {
var src = fs.readFileSync(filepath).toString ('base64');
return module._compile('module.exports = "data:image/png;base64,' + src + '";');
}
Its quite late to answer this question but just for knowledge sharing purpose, I am answering another approach to do this.
Create a test-config.js file and use it while running the mocha test cases.
var jsdom = require('jsdom').jsdom;
process.env.NODE_ENV = 'test';
// -------------------------------
// Disable webpack-specific features for tests since
// Mocha doesn't know what to do with them.
['.css', '.scss', '.png', '.jpg'].forEach(ext => {
require.extensions[ext] = () => null;
});
and inside package.json use this test command to run the test cases
"test": "mocha ./test/test-setup.js './test/**/*.spec.js' --compilers js:babel-core/register",
I hope it helps someone.

Resources