bloodyowl / rescript-test

A lightweight test framework for ReScript
https://bloodyowl.github.io/rescript-test/
MIT License
78 stars 9 forks source link

Can i execute retest as npm script? #2

Closed koji-k closed 3 years ago

koji-k commented 3 years ago

I created following sample unit test files.

[koji:hello_rescript]$ tree tests 
tests
├── MyTest.res
├── test_a
│   └── TestA.res
└── test_b
    ├── TestB.res
    └── test_b2
        └── TestB2.res

and my scripts on package.json

  "scripts": {
    "clean": "bsb -clean-world",
    "build": "bsb -make-world",
    "watch": "bsb -make-world -w",
    "test": "node_modules/rescript-test/bin/retest tests/**/*.bs.js"
  },

It will be executed tests on tests/*.bs.js only. so, sub directories are ignored.

[koji:hello_rescript]$ npm test

> hello_rescript@0.1.0 test /home/koji/code/rescript/hello_rescript
> node_modules/rescript-test/bin/retest tests/**/*.bs.js

1/2: TestA
  PASS - a
  PASS - a2
2/2: TestB
  PASS - a
  PASS - a2

# Ran 2 tests (4 assertions)
# 2 passed
# 0 failed
[koji:hello_rescript]$ 

But, when i execute retest directlly, all tests in sub directories executed.(I expect this behavior)

[koji:hello_rescript]$ node_modules/rescript-test/bin/retest tests/**/*.bs.js
1/4: MyTest
  PASS - a
2/4: TestA
  PASS - a
  PASS - a2
3/4: TestB
  PASS - a
  PASS - a2
4/4: TestB2
  PASS - a
  PASS - a2

# Ran 4 tests (7 assertions)
# 4 passed
# 0 failed
[koji:hello_rescript]$ 

This behavior is not clear to me... Is this because retest or npm ...?

bloodyowl commented 3 years ago

That seems odd, what's your node/npm versions?

bloodyowl commented 3 years ago

Looking into it, seems like it's expanded differently in the script and in the console, especially regarding arbitrary depth.

A workaround is to make sure the glob is compatible with both: retest tests/*.bs.js tests/**/*.bs.js (the files will naturally be deduplicated)

koji-k commented 3 years ago

Thank you! That workaround works fine. (I wrote tests/*.bs.js tests/*/*.bs.js tests/*/*/*.bs.js. then all tests that is on my structure was executed.)