From 94dd7a59dfc19334e40446b4594578e0e7ca4409 Mon Sep 17 00:00:00 2001 From: ealush Date: Thu, 22 Apr 2021 23:20:52 +0300 Subject: [PATCH] patch: simplify produce function generation --- packages/vest/package.json | 2 +- packages/vest/src/core/produce/produce.js | 42 ++++++++--------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/packages/vest/package.json b/packages/vest/package.json index 8bda81f07..fd3797f75 100644 --- a/packages/vest/package.json +++ b/packages/vest/package.json @@ -68,4 +68,4 @@ "dependencies": { "context": "^1.1.3" } -} +} \ No newline at end of file diff --git a/packages/vest/src/core/produce/produce.js b/packages/vest/src/core/produce/produce.js index af47562fd..2441f2b41 100644 --- a/packages/vest/src/core/produce/produce.js +++ b/packages/vest/src/core/produce/produce.js @@ -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()) ) ); };