I'm currently facing an issue while trying to debug a mocha test. Despite my efforts in searching on Google and Stack Overflow, I have not been able to find a solution.
The error message is as follows:
TSError: ⨯ Unable to compile TypeScript:
source-map-support.js:444 error TS2468: Cannot find global value 'Promise'.backend/test/textToSpeech/lib.ts(11,30): error TS2705: An async
function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.backend/test/textToSpeech/lib.ts(12,27): error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.
This is how the tsconfig.json file is configured:
{
"compilerOptions": {
"module": "commonjs",
"watch": true,
"noImplicitAny": false,
"removeComments": true,
"outDir": "./dist",
"sourceMap": true,
"target": "es6",
"lib": [
"ES2015"
],
"types": [
"node",
"pg-promise"
],
"typeRoots": [
"node_modules/@types"
]
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
As for the vscode launch.json configuration:
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/backend/node_modules/mocha/bin/_mocha",
"args": [
"--require", "ts-node/register",
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/backend/test/textToSpeech/lib.ts"
],
"internalConsoleOptions": "openOnSessionStart"
}
The contents of the test file are as follows:
import {} from 'mocha'
import { expect } from 'chai'
import config from '../configuration'
import { TextToSpeechLib } from '../../src/libs/textToSpeech/'
var textToSpeach = new TextToSpeechLib(config)
var text = 'Hello world'
describe('TextToSpeach lib', async () => {
it ('Convert text ...', async () => {
console.log("==== =a= =s= a==")
let resp = await textToSpeach.convertText(text);
expect(resp.status).to.be.equal('success')
})
})
I've tried various solutions but it seems like the launcher is not loading the tsconfig. I even attempted to pass "--lib","'ES2015'" as an argument in the launcher configuration. Any help would be greatly appreciated. Thank you.