1

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 i.e 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?
  }

}
user5325596
  • 2,310
  • 4
  • 25
  • 42
  • I can't test with JSPM right now, but I use this with NPM: `babel-node $(which tape) \"./test/**/*.js\" | faucet` – joews Oct 29 '15 at 21:07

1 Answers1

0

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

Oleksii Rudenko
  • 1,277
  • 12
  • 23
  • 1
    I may go down the karma route eventually. For now though I'm just going with an earlier answer that was deleted pretty quickly for some reason. That answer suggested doing `npm install -D tape` and putting `babel-node node_modules/.bin/tape test/**/*.js` in `package.json`. – user5325596 Nov 02 '15 at 09:05
  • I have created a project that helps to setup browser tests for JSPM projects https://github.com/OrKoN/jspm-testem – Oleksii Rudenko Nov 30 '15 at 14:36