main
main copied to clipboard
Cannot find collections file in /mocks folder when files.options.only is used in mocks.config.js
Describe the bug
When setting up typescript project and following the docs, the collections
file inside of mocks
folder stops working the moment I enable files.options.only
in mocks.config.js
To Reproduce
- Clone this repo: https://github.com/jacobdo2/mocks-server-ts-example
- Run
yarn
to install deps - Run
yarn mocks
to start
Expected behavior It should compile and run the project
Logs Error loading file /Users/myName/Projects/mocks-test/mocks/collections.ts: .only must be an array, or undefined Error: .only must be an array, or undefined
Hi @jacobdo2,
It seems to be related to your Babel version. As described in this issue, since a determined version Babel only supports an array as value for the only
option. So, if you want to use a function you can define an array with a function as unique element:
{
files: {
babelRegister: {
enabled: true,
options: {
only: [(filePath) => {
return filePath.includes("/mocks/") || filePath.includes("/fixtures/");
}],
},
},
},
}
Note: I have tested the change in your repository and it works.
Thanks for the notice, even when it is not related to this project, it would be good to mention it in the guide about how to configure TypeScript. I'll open another issue for that.