Workaround for the issue with chai v5 and ES modules
I couldn't make it work with the Babel loader. There is a possible solution using ts-node as a loader. I didn't want to install another package, so I chose a different workaround. mocha-env.mjs is processed as a module thanks to the suffix, and it sets chai. expect globally, and then I updated tests to use the global expect. Please see https://github.com/chaijs/chai/issues/1568 [MAILPOET-6008]
This commit is contained in:
committed by
Veljko V
parent
73434e1ef7
commit
1d32461b3d
9
mailpoet/tests/javascript/mocha-env.mjs
Normal file
9
mailpoet/tests/javascript/mocha-env.mjs
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as chai from 'chai';
|
||||
import register from '@babel/register';
|
||||
|
||||
// Register Babel to transpile our tests
|
||||
register({ extensions: ['.js', '.jsx', '.ts', '.tsx'] });
|
||||
|
||||
// Set up chai.expect globally due issues with ES modules
|
||||
// See https://github.com/chaijs/chai/issues/1568
|
||||
global.expect = chai.expect;
|
Reference in New Issue
Block a user