简体   繁体   English

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

[英]running multiple tests via npm test and jspm

I'm using jspm to manage the modules in my project. 我正在使用jspm来管理项目中的模块。

I'd like to write tests using tape and using ES6 syntax. 我想使用磁带和ES6语法编写测试。

I'd like to be able to run those tests from the command line using npm test . 我希望能够使用npm test从命令行运行那些npm test

If I run jspm run test/example.js directly from the command line, the test runs. 如果我直接从命令行运行jspm run test/example.js ,则测试将运行。

If I add 如果我加

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

to package.json and then run npm test , the test runs. package.json ,然后运行npm test ,测试运行。

So far so good, but I'd like to be have multiple tests in the test dir. 到目前为止一切顺利,但是我想在test目录中进行多个测试。 jspm run only seems to support one module at a time. jspm run似乎jspm run仅支持一个模块。

If I replace jspm run with babel-node , I get Error: Cannot find module 'tape' . 如果我用babel-node替换jspm runjspm run Error: Cannot find module 'tape' This error makes sense to me ie babel-node doesn't know where tape is, only jspm does. 这个错误对我来说很有意义,即babel-node不知道tape在哪里,只有jspm知道。

So is there a way of saying to npm test , "run all these tests in here and if you can't find a module, ask jspm"? 因此,对npm test有没有一种说法,“在这里运行所有这些测试,如果找不到模块,请询问jspm”?

Here is my sample test 这是我的样品测试

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();
});

Here is my directory structure. 这是我的目录结构。

  package.json
  test
    | - example.js

Here is my package.json 这是我的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) You need some kind of a test runner. 1)您需要某种测试跑步者。 Consider using karma with karma-jspm plugin: https://github.com/Workiva/karma-jspm Since you want to use tape, consider adding karma-tap https://github.com/mapbox/karma-tap 考虑使用带有karma-jspm插件的karma: https : //github.com/Workiva/karma-jspm既然要使用磁带,请考虑添加karma-tap https://github.com/mapbox/karma-tap

It looks like you want to test your code in Node but since JSPM is a package manager for the browser it makes more sense to use karma and run tests in the browser/headless browser. 看来您想在Node中测试代码,但是由于JSPM是浏览器的程序包管理器,因此使用业力并在浏览器/无头浏览器中运行测试更有意义。

2) If you need to test some non-browser code, consider using babel-node with conventional test runners such as mocha. 2)如果您需要测试一些非浏览器代码,请考虑将babel-node与常规测试运行程序(如mocha)一起使用。 You don't need JSPM for this. 您不需要JSPM。

3) Take a look at this sample project https://github.com/curran/jspm-mocha-example I believe it managed to combine jspm, mocha and node execution 3)看一下这个示例项目https://github.com/curran/jspm-mocha-example我相信它成功地结合了jspm,mocha和节点执行

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

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