runner icon indicating copy to clipboard operation
runner copied to clipboard

Improve output of Coffeescript tests

Open hobovsky opened this issue 2 years ago • 5 comments

Setup of Coffeescript suffers from a couple of problems:

  • Passed assertions spam green
  • Assertion messages emitted when assertEquals passes are awkward: Test Passed: Value == 1.
  • Docs mention it uses Codewars Tests Framework but it's not clear how. Coffeescript docs do not link to it (Javascript docs do tho). Reference of the Codewars Testing Framework appears to be missing some funcitonalities and/or details (tolerance of assertApproxEquals, range of randomNumber and randomToken).
  • It's not clear whether chai can be used. It's not listed as a supported library, but it can be used with require('chai'). But when used, feedback of passed assertions is incorrect:

image

hobovsky avatar Feb 06 '23 12:02 hobovsky

CoffeeScript is tested by creating test.coffee by concatenating preloaded, solution, and tests like the following:

require('/runner/frameworks/javascript/cw-2') # defines `Test`
assert = require('assert')
Test.handleError ->
    # preloaded
    # solution
    do ->
        Test = global.Test
        describe = global.describe
        it = global.it
        before = global.before
        after = global.after
        # tests

Then running it with coffee ./test.coffee.

It's using the custom test framework and I don't think it's been updated since https://github.com/codewars/codewars-runner-cli/blob/master/frameworks/javascript/cw-2.js

The custom test framework is no longer maintained, so to fix the issues, we'll need to add a new language version that uses Mocha and @codewars/test-compat like Node 12. I'm pretty sure the same packages can be used as is.

kazk avatar Feb 07 '23 00:02 kazk

Where do assertions come from, and where would they come from in the potential new setup? is this Node assert, or something else?

hobovsky avatar Feb 07 '23 00:02 hobovsky

assert = require('assert') from the above is importing Node's assertion.

In the new setup, old assertions can be used with Test = require('@codewars/test-compat') or chai can be used directly.

kazk avatar Feb 07 '23 00:02 kazk

The issue with the test output is related to Node v8 being used, at least for chai assertions. The same behaviour can be observed by running a JS/TS Kata that uses chai in the Node v8 runner, it produces the same highly verbose output on passed tests as the current CS runner does.

KayleighWasTaken avatar Dec 28 '23 01:12 KayleighWasTaken

No, that's because Node v8 uses the custom "Codewars test framework" just like CoffeeScript. We started using Mocha instead since Node 10.

kazk avatar Jan 03 '24 06:01 kazk