我正在使用jspm来管理我项目中的模块。
我想使用磁带和 ES6 语法编写测试。
我希望能够使用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
,我得到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?
}
}