Skip to content

Commit

Permalink
patch: simplify produce function generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed May 11, 2021
1 parent 09b2aa4 commit 94dd7a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/vest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@
"dependencies": {
"context": "^1.1.3"
}
}
}
42 changes: 15 additions & 27 deletions packages/vest/src/core/produce/produce.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,21 @@ const produce = isDraft => {
return cache(
[testObjects, isDraft],
context.bind(ctxRef, () =>
Object.defineProperties(
genTestsSummary(),
[
[HAS_ERRORS, hasFaillures, SEVERITY_GROUP_ERROR],
[HAS_WARNINGS, hasFaillures, SEVERITY_GROUP_WARN],
['getErrors', getFailures, SEVERITY_GROUP_ERROR],
['getWarnings', getFailures, SEVERITY_GROUP_WARN],
['hasErrorsByGroup', hasFailuresByGroup, SEVERITY_GROUP_ERROR],
['hasWarningsByGroup', hasFailuresByGroup, SEVERITY_GROUP_WARN],
['getErrorsByGroup', getFailuresByGroup, SEVERITY_GROUP_ERROR],
['getWarningsByGroup', getFailuresByGroup, SEVERITY_GROUP_WARN],
]
.concat(isDraft ? [] : [['done', done]])
.reduce(
(properties, [name, fn, severityKey]) => (
(properties[name] = {
configurable: true,
enumerable: true,
name,
value: context.bind(ctxRef, fn, severityKey),
writeable: true,
}),
properties
),
{}
)
)
[
[HAS_ERRORS, hasFaillures, SEVERITY_GROUP_ERROR],
[HAS_WARNINGS, hasFaillures, SEVERITY_GROUP_WARN],
['getErrors', getFailures, SEVERITY_GROUP_ERROR],
['getWarnings', getFailures, SEVERITY_GROUP_WARN],
['hasErrorsByGroup', hasFailuresByGroup, SEVERITY_GROUP_ERROR],
['hasWarningsByGroup', hasFailuresByGroup, SEVERITY_GROUP_WARN],
['getErrorsByGroup', getFailuresByGroup, SEVERITY_GROUP_ERROR],
['getWarningsByGroup', getFailuresByGroup, SEVERITY_GROUP_WARN],
]
.concat(isDraft ? [] : [['done', done]])
.reduce((properties, [name, fn, severityKey]) => {
properties[name] = context.bind(ctxRef, fn, severityKey);
return properties;
}, genTestsSummary())
)
);
};
Expand Down

0 comments on commit 94dd7a5

Please sign in to comment.