From 74a590a3e40e1052f7940611b93f4d44a89fcb98 Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Mon, 19 Dec 2022 17:40:25 +0200 Subject: [PATCH] perf: improve bundle size --- package.json | 4 ++-- src/context/TestRunContext.ts | 5 ++--- src/selectors/testCase.ts | 7 +++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 5dbdb74..4fc2d3a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jest-allure2-reporter", "version": "1.0.0", - "description": "TODO: describe reporter", + "description": "Idiomatic Jest reporter for Allure Framework", "license": "MIT", "keywords": [ "allure", @@ -73,6 +73,7 @@ "jest": "^28.1.1", "jest-environment-node": "^28.1.2", "lint-staged": "^13.0.3", + "lodash": "^4.17.21", "prettier": "^2.7.1", "semantic-release": "^19.0.3", "tempfile": "^3.0.0", @@ -84,7 +85,6 @@ }, "dependencies": { "allure-js-commons": "^2.0.0-beta.19", - "lodash": "^4.17.21", "pkg-up": "^3.1.0", "rimraf": "^3.0.2", "strip-ansi": "^6.0.0" diff --git a/src/context/TestRunContext.ts b/src/context/TestRunContext.ts index bdbb39f..28f8b8f 100644 --- a/src/context/TestRunContext.ts +++ b/src/context/TestRunContext.ts @@ -1,6 +1,5 @@ import path from 'path'; -import { mapValues } from 'lodash'; // eslint-disable-next-line node/no-unpublished-import import type { Test, TestResult } from '@jest/reporters'; @@ -27,11 +26,11 @@ export default class TestRunContext { runtime.writeCategoriesDefinitions([]); } - async _getEnvironmentInfo() { + async _getEnvironmentInfo(): Promise { const { getEnvironmentInfo } = this._config; if (typeof getEnvironmentInfo === 'boolean') { - return getEnvironmentInfo ? mapValues(process.env, String) : {}; + return getEnvironmentInfo ? process.env : {}; } return getEnvironmentInfo(); diff --git a/src/selectors/testCase.ts b/src/selectors/testCase.ts index 98ae85d..39032f6 100644 --- a/src/selectors/testCase.ts +++ b/src/selectors/testCase.ts @@ -1,7 +1,6 @@ import path from 'path'; import { Status } from 'allure-js-commons'; -import { isEmpty } from 'lodash'; import stripAnsi from 'strip-ansi'; // eslint-disable-next-line node/no-unpublished-import import type { TestCaseResult } from '@jest/reporters'; @@ -17,6 +16,9 @@ import type { TimeService, } from './fallbacks'; +const isEmptyObject = (value: unknown) => + value && typeof value === 'object' && Object.keys(value).length === 0; + type Services = { reporterOptions: Partial; meta: MetadataService; @@ -100,7 +102,8 @@ export class TestCaseSelectors { if (this._services.reporterOptions.errorsAsFailedAssertions) { return Status.FAILED; } else { - const hasUnhandledErrors = testCaseResult.failureDetails.some((item) => isEmpty(item)); + // eslint-disable-next-line unicorn/no-array-callback-reference + const hasUnhandledErrors = testCaseResult.failureDetails.some(isEmptyObject); return hasUnhandledErrors ? Status.BROKEN : Status.FAILED; } case 'pending':