From 810bf7f616730fa2c94f26be65a2b4d963d18625 Mon Sep 17 00:00:00 2001 From: Antony74 Date: Thu, 8 Apr 2021 19:58:28 +0100 Subject: [PATCH 1/5] Possible fix for #106 --- problems/sum/exercise.js | 6 +++--- problems/utils.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/problems/sum/exercise.js b/problems/sum/exercise.js index 1c5d958..708b615 100644 --- a/problems/sum/exercise.js +++ b/problems/sum/exercise.js @@ -5,7 +5,7 @@ const fs = require('fs') const path = require('path') const async = require('async') const _ = require('lodash') -const {getRandomInt} = require('../utils') +const {getRandomInt, pickStaticProps} = require('../utils') let exercise = require('workshopper-exercise')() // cleanup for both run and verify @@ -46,11 +46,11 @@ exercise.addProcessor(function (mode, callback) { cb() } ], (err, results) => { - submissionResult = results[0] + submissionResult = pickStaticProps(results[0]) if (mode === 'run') { console.log(`Execution with left: ${a}, right: ${b} returned: ${JSON.stringify(submissionResult)}`) } else { - solutionResult = results[1] + solutionResult = pickStaticProps(results[1]) if (!_.isEqual(solutionResult, submissionResult)) { exercise.emit('fail', `Expected result: ${JSON.stringify(solutionResult)}` + `, Actual result: ${JSON.stringify(submissionResult)}`) diff --git a/problems/utils.js b/problems/utils.js index d3dabd8..f753f9b 100644 --- a/problems/utils.js +++ b/problems/utils.js @@ -1,5 +1,7 @@ 'use strict' +const _ = require('lodash') + exports.getRandomInt = (min = 0, max = 100) => { min = Math.ceil(min) max = Math.floor(max) @@ -12,3 +14,13 @@ exports.getRandomFloat = (min = 0, max = 100) => { const num = Math.floor(Math.random() * (max - min)) + min return Math.round(num * 10) / 100 } + +exports.pickStaticProps = (result) => { + const staticProps = [ + 'pattern', 'action', 'tag', 'seneca', 'version', 'timeout', 'custon', 'plugin', 'parents', + 'remote', 'sync', 'trace', 'sub', 'data', 'err', 'err_trace', 'error', 'empty' + ] + result[1] = _.pick(result[1], staticProps) + return result +} + From ddf6aa2e3a450047e6967235faf961a5b986d5e9 Mon Sep 17 00:00:00 2001 From: Antony74 Date: Thu, 8 Apr 2021 21:33:21 +0100 Subject: [PATCH 2/5] Implement pickStaticProps with less potential for suprise --- problems/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/problems/utils.js b/problems/utils.js index f753f9b..187c3ad 100644 --- a/problems/utils.js +++ b/problems/utils.js @@ -20,7 +20,7 @@ exports.pickStaticProps = (result) => { 'pattern', 'action', 'tag', 'seneca', 'version', 'timeout', 'custon', 'plugin', 'parents', 'remote', 'sync', 'trace', 'sub', 'data', 'err', 'err_trace', 'error', 'empty' ] - result[1] = _.pick(result[1], staticProps) - return result + + return [result[0], _.pick(result[1], staticProps)] } From eb1acebdf5cf6765a6527cb2415f2daff4a9f1f3 Mon Sep 17 00:00:00 2001 From: Antony74 Date: Sat, 10 Apr 2021 12:12:46 +0100 Subject: [PATCH 3/5] Deal with unexpect results --- problems/utils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/problems/utils.js b/problems/utils.js index 187c3ad..fa28537 100644 --- a/problems/utils.js +++ b/problems/utils.js @@ -21,6 +21,10 @@ exports.pickStaticProps = (result) => { 'remote', 'sync', 'trace', 'sub', 'data', 'err', 'err_trace', 'error', 'empty' ] - return [result[0], _.pick(result[1], staticProps)] + if (result && result.length >= 2) { + return [result[0], _.pick(result[1], staticProps)] + } else { + return result + } } From 365b34e8cac5975b0154d9019bd8c1c0e6340a76 Mon Sep 17 00:00:00 2001 From: Antony74 Date: Sat, 10 Apr 2021 21:56:58 +0100 Subject: [PATCH 4/5] Fix the 'roles' exercise --- problems/roles/exercise.js | 6 +++--- problems/utils.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/problems/roles/exercise.js b/problems/roles/exercise.js index 649e7a1..3acfe30 100644 --- a/problems/roles/exercise.js +++ b/problems/roles/exercise.js @@ -5,7 +5,7 @@ const fs = require('fs') const path = require('path') const async = require('async') const _ = require('lodash') -const {getRandomInt} = require('../utils') +const {getRandomInt, pickStaticProps} = require('../utils') let exercise = require('workshopper-exercise')() // cleanup for both run and verify @@ -47,11 +47,11 @@ exercise.addProcessor(function (mode, callback) { cb() } ], (err, results) => { - submissionResult = results[0] + submissionResult = pickStaticProps(results[0]) if (mode === 'run') { console.log(`Execution with left: ${a}, right: ${b} returned: ${JSON.stringify(submissionResult)}`) } else { - solutionResult = results[1] + solutionResult = pickStaticProps(results[1]) if (!_.isEqual(solutionResult, submissionResult)) { exercise.emit('fail', `Expected result: ${JSON.stringify(solutionResult)}` + `, Actual result: ${JSON.stringify(submissionResult)}`) diff --git a/problems/utils.js b/problems/utils.js index fa28537..15b35a1 100644 --- a/problems/utils.js +++ b/problems/utils.js @@ -17,7 +17,7 @@ exports.getRandomFloat = (min = 0, max = 100) => { exports.pickStaticProps = (result) => { const staticProps = [ - 'pattern', 'action', 'tag', 'seneca', 'version', 'timeout', 'custon', 'plugin', 'parents', + 'pattern', 'tag', 'seneca', 'version', 'timeout', 'custon', 'parents', 'remote', 'sync', 'trace', 'sub', 'data', 'err', 'err_trace', 'error', 'empty' ] From 68902794c929dbf1c564342b6f1409a6c987d0bf Mon Sep 17 00:00:00 2001 From: Antony74 Date: Mon, 12 Apr 2021 17:23:03 +0100 Subject: [PATCH 5/5] Fix for 'extend' exercise --- problems/extend/exercise.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/extend/exercise.js b/problems/extend/exercise.js index a7cd878..c1209d4 100644 --- a/problems/extend/exercise.js +++ b/problems/extend/exercise.js @@ -5,7 +5,7 @@ const fs = require('fs') const path = require('path') const async = require('async') const _ = require('lodash') -const {getRandomFloat} = require('../utils') +const {getRandomFloat, pickStaticProps} = require('../utils') let exercise = require('workshopper-exercise')() // cleanup for both run and verify @@ -47,11 +47,11 @@ exercise.addProcessor(function (mode, callback) { cb() } ], (err, results) => { - submissionResult = results[0] + submissionResult = pickStaticProps(results[0]) if (mode === 'run') { console.log(`Execution with left: ${a}, right: ${b} returned: ${JSON.stringify(submissionResult)}`) } else { - solutionResult = results[1] + solutionResult = pickStaticProps(results[1]) if (!_.isEqual(solutionResult, submissionResult)) { exercise.emit('fail', `Expected result: ${JSON.stringify(solutionResult)}` + `, Actual result: ${JSON.stringify(submissionResult)}`)