Skip to content

Commit

Permalink
fix: incorrect lodash imports
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Dec 19, 2022
1 parent 74a590a commit ce0f961
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/context/TestFileContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
// eslint-disable-next-line node/no-unpublished-import
} from '@jest/reporters';
import { AllureGroup, LabelName, Stage, Status } from 'allure-js-commons';
import isEqual from 'lodash/isEqual';

import shallowEqualArrays from '../utils/shallowEqualArrays';

import { TestFileContextConfig } from './TestFileContextConfig';

Expand All @@ -22,7 +23,7 @@ export default class TestFileContext {
}

handleTestCaseResult(testCaseResult: TestCaseResult) {
if (!isEqual(this._ancestorTitles, testCaseResult.ancestorTitles)) {
if (!shallowEqualArrays(this._ancestorTitles, testCaseResult.ancestorTitles)) {
this._changeSubsuiteGroup(testCaseResult);
}

Expand Down
5 changes: 3 additions & 2 deletions src/selectors/fallbacks/ProjectService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import path from 'path';

import attempt from 'lodash/attempt';
import isError from 'lodash/isError';
import pkgUp from 'pkg-up';

import attempt from '../../utils/attempt';
import isError from '../../utils/isError';

type Config = {
rootDir: string;
packageName?: string;
Expand Down
4 changes: 1 addition & 3 deletions src/selectors/testCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import stripAnsi from 'strip-ansi';
import type { TestCaseResult } from '@jest/reporters';

import type { JestAllure2ReporterOptions } from '../JestAllure2ReporterOptions';
import isEmptyObject from '../utils/isEmptyObject';
import md5 from '../utils/md5';

import type {
Expand All @@ -16,9 +17,6 @@ import type {
TimeService,
} from './fallbacks';

const isEmptyObject = (value: unknown) =>
value && typeof value === 'object' && Object.keys(value).length === 0;

type Services = {
reporterOptions: Partial<JestAllure2ReporterOptions>;
meta: MetadataService;
Expand Down
7 changes: 7 additions & 0 deletions src/utils/attempt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function attempt<T>(function_: () => T): T | Error {
try {
return function_();
} catch (error) {
return error;
}
}
3 changes: 3 additions & 0 deletions src/utils/isEmptyObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function isEmptyObject(value: unknown) {
return value && typeof value === 'object' && Object.keys(value).length === 0;
}
3 changes: 3 additions & 0 deletions src/utils/isError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function isError(error: unknown): error is Error {
return error instanceof Error;
}
24 changes: 24 additions & 0 deletions src/utils/shallowEqualArrays.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable unicorn/no-null */

type Maybe<T> = T | null | undefined;

export default function shallowEqualArrays(a: Maybe<unknown[]>, b: Maybe<unknown[]>) {
if (a === b) {
return true;
}

if (a == null || b == null) {
return false;
}

if (a.length !== b.length) {
return false;
}

// eslint-disable-next-line unicorn/no-array-callback-reference,unicorn/no-array-method-this-argument
return a.every(isItemEqual, b);
}

function isItemEqual(this: unknown[], value: unknown, index: number) {
return value === this[index];
}

0 comments on commit ce0f961

Please sign in to comment.