magic-akari/swc_mut_cjs_exports

Mocha version

fatso83 opened this issue · 2 comments

This module solves a problem that is recurring in many situations (and which also occurs in other bundlers). The essential changes seem to have nothing to do with Jest specifically, so would it be possible to modify the API to make it possible to using it with other test runners, like Ava or Mocha?

Typically, seeing something like this in .mocharc.json:

{
  "spec": ["src/**/*.{spec,test}.ts"],
  "require": ["@swc/register", "jest-mutable-exports"],
  "recursive": true
}

I think it should work out of the box. You can just put jest_workaround in the .swcrc configuration file.

I don't know the details about whether it can only work for mocha like jest.

For the issue you linked, there is another unsolvable issue:

@magic-akari Thanks for that! I think the plugin should be renamed to something that has nothing to do with Jest. It really should be something like "plugin-swc-mutable-exports" (or whatever the naming convention for swc is).

I got it running though! https://github.com/fatso83/sinon-swc-bug/tree/swc-with-mutable-exports

The issue you talk about is that the exports are getters. Since these getters are actually writable/configurable, I just instructed Sinon to replace the getter.