console-ninja icon indicating copy to clipboard operation
console-ninja copied to clipboard

Support @salesforce/sfdx-lwc-jest

Open dkadam77 opened this issue 2 years ago • 9 comments

I have a Salesforce LWC project and I am using Jest for Unti Testing. The project does have a Jest Unit tests. But the extension is showing that it is waiting for Jest to start/restart. Please note that I have console.log statement as well but nothing happens.

Here is the code -

import { createElement } from "lwc"; import helloLWC from "c/helloLWC";

it("displays greeting", () => { // Create element const element = createElement("c-hello-lwc", { is: helloLWC }); document.body.appendChild(element);

// Verify displayed greeting const div = element.shadowRoot.querySelector("div"); console.log(div.textContent); expect(div.textContent).toBe("Hello World!");

});

package.json

{ "name": "salesforce-app", "private": true, "version": "1.0.0", "description": "Salesforce App", "scripts": { "lint": "eslint /{aura,lwc}/", "test": "npm run test:unit", "test:unit": "sfdx-lwc-jest", "test:unit:watch": "sfdx-lwc-jest --watch", "test:unit:debug": "sfdx-lwc-jest --debug", "test:unit:coverage": "sfdx-lwc-jest --coverage", "prettier": "prettier --write "/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}"", "prettier:verify": "prettier --list-different "/.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}"", "postinstall": "husky install", "precommit": "lint-staged" }, "devDependencies": { "@lwc/eslint-plugin-lwc": "^1.1.2", "@prettier/plugin-xml": "^2.0.1", "@salesforce/eslint-config-lwc": "^3.2.3", "@salesforce/eslint-plugin-aura": "^2.0.0", "@salesforce/eslint-plugin-lightning": "^1.0.0", "@salesforce/sfdx-lwc-jest": "^1.2.1", "eslint": "^8.11.0", "eslint-plugin-import": "^2.25.4", "eslint-plugin-jest": "^26.1.2", "husky": "^7.0.4", "jest": "^29.3.1", "lint-staged": "^12.3.7", "prettier": "^2.6.0", "prettier-plugin-apex": "^1.10.0" }, "lint-staged": { "**/.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}": [ "prettier --write" ], "/{aura,lwc}/": [ "eslint" ] } }

dkadam77 avatar Dec 09 '22 05:12 dkadam77

Can you please share the extension trace.log file (located at ~/.console-ninja/trace.log)?

ArtemGovorov avatar Dec 10 '22 04:12 ArtemGovorov

trace.log

Please find attached trace.log.

We are not able to see any effect of Console Ninja and it says waiting for event. Jest is on watch and still it does not detect the issues in the code for failed cases.

dkadam77 avatar Dec 10 '22 11:12 dkadam77

Jest is on watch and still it does not detect the issues in the code for failed cases.

Console Ninja is not handling errors from testing frameworks, only console.logs. If you want to get realtime logs/errors/coverage feedback from your tests, please check out Wallaby.js.

ArtemGovorov avatar Dec 10 '22 12:12 ArtemGovorov

even console.log is not coming

dkadam77 avatar Dec 10 '22 12:12 dkadam77

Just noticed that you are not running Jest directly, but are using @salesforce/sfdx-lwc-jest. We have a working Jest tests sample, but maybe @salesforce/sfdx-lwc-jest works somehow differently or wraps Jest in some way that is incompatible with Console Ninja. We will investigate it and let you know the result.

ArtemGovorov avatar Dec 10 '22 12:12 ArtemGovorov

We have ran a few tests Jest is working as expected (prints logs), however @salesforce/sfdx-lwc-jest on the same test does not, likely because sfdx-lwc-jest spawns/kills Jest process before Console Ninja has a chance to report the results, but this needs more investigation.

Marking it as a feature request.

ArtemGovorov avatar Dec 12 '22 06:12 ArtemGovorov

Can you please send me the recording of the Jest working with Console ninja pls?

dkadam77 avatar Dec 12 '22 06:12 dkadam77

Also please provide support for Salesforce Apex as it is mostly debug statements for debugging the code. This would take you to altogether to differrent level for your product if Apex has incoporated in the plugin.

dkadam77 avatar Dec 12 '22 07:12 dkadam77

Can you please send me the recording of the Jest working with Console ninja pls?

Sure: cn

ArtemGovorov avatar Dec 12 '22 07:12 ArtemGovorov