allure-js
allure-js copied to clipboard
Error: Module not found: Error: Can't resolve 'fs'
I use allure jasmine adapter in angular tests. Why command
import { readFileSync } from "fs"; in
/node_modules/allure-js-commons/dist/esm/src/current/writers/FileSystemAllureWriter.js:1:0-72
can't be executed?
i configured like in the description https://allurereport.org/docs/jasmine/
adapter in helpers/setup.ts added
import { JasmineAllureReporter } from "allure-jasmine";
import { Status, TestResult } from "allure-js-commons";
import * as os from "os";
const reporter = new JasmineAllureReporter({
resultsDir: "./allure-results",
testMapper: (result: TestResult) => {
if (result.status == Status.SKIPPED) {
result.fullName = `(WAS SKIPPED) ${result.fullName}`;
}
return result;
},
});
jasmine.getEnv().addReporter(reporter);
export const allure = reporter.getInterface();
allure.writeEnvironmentInfo({
os_platform: os.platform(),
os_release: os.release(),
os_version: os.version(),
node_version: process.version,
});
allure.writeCategoriesDefinitions([
{
name: "Sad tests",
messageRegex: /.*Sad.*/,
matchedStatuses: [Status.FAILED],
},
{
name: "Infrastructure problems",
messageRegex: ".*RuntimeException.*",
matchedStatuses: [Status.BROKEN],
},
{
name: "Outdated tests",
messageRegex: ".*FileNotFound.*",
matchedStatuses: [Status.BROKEN],
},
{
name: "Regression",
messageRegex: ".*\\sException:.*",
matchedStatuses: [Status.BROKEN],
},
]);
test:
import { SimpleService } from "./simple.service"
import { allure } from "../../helpers/setup";
let service: SimpleService;
describe('should create Simple service', () => {
beforeEach( () => {
service = new SimpleService();
});
it('should create Simple service-002', () => {
allure.description('Test1: should create Simple service');
expect(service).toBeTruthy();
});
ERROR by start: ng test
./node_modules/allure-js-commons/dist/esm/src/current/writers/FileSystemAllureWriter.js:1:0-72 - Error: Module not found: Error: Can't resolve 'fs' in '/home/mkm/projects/testapp/node_modules/allure-js-commons/dist/esm/src/current/writers'
./node_modules/allure-js-commons/dist/esm/src/current/writers/FileSystemAllureWriter.js:2:0-28 - Error: Module not found: Error: Can't resolve 'path' in '/home/mkm/projects/testapp/node_modules/allure-js-commons/dist/esm/src/current/writers'
package.json
{
"name": "testapp",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "^17.3.0",
"@angular/common": "^17.3.0",
"@angular/compiler": "^17.3.0",
"@angular/core": "^17.3.0",
"@angular/forms": "^17.3.0",
"@angular/platform-browser": "^17.3.0",
"@angular/platform-browser-dynamic": "^17.3.0",
"@angular/router": "^17.3.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.3.5",
"@angular/cli": "^17.3.5",
"@angular/compiler-cli": "^17.3.0",
"@types/jasmine": "~5.1.0",
"jasmine-core": "~5.1.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"allure-jasmine": "~2.15.1",
"typescript": "~5.4.2"
}
}
Hey!
Your tests run in a browser environment where the node standard library is not available.
I can propose you to try to follow the recommendation from the prompt you attached. Currently, I don't know how looks communication between karma and jasmine in case of angular testing and what kind of reporter we can use there.
Thx. I soled it with karma allure module how here https://github.com/allure-framework/allure-karma
@mourav2222 is there anything specific you did to get these allure-js-commons
imports working in a Karma runner? We have an Angular repo and we're facing the same issue.
@dasco144 No, i didn't solve with allure jasmine in angular 17. I sent other question in hope, somebody will help me. https://github.com/orgs/allure-framework/discussions/2575
Thanks, Mike. I'll follow that thread as well.
There must be some way to get this working, as I see the karma plugin imports from allure-js-commons
.
I see when the tests run that there is a window.allure
object, but I'm not sure it exposes all that allure-js-commons
provides.