From e9b84fada3cfb10c57f991c149f6e622b36bba75 Mon Sep 17 00:00:00 2001 From: Linus Thiel Date: Tue, 13 Dec 2022 23:59:55 +0100 Subject: [PATCH] Proof of Concept: Test one function using testy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is just a PoC to show the feasability of doctest:ing the JSDoc @examples instead of / in addition to other tests. Because of require/import discrepancies, the test scaffolding needs some import shenanigans. Apart from that, the rounding needs to be handled somewhat differently. This could be solved in other ways, if given a feature request to testy: - One could imagine the option to inject different expect-logic in the test suite (make expect behave more fuzzy). - Or, the option of injecting a helper function to use in @examples. - ... or other options. In anticipation of a more thorough effort, though, it seems pertinent to update and modernize the project first, though. Nice library! 🙌 --- lib/diff.js | 12 ++++++++++++ package.json | 5 +++-- test/doctests.js | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/doctests.js diff --git a/lib/diff.js b/lib/diff.js index 92428b5..7cf065d 100644 --- a/lib/diff.js +++ b/lib/diff.js @@ -52,6 +52,18 @@ var PI = Math.PI; * @param {labcolor} c1 Should have fields L,a,b * @param {labcolor} c2 Should have fields L,a,b * @return {float} Difference between c1 and c2 +* @example +* // It uses the true chroma difference (#1) +* ciede2000({ +* L: 50.0000, +* a: 2.6772, +* b: -79.7751 +* }, { +* L: 50.0000, +* a: 0.0000, +* b: -82.7485 +* }).toFixed(4) +* //=> "2.0425" */ function ciede2000(c1,c2) { diff --git a/package.json b/package.json index e64d15c..ccb99df 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,10 @@ "url": "https://github.com/markusn/color-diff/issues" }, "devDependencies": { + "@linus/testy": "^1.1.0", "assert": "~1.4.1", - "mocha": "~5.0.4", "coveralls": "~3.0.0", - "istanbul": "~0.4.5" + "istanbul": "~0.4.5", + "mocha": "~5.0.4" } } diff --git a/test/doctests.js b/test/doctests.js new file mode 100644 index 0000000..ec388d2 --- /dev/null +++ b/test/doctests.js @@ -0,0 +1,5 @@ +import('@linus/testy').then(({ testy }) => { + describe('Test', () => { + testy('lib/diff.js'); + }); +});