hbenl / vscode-jasmine-test-adapter

Jasmine Test Adapter for the VS Code Test Explorer
MIT License
20 stars 20 forks source link

[Solved] Cannot use import statement outside a module #51

Closed jobwat closed 2 years ago

jobwat commented 2 years ago

This is a typescript related issue.

The extension was failing on a new generated typescript project:

Jasmine Tests output:

(node:75786) UnhandledPromiseRejectionWarning: /private/tmp/test/spec/tests/users.spec.ts:1
import supertest from 'supertest';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:988:16)
    at Module._compile (internal/modules/cjs/loader.js:1036:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Loader.requireShim [as require_] (/Users/yourmum/.vscode/extensions/hbenl.vscode-jasmine-test-adapter-1.7.1/node_modules/jasmine/lib/loader.js:35:3)
    at /Users/yourmum/.vscode/extensions/hbenl.vscode-jasmine-test-adapter-1.7.1/node_modules/jasmine/lib/loader.js:28:12
    at new Promise (<anonymous>)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:75786) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:75786) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The fix has been found in another issue related to typescript:

Ensure ts-node and tsconfig-paths packages are installed and add this config to the settings.json of VScode

"jasmineExplorer.nodeArgv": [
        "--require",
        "ts-node/register",
        "--require",
        "tsconfig-paths/register"
    ],

Hope this helps the next one

$ node --version
v14.17.6