As far as I can see, testing with Jest or any other test framework is impossible when using Vue, native modules, and Electron running as Node. Electron needs to be run as Node to allow native modules to work, since they have been compiled against a particular version of Electron, and this means a version that is different from any Node version.
But if you call the test via the 'scripts' section of package.json using this:
vue-cli-service test:unit
The error is like:
The module ...\Release\XXXXXXX' was compiled against a different
Node.js version using NODE_MODULE_VERSION 70.
This version of Node.js requires NODE_MODULE_VERSION 72.
The fundamental issue is the that vue-cli-service
doesn't allow you to make it run via Electron.
If you attempt to run in a way that uses Electron (running as Node):, such as:
cross-env ELECTRON_RUN_AS_NODE=true
./node_modules/.bin/electron
./node_modules/@vue/cli-service/bin/vue-cli-service.js test:unit
Then the native module is fine, but the vue-cli-service totally fails to understand what Vue is, showing this error:
TypeError: Cannot read property 'extend' of undefined
> 36 | export default Vue.extend({
| ^
Sadly, the same problem occurs if you run this using Jest and Electron. Anything with the native module is fine. However, tests that touch Vue don't work.
Mocking the native module doesn't work since that bypasses the exports of the module, but it is still 'run' in some way and causes an error. And I can't mock Vue, because I want to test my code...
I'd be happy to get any Jest or Mocha or Vue CLI or any solution working!
Aucun commentaire:
Enregistrer un commentaire