由于“未知的\“报告者\”,Mocha无法在WSL的WebStorm中工作

时间:2019-11-14 23:40:27

标签: node.js typescript mocha webstorm windows-subsystem-for-linux

在WebSstorm中运行的Mocha指向WSL环境时,我得到:

C:\Users\iursino\AppData\Local\Microsoft\WindowsApps\ubuntu.exe run "export PATH=/home/iursino/n/bin:$PATH && /home/iursino/n/bin/node --inspect-brk=49953 /mnt/c/workspace/redacted-project-name/node_modules/mocha/bin/_mocha --timeout 0 --ui bdd --reporter \"/mnt/c/Program Files/JetBrains/WebStorm 2019.2.4/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js\" /mnt/c/workspace/redacted-project-name/src/Filename.spec.ts --grep \"^invoke lambda Expect error if lambda returns an error$\""
Debugger listening on ws://127.0.0.1:49953/f31007fa-106c-4847-94cf-3e7d98d72e71
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
mocha debug [spec..]

Run tests with Mocha

Rules & Behavior
  --allow-uncaught           Allow uncaught errors to propagate        [boolean]
  --async-only, -A           Require all tests to use a callback (async) or
                             return a Promise                          [boolean]
  --bail, -b                 Abort ("bail") after first test failure   [boolean]
  --check-leaks              Check for global variable leaks           [boolean]
  --delay                    Delay initial execution of root suite     [boolean]
  --exit                     Force Mocha to quit after tests complete  [boolean]
  --forbid-only              Fail if exclusive test(s) encountered     [boolean]
  --forbid-pending           Fail if pending test(s) encountered       [boolean]
  --global, --globals        List of allowed global variables            [array]
  --retries                  Retry failed tests this many times         [number]
  --slow, -s                 Specify "slow" test threshold (in milliseconds)
                                                          [number] [default: 75]
  --timeout, -t, --timeouts  Specify test timeout threshold (in milliseconds)
                                                        [number] [default: 2000]
  --ui, -u                   Specify user interface    [string] [default: "bdd"]

Reporting & Output
  --color, -c, --colors                     Force-enable color output  [boolean]
  --diff                                    Show diff on failure
                                                       [boolean] [default: true]
  --full-trace                              Display full stack traces  [boolean]
  --growl, -G                               Enable Growl notifications [boolean]
  --inline-diffs                            Display actual/expected differences
                                            inline within each string  [boolean]
  --reporter, -R                            Specify reporter to use
                                                      [string] [default: "spec"]
  --reporter-option, --reporter-options,    Reporter-specific options
  -O                                        (<k=v,[k1=v1,..]>)           [array]

Configuration
  --config   Path to config file                    [default: (nearest rc file)]
  --opts     Path to `mocha.opts`        [string] [default: "./test/mocha.opts"]
  --package  Path to package.json for config                            [string]

File Handling
  --exclude                        Ignore file(s) or glob pattern(s)
                                                       [array] [default: (none)]
  --extension, --watch-extensions  File extension(s) to load and/or watch
                                                           [array] [default: js]
  --file                           Specify file(s) to be loaded prior to root
                                   suite execution     [array] [default: (none)]
  --recursive                      Look for tests in subdirectories    [boolean]
  --require, -r                    Require module      [array] [default: (none)]
  --sort, -S                       Sort test files                     [boolean]
  --watch, -w                      Watch files in the current working directory
                                   for changes                         [boolean]

Test Filters
  --fgrep, -f   Only run tests containing this string                   [string]
  --grep, -g    Only run tests matching this string or regexp           [string]
  --invert, -i  Inverts --grep and --fgrep matches                     [boolean]

Positional Arguments
  spec  One or more files, directories, or globs to test
                                                     [array] [default: ["test"]]

Other Options
  --help, -h     Show usage information & exit                         [boolean]
  --version, -V  Show version number & exit                            [boolean]
  --interfaces   List built-in user interfaces & exit                  [boolean]
  --reporters    List built-in reporters & exit                        [boolean]

✖ ERROR: Unknown "reporter": /mnt/c/Program Files/JetBrains/WebStorm 2019.2.4/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js
Waiting for the debugger to disconnect...

Process finished with exit code 1

如果我复制,则将第一行粘贴到cmd中,尽管它会运行。似乎是引号等问题。

虽然不起作用,我明白了:

C:\Users\iursino>C:\Users\iursino\AppData\Local\Microsoft\WindowsApps\ubuntu.exe run "export PATH=/home/iursino/n/bin:$PATH && /home/iursino/n/bin/node /mnt/c/workspace/project-name-redacted/node_modules/mocha/bin/_mocha --require ts-node/register --ui bdd --reporter \"/mnt/c/Program Files/JetBrains/WebStorm 2019.2.4/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js\" /mnt/c/workspace/project-name-redacted/src/Filename.spec.ts --grep \"^invoke lambda Expect success result when invoking lambda$\""

