jhnns / rewire

Easy monkey-patching for node.js unit tests
MIT License
3.08k stars 128 forks source link

Rewire does not seem to work with flow #186

Closed darthzeran closed 2 years ago

darthzeran commented 3 years ago

I inherited some code, and when I ran the test, it failed when rewiring my application.

When the rewire rewires my file, it says

/MockedFile.js:5
key: string,
    ^
SyntaxError: Unexpected token :
1 | const rewire = require('rewire')
2 |
3 | const MockedFile= rewire('./MockedFile')
                        ^                       

It seems to be failing on the : for flow. Is this a case to use babel-plugin-rewire? Or is there another way around it?

jhnns commented 2 years ago

I'm sorry, loading anything other than JavaScript is out of scope of this project. You could either use babel + babel-plugin-rewire or transform your files to plain JS before running your tests.