Skip to content

Commit e9a107f

Browse files
committed
[SERACH] add tst
1 parent 6899662 commit e9a107f

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { update } from './lib/update'
55
import { generate } from './lib/generate'
66
import { init } from './lib/init'
77
import { logs } from './lib/logs'
8+
import { search } from './lib/search'
89
import { output } from './lib/output'
910
import { htmlRender } from './lib/helpers/htmlRender'
1011
import StatusHelper from './lib/StatusHelper'
@@ -22,6 +23,7 @@ export default {
2223
update: update,
2324
generate: generate,
2425
init: init,
26+
search: search,
2527
logs: logs,
2628
output: output,
2729
CSVBuilder: CSVBuilder,

src/tests/search.spec.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
let sinon = require('sinon')
2+
let fs = require('fs')
3+
let walkSync = require('walk-sync')
4+
let findInFiles = require('find-in-files')
5+
6+
import { test } from 'ava'
7+
import ADR from 'adr'
8+
9+
let Utils = ADR.Utils
10+
let Config = ADR.Config
11+
12+
let adrTemplate = `# 1. 编写完整的单元测试
13+
14+
日期: 2017/11/22
15+
16+
## 状态
17+
18+
2017-11-22 提议
19+
20+
2017-11-26 已完成
21+
`
22+
23+
let adrOptions = JSON.stringify({
24+
path: './',
25+
language: 'zh-cn'
26+
})
27+
28+
test('ADR: list', t => {
29+
let findSpy = sinon.stub(findInFiles, 'find').returns({
30+
then: cb => {
31+
cb({'doc/adr/001-filename.md': {}})
32+
}
33+
})
34+
let ADRGetSavePathSpy = sinon.stub(Config, 'getSavePath').returns('./')
35+
let i18nSpy = sinon.stub(Utils, 'getI18n').returns({
36+
decision: '决策',
37+
modifiedDate: '上次修改时间',
38+
lastStatus: '最后状态',
39+
logSavePath: '保存路径:'
40+
})
41+
let consoleSpy = sinon.stub(console, 'log')
42+
let fsReadSpy = sinon.stub(fs, 'readFileSync')
43+
.onCall(0).returns(adrTemplate)
44+
.onCall(1).returns(adrTemplate)
45+
.onCall(2).returns(JSON.stringify(adrOptions))
46+
.onCall(3).returns(JSON.stringify(adrOptions))
47+
let entriesSpy = sinon.stub(walkSync, 'entries').returns([{
48+
relativePath: '001-filename.md',
49+
basePath: '/Users/fdhuang/learing/adr/doc/adr/',
50+
mode: 33188,
51+
size: 246,
52+
mtime: 1511435254653 }
53+
])
54+
55+
ADR.search('测试')
56+
t.deepEqual(consoleSpy.calledWith(
57+
`╔════════════╤═══════════════════╗
58+
║ 决策 │ 最后状态 ║
59+
╟────────────┼───────────────────╢
60+
║ 1.filename │ 2017-11-26 已完成 ║
61+
╚════════════╧═══════════════════╝
62+
`), true)
63+
findSpy.restore()
64+
ADRGetSavePathSpy.restore()
65+
entriesSpy.restore()
66+
consoleSpy.restore()
67+
fsReadSpy.restore()
68+
i18nSpy.restore()
69+
})

0 commit comments

Comments
 (0)