Fork me on GitHub
#react
<
2021-10-10
>
pesterhazy16:10:08

IMO the future of testing CLJS frontend apps is Jest I've build a proof-of-concept todomvc app using TDD here. Rationale in the README: https://github.com/pesterhazy/shadow-jest — feedback welcome!

Lucy Wang01:10:19

Nice try! Actually there is another similar effort in the community, but with mocha instead of with jest https://www.reddit.com/r/Clojure/comments/px001o/using_mocha_to_test_clojurescript/ .

👀 1
Lucy Wang01:10:29

I think your way of compiling to "npm-module" target is better than compiling into "node-script" target.

Lucy Wang05:10:18

@U06F82LES I just played your demo repo and it works pretty well. But when I adopts it to one of my real world projects, it became extremely slow. By bisecting the deps it looks like sci and malli is the culprit.

pesterhazy06:10:33

Is the compile step slow or the run in jest? How long does a run take?

Lucy Wang06:10:06

Compile is fast. Jest run could take a minute and sometimes node process died of OOM

pesterhazy07:10:18

Oh wow, there must be something funny going on there

Lucy Wang12:10:57

@U06F82LES this is fixed by adding transform: {} to jest.config.js. By default jest would transform .js files with babel so that could be the problem https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object

pesterhazy18:10:07

$ npx jest --no-cache
 PASS  dist-test/todomvc.app_spec.js
  ✓ initial screen (123 ms)
  ✓ add todo (27 ms)
  ✓ can't create empty todo (15 ms)
  ✓ remove todo (18 ms)
  ✓ complete todo (21 ms)
  ✓ select filter (38 ms)
  ✓ toggle all (20 ms)
  ✓ edit todo (36 ms)

Test Suites: 1 passed, 1 total
Tests:       8 passed, 8 total
Snapshots:   0 total
Time:        1.749 s
Ran all test suites.
$ npx jest --no-cache
 PASS  dist-test/todomvc.app_spec.js (9.206 s)
  ✓ initial screen (135 ms)
  ✓ add todo (39 ms)
  ✓ can't create empty todo (17 ms)
  ✓ remove todo (19 ms)
  ✓ complete todo (24 ms)
  ✓ select filter (35 ms)
  ✓ toggle all (20 ms)
  ✓ edit todo (40 ms)

Test Suites: 1 passed, 1 total
Tests:       8 passed, 8 total
Snapshots:   0 total
Time:        9.72 s
Ran all test suites.

pesterhazy18:10:39

first run with transformer: {} -> 1.7s

pesterhazy18:10:56

second run with transform: undefined (defaulting to babel) -> 9.7s

bananadance 1
pesterhazy18:10:14

great find, thanks @UP90Q48J3