console-ninja
console-ninja copied to clipboard
Support @salesforce/sfdx-lwc-jest
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" ] } }
Can you please share the extension trace.log file (located at ~/.console-ninja/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.
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.
even console.log is not coming
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.
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.
Can you please send me the recording of the Jest working with Console ninja pls?
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.
Can you please send me the recording of the Jest working with Console ninja pls?
Sure:
