Skip to content

Commit 787d131

Browse files
committed
test: add test
1 parent b9127cd commit 787d131

File tree

5 files changed

+57
-27
lines changed

5 files changed

+57
-27
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ See [CHANGELOG](./CHANGELOG.md).
8181

8282
## ✈️ TODO
8383

84-
- [ ] init lib
85-
- [ ] 完成 replaceStringInFiles 函数开发
86-
- [ ] 完成同步开发
84+
- [x] init lib
85+
- [x] 完成 replaceStringInFiles 函数开发
86+
- [x] 完成同步函数开发
87+
- [ ] 完成测试
88+
- [ ] 生命周期??
8789

src/utils/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { OPTIONS_TYPES, Strings } from './constance'
2-
import * as fg from 'fast-glob';
32
import * as fs from 'fs';
43

4+
const fg = require('fast-glob')
5+
56

67
/**
78
* init parse options
@@ -21,7 +22,7 @@ export const parseOptions = (options: OPTIONS_TYPES): OPTIONS_TYPES => {
2122

2223
options.glob = options.glob ?? {};
2324

24-
const { files, from, to, ignore, encoding } = options;
25+
const { files, from, to, ignore, encoding } = options
2526
if (typeof files === 'undefined') throw new Error('files type error')
2627

2728
if (typeof from === 'undefined') throw new Error('from type error')
@@ -30,11 +31,11 @@ export const parseOptions = (options: OPTIONS_TYPES): OPTIONS_TYPES => {
3031

3132
if (!Array.isArray(files)) options.files = [files]
3233

33-
if (!Array.isArray(ignore)) options.ignore = ignore ? [] : [ignore]
34+
if (!Array.isArray(ignore)) options.ignore = !ignore ? [] : [ignore]
3435

35-
if (!options.encoding) options.encoding = 'utf-8'
36+
if (!encoding) options.encoding = 'utf-8'
3637

37-
return Object.assign({}, defaults, options);
38+
return Object.assign({}, defaults, options)
3839
}
3940

4041

test/getPathsAsync.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { test } from 'uvu'
2+
import * as assert from 'uvu/assert'
3+
import { getPathsAsync, getPathsSync } from '../src/utils/index'
4+
5+
test('getPathsAsync', async () => {
6+
const p1 = {
7+
files: '123',
8+
from: '11',
9+
to: '22'
10+
}
11+
assert.is(typeof getPathsAsync('123', p1), 'object')
12+
13+
const res = await getPathsAsync('123', p1)
14+
assert.equal(res, [])
15+
})
16+
test('getPathsSync', () => {
17+
const p1 = {
18+
files: '123',
19+
from: '11',
20+
to: '22'
21+
}
22+
assert.equal(getPathsSync('123', p1), [])
23+
})

test/index.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
import { test } from 'uvu'
2-
import * as assert from 'uvu/assert'
3-
4-
test('Math.sqrt()', () => {
5-
assert.is(Math.sqrt(4), 2)
6-
assert.is(Math.sqrt(144), 12)
7-
assert.is(Math.sqrt(2), Math.SQRT2)
8-
})
9-
10-
test('JSON', () => {
11-
const input = {
12-
foo: 'hello',
13-
bar: 'world'
14-
}
15-
16-
const output = JSON.stringify(input)
17-
18-
assert.snapshot(output, `{"foo":"hello","bar":"world"}`)
19-
assert.equal(JSON.parse(output), input, 'matches original')
20-
})
2+
import './parseOptions'
3+
import './getPathsAsync'
214

225
test.run()

test/parseOptions.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test } from 'uvu'
2+
import * as assert from 'uvu/assert'
3+
import { parseOptions } from '../src/utils/index'
4+
test('parseOptions', () => {
5+
const p1 = {
6+
files: '123',
7+
from: '11',
8+
to: '22'
9+
}
10+
assert.equal(parseOptions(p1), {
11+
files: ['123'],
12+
from: '11',
13+
to: '22',
14+
ignore: [],
15+
encoding: 'utf-8',
16+
disableGlobs: false,
17+
countMatches: false,
18+
freeze: false,
19+
glob: {},
20+
})
21+
})

0 commit comments

Comments
 (0)