[英]running multiple tests via npm test and jspm
我正在使用jspm來管理項目中的模塊。
我想使用磁帶和ES6語法編寫測試。
我希望能夠使用npm test
從命令行運行那些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
替換jspm run
, jspm run
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?
}
}
1)您需要某種測試跑步者。 考慮使用帶有karma-jspm插件的karma: https : //github.com/Workiva/karma-jspm既然要使用磁帶,請考慮添加karma-tap https://github.com/mapbox/karma-tap
看來您想在Node中測試代碼,但是由於JSPM是瀏覽器的程序包管理器,因此使用業力並在瀏覽器/無頭瀏覽器中運行測試更有意義。
2)如果您需要測試一些非瀏覽器代碼,請考慮將babel-node與常規測試運行程序(如mocha)一起使用。 您不需要JSPM。
3)看一下這個示例項目https://github.com/curran/jspm-mocha-example我相信它成功地結合了jspm,mocha和節點執行
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.