/mnt/c/workspace/project-name-redacted/node_modules/ts-node/src/index.ts:245
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
error TS2468: Cannot find global value 'Promise'.
../../workspace/project-name-redacted/src/Filename.spec.ts:3:8 - error TS1259: Module '"chai"' can only be default-imported using the 'esModuleInterop' flag

3 import chai, { expect } from 'chai'
         ~~~~

  ../../workspace/project-name-redacted/node_modules/@types/chai/index.d.ts:1921:5
    1921     export = chai;
             ~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
../../workspace/project-name-redacted/src/Filename.spec.ts:4:8 - error TS1259: Module '"chai-as-promised"' can only be default-imported using the 'esModuleInterop' flag

4 import chaiAsPromised from 'chai-as-promised'
         ~~~~~~~~~~~~~~

  ../../workspace/project-name-redacted/node_modules/@types/chai-as-promised/index.d.ts:20:5
    20     export = chaiAsPromised;
           ~~~~~~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
../../workspace/project-name-redacted/src/Filename.spec.ts:9:1 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

9 describe('invoke lambda', () => {
  ~~~~~~~~
../../workspace/project-name-redacted/src/Filename.spec.ts:25:5 - error TS2304: Cannot find name 'beforeEach'.

25     beforeEach(() => {
       ~~~~~~~~~~
../../workspace/project-name-redacted/src/Filename.spec.ts:30:5 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

30     it('Expect success result when invoking lambda', async () => {
       ~~
../../workspace/project-name-redacted/src/Filename.spec.ts:30:54 - 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.

30     it('Expect success result when invoking lambda', async () => {
                                                        ~~~~~~~~~~~~~
../../workspace/project-name-redacted/src/Filename.spec.ts:39:5 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

39     it('Expect error if lambda returns an error', async () => {
       ~~
../../workspace/project-name-redacted/src/Filename.spec.ts:39:51 - 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.

39     it('Expect error if lambda returns an error', async () => {
                                                     ~~~~~~~~~~~~~
../../workspace/project-name-redacted/src/Filename.spec.ts:48:5 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

48     it('Expect promise rejection if lambda returns an object as error (but not of type error)',  async () => {
       ~~
../../workspace/project-name-redacted/src/Filename.spec.ts:48:98 - 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.

48     it('Expect promise rejection if lambda returns an object as error (but not of type error)',  async () => {
                                                                                                    ~~~~~~~~~~~~~
../../workspace/project-name-redacted/src/Filename.spec.ts:57:5 - error TS2304: Cannot find name 'afterEach'.

57     afterEach(() => {
       ~~~~~~~~~

    at createTSError (/mnt/c/workspace/project-name-redacted/node_modules/ts-node/src/index.ts:245:12)
    at reportTSError (/mnt/c/workspace/project-name-redacted/node_modules/ts-node/src/index.ts:249:19)
    at getOutput (/mnt/c/workspace/project-name-redacted/node_modules/ts-node/src/index.ts:357:34)
    at Object.compile (/mnt/c/workspace/project-name-redacted/node_modules/ts-node/src/index.ts:415:32)
    at Module.m._compile (/mnt/c/workspace/project-name-redacted/node_modules/ts-node/src/index.ts:493:43)
    at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/mnt/c/workspace/project-name-redacted/node_modules/ts-node/src/index.ts:496:12)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at /mnt/c/workspace/project-name-redacted/node_modules/mocha/lib/mocha.js:330:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/mnt/c/workspace/project-name-redacted/node_modules/mocha/lib/mocha.js:327:14)
    at Mocha.run (/mnt/c/workspace/project-name-redacted/node_modules/mocha/lib/mocha.js:804:10)
    at Object.exports.singleRun (/mnt/c/workspace/project-name-redacted/node_modules/mocha/lib/cli/run-helpers.js:207:16)
    at exports.runMocha (/mnt/c/workspace/project-name-redacted/node_modules/mocha/lib/cli/run-helpers.js:300:13)
    at Object.exports.handler.argv [as handler] (/mnt/c/workspace/project-name-redacted/node_modules/mocha/lib/cli/run.js:296:3)
    at Object.runCommand (/mnt/c/workspace/project-name-redacted/node_modules/yargs/lib/command.js:242:26)
    at Object.parseArgs [as _parseArgs] (/mnt/c/workspace/project-name-redacted/node_modules/yargs/yargs.js:1087:28)
    at Object.parse (/mnt/c/workspace/project-name-redacted/node_modules/yargs/yargs.js:566:25)
    at Object.exports.main (/mnt/c/workspace/project-name-redacted/node_modules/mocha/lib/cli/cli.js:63:6)
    at Object.<anonymous> (/mnt/c/workspace/project-name-redacted/node_modules/mocha/bin/_mocha:10:23)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

为什么cmd和WebStorm有区别?另一个问题:cmd中出现的错误是怎么回事?

编辑:以编辑过的格式上载cmd输出。

0 个答案:

没有答案