Last active
December 20, 2017 13:59
-
-
Save tily/ed73dc17ee8a07c638901f13e95955be to your computer and use it in GitHub Desktop.
mocha のテストに無理やり連番を振って番号指定でテスト実行できるようにする ref: https://qiita.com/tily/items/767d1d5acaabe9dcf4fb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Mocha = require("mocha"); | |
const originalRun = Mocha.prototype.run; | |
Mocha.prototype.run = function (fn) { | |
let i = 1 | |
this.loadFiles(() => { | |
this.suite.eachTest((test) => { | |
test.title = `#${i}: ${test.title}` | |
i += 1 | |
}) | |
}) | |
return originalRun.apply(this, [fn]) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require("assert"); | |
describe("Numbered tests", ()=> { | |
for(let i = 0; i < 15; i += 1) { | |
it("test hogehoge", () => { | |
assert(1 == 1) | |
}) | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mocha --require mocha_ext.js test.js | |
Numbered tests | |
✓ #1: test hogehoge | |
✓ #2: test hogehoge | |
✓ #3: test hogehoge | |
✓ #4: test hogehoge | |
✓ #5: test hogehoge | |
✓ #6: test hogehoge | |
✓ #7: test hogehoge | |
✓ #8: test hogehoge | |
✓ #9: test hogehoge | |
✓ #10: test hogehoge | |
✓ #11: test hogehoge | |
✓ #12: test hogehoge | |
✓ #13: test hogehoge | |
✓ #14: test hogehoge | |
✓ #15: test hogehoge | |
15 passing (11ms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mocha --require mocha_ext.js test.js --grep '#8:' | |
Numbered tests | |
✓ #8: test hogehoge | |
1 passing (10ms) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment