简体   繁体   中英

running multiple tests via npm test and jspm

I'm using jspm to manage the modules in my project.

I'd like to write tests using tape and using ES6 syntax.

I'd like to be able to run those tests from the command line using npm test .

If I run jspm run test/example.js directly from the command line, the test runs.

If I add

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

to package.json and then run npm test , the test runs.

So far so good, but I'd like to be have multiple tests in the test dir. jspm run only seems to support one module at a time.

If I replace jspm run with babel-node , I get Error: Cannot find module 'tape' . This error makes sense to me ie babel-node doesn't know where tape is, only jspm does.

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"?

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

{
  "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. 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

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.

2) If you need to test some non-browser code, consider using babel-node with conventional test runners such as mocha. You don't need JSPM for this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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