Jest failed tests no longer provide failure info, only `maxLength` error - error-handling

In my project we had Jest running just fine and as far as I know no test dependencies were changed. When tests would fail it would log out the details of what was expected versus what was received. But if I have a failing test now (or try to make it fail like the following example) all I get is an error around pretty-format options:
when provided no parameters other than text › default values are set correctly
pretty-format: Unknown option "maxWidth".
48 |
49 | it('default values are set correctly', async () => {
> 50 | expect(element.variant).toBe('primarzy');
It should be telling me that it expected "primarzy" (misspelled on purpose) but got "primary". This is happening no matter which test suite has a failed test.

So for anyone else who encounters this, apparently different packages in my test dependencies were trying to run different versions of pretty-format breaking failed test output. The fix for me was just manually installing pretty-format:
npm i pretty-format --save-dev
Everything works fine after that.

Related

ESlint problem with Cypress while using Vite

I wanted to try automated testing with Vue3 for my next project.
When I created my app using Vite and selected that I would like to test with Cypress everything seems to work fine but...
Although project starts like it suppose to when i type in console npm run lint I receive an error message saying:
C:\Users\myname\Desktop\vue-project\cypress\support\component.js
27:1 error 'Cypress' is not defined no-undef
and this is the line in which error occurs:
Cypress.Commands.add("mount", mount);
Any help from you guys would be appreciated
Ok so maybe someone will find it helpful.
It appears that problem with this one considers mainly ESlint.
If you can not run Cypress with command npm run test:unit:
make sure Cypress is also installed globally.
Then simply ignore ESlint errors considering cypress and don't change this line - const { defineConfig } = require("cypress"); even if lint suggest
doing it.
Congrats, you now should be able to run tests with Cypress :)
Bonus: if you do mind errors in your console and wanna keep it clean you search for some lint setup considering Cypress, to find a good setup for your lint if you do mind errors in your console.'eslint-plugin-cypress' didn't do the trick for me.

Why might webpack/babel stop compiling randomly?

I have encountered a few times that either the babel loader in webpack begins throwing errors unexpectedly despite nothing directly relating to webpack or babel etc being altered. As an example I was recently unable to compile due to babel not being able to handle private methods in classes, despite this supposedly being covered as part of babel 7.14+
ERROR in ./node_modules/pdfjs-dist/build/pdf.js 1413:9
Module parse failed: Unexpected character '#' (1413:9)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|
| class PDFDocumentLoadingTask {
> static #docId = 0;
|
The problem persisted even after I rolled back changes to the previous working commit and in the end I was only able to get webpack to compile after reinstalling all npm packages.
What are the possible causes of this?

Migrating from local GitLab to cloud based GitLab results in npm test failing: "TypeError: Cannot read property 'close' of undefined"

On our local build instance with GitLab running jest everything works fine. We are migrating everything to gitlab's cloud and running ci/cd there. The linter, build, etc. all work, but when it gets to npm test and tries to execute the tests, every one of them fails with the same error in same place:
FAIL tests/Charts.test.js
● Test suite failed to run
TypeError: Cannot read property 'close' of undefined
42 |
43 | afterAll(() => {
> 44 | browser.close();
| ^
45 | });
Feels like a dependency issue or configuration. Any help would be appreciated. LMK if something else is needed like package file.
We figured out the problem, turns out the xserver stuff wasn't installed and since we had headless set to false, the browser window couldn't open up.
Setting 'headless' to 'true' let us progress

Animating text in run tool window

I'm using PhpStorm with a Laravel project and have set up a few basic JS tests using AVA.
They all work fine when I run them in the command line. e.g.:
example.text.js
import test from 'ava';
test('just a mockup', async (t) => {
let i = 1;
t.is(1,i);
});
If I run this in the terminal I get:
npm run ava src/example.test.js
ava [...]
ava "src/example.test.js"
1 passed
However if I setup a run configuration and run it via the run window of PhpStorm I get:
npm run ava src/example.test.js
ava [...]
ava "src/example.test.js"
⠋
⠙
⠹
⠸
⠼
⠴
⠦
⠧
⠧ just a mockup…
1 passed
⠇ just a mockup…
1 passed
1 passed
Which is the entire text "animation".
It's not really a problem but it's just annoying when there's many tests since you have to plow through all that junk to get to the actual meaningful information.
Is there any way to get the run window to animate the text?
Update
In case it helps anyone, I'm moving the comment conversation here:
There are 2 separate bug reports/feature requests in webstorm
WEB-19849 Support ANSI commands to show progress correctly to allow ANSI commands in general (which is how the animations are achieved)
WEB-21788 Support ava test runner to allow the Webstom test interface for ava tests
In addition as a temporary solution for myself using the tap output (--tap) in my run configuration which looks a bit nicer.

Ember.js Mocha tests failing randomly with async code

I’m writing tests for an Ember.js application with Mocha. I use the ember-mocha-adapter from Teddy Zeenny.
As soon as a promise is involved, the tests fail randomly. I usually get this error:
Error: Assertion Failed: You cannot defer readiness since the `ready()` hook has already been called.
Here is a JS Bin testcase. It contains 10 times the same test and usually fails (tested with Firefox and Chromium).
The same tests run fine with QUnit (maybe by chance :)) (JS Bin testcase). How can I make this work with Mocha? I tried wrapping the promise in an Ember.run() call, but it doesn’t solve the problem.
There is another question about the same problem, but the corrected JS Bin proposed by Teddy Zeenny also fails for me.
There are 3 problems with the code:
It should not call mocha.setup(), as is now explained in the README.
The function calls to setup Ember.js for testing should happen outside any Mocha callback, not in before().
mocha.run() should be called like this:
Ember.$(function() {
mocha.run();
});
Here is the fixed JS Bin testcase.
Teddy Zeenny found the solution to this problem in teddyzeenny/ember-mocha-adapter#18.
Really the only reason the qunit is working and mocha isn't is because you're running reset before each test vs after each test.
http://emberjs.jsbin.com/nusewoqi/4/edit