Performing a destructuring assignment on global variables anywhere in an ES6 module results in the following error being thrown when running a Jest test configured with the '--experimental-vm-modules' CLI option in VSCode:
● Test suite failed to run
SyntaxError: Invalid destructuring assignment target at Runtime.loadEsmModule (node_modules/jest-runtime/build/index.js:551:22)
Adding the following line after initial declaration, or within function scope results in the error.
[globalOne, globalTwo] = ["", ""];
The code executes without issue in the browser (Chrome/Safari/Firefox).
Separately, are there any Node or Jest CLI configs that would help trace line numbers that throw this type of parsing error? Tracking down the culprit was a bit too manual.
Edit:
example_module.js
var globalOne, globalTwo;
[globalOne, globalTwo] = ["", ""];
example_module.test.js
import * as example_module from './example_module.js';
Visual Studio Code | .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Example",
"type": "node",
"cwd": "${workspaceRoot}/PROJECT/",
"request": "launch",
"runtimeArgs": [
"--experimental-vm-modules",
"--inspect-brk",
"${workspaceRoot}/PROJECT/node_modules/.bin/jest",
"--runInBand",
"--testPathPattern",
"example_module.test.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
}
]
}
Both example_module.js and example_module.test.js in '${workspaceRoot}/PROJECT/'