Can't access module from test file

So if I have src/Demo.res and test/Demo.test.res everything is fine if I don’t need to access Demo.res. But if I need to access a function in Demo.res in the test, Demo.test.res won’t compile and I get a module or file can’t be found error.

To make things more interesting, if I add “namespace”: true to rescript.json then Demo.test.res compiles and everything works. So why doesn’t it work if namespace is not set? The files in the lib folder end up being Demo-MyApp.xxx and Demo.test-Myapp.xxx. Why does setting namespace to true make everything okay?

I remember I was trying to fix the issue a while ago, but I wasn’t familiar with the compiler good enough back then, so I failed. I want to try again at some point.

I personally worked around the issue by using underscore instead of dot like this: Demo_test.res

That’s an interesting point, I didn’t know about it.

Changing to _test definitely works. Initially I thought it wouldn’t work with Bun Test runner, but turns out there must be a typo in their error message that said the file name had to have “_test_” in the filename, but I checked the documentation and it says the test runner looks for “_test” and not “_test_”.

So I guess the options are “_test” without the namespace option or “.test” with namespace set to true in rescript.json.

1 Like