Ava在测试时会忽略卷目录,并使用测试所在的特定文件夹

时间:2018-12-06 19:21:32

标签: node.js docker testing ava

当我使用以下命令运行ava测试时:

npm test

我想使ava进入一个文件夹,该文件夹用于项目交付的docker-compose.yml的docker卷,我用它来产生具有开发所需服务的开发环境。

就我而言,我为自定义xmpp客户端生成了一个openfire xmpp服务器:

version: '3'
services:
  openfire:
    build:
      context: submodules/docker-openfire
      dockerfile: submodules/docker-openfire/Dockerfile
    image: pcmagas/openfire:4.2.3-ubuntu
    ports:
      - "9090:9090"
      - "5222:5222"
      - "7777:7777"
      - "7070:7070"
      - "7443:7443"
    volumes:
      - "./volumes/openfire:/var/lib/openfire"

我将package.json中运行的测试配置为:

  "scripts": {
    "test": "ava"
  },

但是当我运行npm test时,我得到了错误:

> custom_xmpp@1.0.0 test /home/pcmagas/Kwdikas/master_thesis/custom_xmpp
> ava

glob error { [Error: EACCES: permission denied, scandir '/home/pcmagas/Kwdikas/master_thesis/custom_xmpp/volumes/openfire']
  errno: -13,
  code: 'EACCES',
  syscall: 'scandir',
  path:
   '/home/pcmagas/Kwdikas/master_thesis/custom_xmpp/volumes/openfire' }
Error: EACCES: permission denied, scandir '/home/pcmagas/Kwdikas/master_thesis/custom_xmpp/volumes/openfire'
    at handlePaths (/home/pcmagas/Kwdikas/master_thesis/custom_xmpp/node_modules/ava/lib/ava-files.js:13:18)
    at AvaFiles.findTestFiles (/home/pcmagas/Kwdikas/master_thesis/custom_xmpp/node_modules/ava/lib/ava-files.js:136:10)
    at Api.run (/home/pcmagas/Kwdikas/master_thesis/custom_xmpp/node_modules/ava/api.js:85:99)
    at Object.exports.run (/home/pcmagas/Kwdikas/master_thesis/custom_xmpp/node_modules/ava/lib/cli.js:248:7)
    at Object.<anonymous> (/home/pcmagas/Kwdikas/master_thesis/custom_xmpp/node_modules/ava/cli.js:10:23)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
npm ERR! Test failed.  See above for more details.

因此,我在package.json中尝试了以下配置,但仍然遇到上述相同的错误(基于此answer和此answer):

  "ava":{
    "files":[
      "!./volumes/openfire/__tests__",
      "!./volumes/openfire/test/*",
      "./test/*.js"
    ],
    "sources": [
            "**/*.{js,jsx}",
      "!dist/**/*",
      "!./volumes/"
        ]
  }

所以我改成了这个,导致了上面提到的错误:

"ava":{
    "files": ["./test","!./volumes"],
    "sources": "./src/**/*.{js,jsx}"
  },

还通过放置以下配置:

 "ava":{
    "files": "!./volumes",
    "sources": "./src/**/*.{js,jsx}"
  },

我收到以下错误:

> custom_xmpp@1.0.0 test /home/pcmagas/Kwdikas/master_thesis/custom_xmpp
> ava


  ✖ Couldn't find any files to test

npm ERR! Test failed.  See above for more details.

在我的测试文件夹中,有一个名为test/participantTest.js的文件,其内容如下:

import test from ava;
import { RosterItem } from './src/xmpp_helpers/roster';

test('createItem', t => {
    const participant = new RosterItem('user@example.com');
    if (participant.getJid() === 'user@example.com') {
        t.pass('A roster Item Has sucessfully been Created');
    }
    else {
        t.fail('Failed to Create a roster Item');
    }
});

您知道为什么我无法运行位于./test/文件夹中的测试吗?

0 个答案:

没有答案