1

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

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

我希望能够使用npm test.

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

如果我添加

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

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

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

如果我替换jspm runbabel-node,我得到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?
  }

}
4

1 回答 1

0

1)您需要某种测试运行器。考虑将 karma 与 karma-jspm 插件一起使用:https ://github.com/Workiva/karma-jspm既然要使用磁带,请考虑添加 karma-tap https://github.com/mapbox/karma-tap

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

2)如果你需要测试一些非浏览器的代码,可以考虑使用 babel-node 和 mocha 等常规测试运行器。为此,您不需要 JSPM。

3)看看这个示例项目https://github.com/curran/jspm-mocha-example我相信它设法结合了 jspm、mocha 和节点执行

于 2015-10-30T14:30:30.860 回答