繁体   English   中英

通过npm test和jspm运行多个测试

[英]running multiple tests via npm test and jspm

我正在使用jspm来管理项目中的模块。

我想使用磁带和ES6语法编写测试。

我希望能够使用npm test从命令行运行那些npm test

如果我直接从命令行运行jspm run test/example.js ,则测试将运行。

如果我加

"scripts" : {
    "test" : "jspm run test/example.js"
}

package.json ,然后运行npm test ,测试运行。

到目前为止一切顺利,但是我想在test目录中进行多个测试。 jspm run似乎jspm run仅支持一个模块。

如果我用babel-node替换jspm runjspm run Error: Cannot find module 'tape' 这个错误对我来说很有意义,即babel-node不知道tape在哪里,只有jspm知道。

因此,对npm test有没有一种说法,“在这里运行所有这些测试,如果找不到模块,请询问jspm”?

这是我的样品测试

import test from 'tape';

test('A passing test', (assert) => {

  assert.pass('This test will pass.');

  assert.end();
});

test('Assertions with tape.', (assert) => {
  const expected = 'something to test';
  const actual = 'sonething to test';

  assert.equal(actual, expected,
    'Given two mismatched values, .equal() should produce a nice bug report');

  assert.end();
});

这是我的目录结构。

  package.json
  test
    | - example.js

这是我的package.json

{
  "name": "playground",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "ISC",
  "jspm": {
    "devDependencies": {
      "babel": "npm:babel-core@^5.8.24",
      "babel-runtime": "npm:babel-runtime@^5.8.24",
      "core-js": "npm:core-js@^1.1.4",
      "tape": "npm:tape@^4.2.2"
    }
  },
  "devDependencies": {
    "jspm": "^0.16.13"
  },
  "scripts" : {
    "test" : "jspm run test/example.js" //<-- what should I put here?
  }

}

1)您需要某种测试跑步者。 考虑使用带有karma-jspm插件的karma: https : //github.com/Workiva/karma-jspm既然要使用磁带,请考虑添加karma-tap https://github.com/mapbox/karma-tap

看来您想在Node中测试代码,但是由于JSPM是浏览器的程序包管理器,因此使用业力并在浏览器/无头浏览器中运行测试更有意义。

2)如果您需要测试一些非浏览器代码,请考虑将babel-node与常规测试运行程序(如mocha)一起使用。 您不需要JSPM。

3)看一下这个示例项目https://github.com/curran/jspm-mocha-example我相信它成功地结合了jspm,mocha和节点执行

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM