Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: avoid spread operator in reduce #15476

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,12 +756,14 @@
: [];
const projectEntry =
globMatches.length > 0 ? globMatches : project;
return [
...projects,
...(Array.isArray(projectEntry)
? projectEntry
: [projectEntry]),
];

if (Array.isArray(projectEntry)) {
for (const entry of projectEntry) projects.push(entry);

Check warning on line 761 in packages/jest-config/src/normalize.ts

View check run for this annotation

Codecov / codecov/patch

packages/jest-config/src/normalize.ts#L761

Added line #L761 was not covered by tests
} else {
projects.push(projectEntry);
}

return projects;
},
[],
);
Expand Down Expand Up @@ -1139,7 +1141,8 @@
) {
return patterns;
}
return [...patterns, filename];
patterns.push(filename);
return patterns;

Check warning on line 1145 in packages/jest-config/src/normalize.ts

View check run for this annotation

Codecov / codecov/patch

packages/jest-config/src/normalize.ts#L1144-L1145

Added lines #L1144 - L1145 were not covered by tests
}, newOptions.collectCoverageFrom);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/jest-core/src/ReporterDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export default class ReporterDispatcher {
getErrors(): Array<Error> {
return this._reporters.reduce<Array<Error>>((list, reporter) => {
const error = reporter.getLastError?.();
return error ? [...list, error] : list;
if (error) list.push(error);
return list;
}, []);
}

Expand Down
12 changes: 7 additions & 5 deletions packages/jest-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,16 @@ const groupSnapshotsBy =
snapshots.reduce<Record<string, Array<InlineSnapshot>>>(
(object, inlineSnapshot) => {
const key = createKey(inlineSnapshot);
return {
...object,
[key]: [...(object[key] || []), inlineSnapshot],
};

if (!object[key]) {
object[key] = [];
}

object[key].push(inlineSnapshot);
return object;
},
{},
);

const groupSnapshotsByFrame = groupSnapshotsBy(({frame: {line, column}}) =>
typeof line === 'number' && typeof column === 'number'
? `${line}:${column - 1}`
Expand Down
Loading