首页 > 解决方案 > 插件“gulp-mocha”中的错误

问题描述

我想使用 chai.assert 使用“gulp test”运行测试,并且插件“gulp-mocha”出现错误。'npm start' 工作正常。Webstorm 向我显示此消息:

[16:17:53] 'test' errored after 131 ms
[16:17:53] Error in plugin "gulp-mocha"
Message:
    spawn mocha ENOENT
Details:
    errno: ENOENT
    code: ENOENT
    syscall: spawn mocha
    path: mocha
    spawnargs: /Applications/WebStorm.app/Contents/bin/https:/github.com/AlinaGay/module3_node_js/791559-pixel-hunter/build/test/data/game-data.test.js,--colors,--reporter=spec
    stdout: 
    stderr: 
    failed: true
    signal: null
    cmd: mocha /Applications/WebStorm.app/Contents/bin/https:/github.com/AlinaGay/module3_node_js/791559-pixel-hunter/build/test/data/game-data.test.js --colors --reporter=spec
    timedOut: false
    killed: false

这是测试代码:

import {assert} from 'chai';

describe(`Array`, () => {
  describe(`#indexOf()`, () => {
    it(`should return -1 when the value is not present`, () => {
      assert.equal(-1, [1, 2, 3].indexOf(4));
    });
  });
});

.eslinter.yml 的代码如下:

parserOptions:
  sourceType: 'module'

env:
  es6: true
  browser: true
  commonjs: true
  mocha: true

galpfile.js 看起来

.....................
const mocha = require(`gulp-mocha`);
const commonjs = require(`rollup-plugin-commonjs`);
...............................
gulp.task(`test`, function () {
  return gulp
    .src([`js/**/*.test.js`])
    .pipe(rollup({
      plugins: [
        commonjs() // Сообщает Rollup, что модули можно загружать из node_modules
      ]}, `cjs`)) // Выходной формат тестов — `CommonJS` модуль
    .pipe(gulp.dest(`build/test`))
    .pipe(mocha({
      reporter: `spec` // Вид в котором я хочу отображать результаты тестирования
    }));
});

标签: javascriptgulpmocha.jschai

解决方案


推荐阅读