devcards icon indicating copy to clipboard operation
devcards copied to clipboard

Run test fixtures

Open pieter-van-prooijen opened this issue 10 years ago • 4 comments

Hello Bruce,

When running tests in a devcard it the fixtures associated with that test are not executed. This PR changes that by running the tests using the var created by deftest and using the deftest fixture machinery in cljs.test/test-vars-block. It differs from a normal clsj.test run in the following ways:

  • Fixtures are retrieved at runtime, not compile time as in cljs.test. This might break when using advanced optimisations in the closure compiler
  • Because each var is tested separately, the :once fixtures are run for each var, not for each test namespace. This might create extra overhead when running tests.
  • Instead of a list of test thunks, each test run consists of a test var and an optional test docstring. I've renamed the relevant function args to reflect this.

Kind regards,

Pieter van Prooijen

pieter-van-prooijen avatar Dec 15 '15 19:12 pieter-van-prooijen

This is interesting.

I'm going to look at this some more. However right off the bat all devcard code needs to work in advanced compilation. This is a Devcards requirement so that folks can deploy reference material and examples to the web. This also allows folks to see if their tests still run in different compilation modes.

We could say that well only fixtures don't work in advanced compilation but ... slippery slope eh?

bhauman avatar Dec 23 '15 22:12 bhauman

Hello Bruce,

I've incorporated the use-fixtures macro into devcards so it marks the fixture symbols as exportable and they don't get munged by the Closure compiler. Seems to work, I can now run the fixtures in advanced compilation mode.

pieter-van-prooijen avatar Dec 27 '15 11:12 pieter-van-prooijen

So, I've been looking at this and I have found some errors. Please refer to the devdemos.testing ns. See how it functions before your commits and then after.

The timeout doesn't seem to fire. The mid-test documentation isn't getting output.

Thank you for working on this but another approach may be required.... Still looking at it.

bhauman avatar Dec 31 '15 00:12 bhauman

Hi Bruce,

The timeout in devdemos.testing doesn't fire because an async block should always be the last expression in a deftest, due to the way cljs.test detects and schedules async tests. The test now works because devcards runs each form in a deftest individually, not as a whole as cljs.test does it. In my branch of devdemos.testing, I've moved the async block to the end of deftest and that seems to do the trick. I've also re-added the dc/tests macro, so the last devcard on that page also works.

I'm afraid I don't have a solution for rendering the test doc strings in the middle of a deftest, (other than using the "testing" macro), bcause deftest doesn't support this.

pieter-van-prooijen avatar Jan 02 '16 11:01 pieter-van-prooijen