chore(TypeScript): fix unit tests and coverage

This commit is contained in:
harttle
2019-02-17 20:46:33 +08:00
parent fc9ebdb90f
commit aa49b4f117
8 changed files with 43 additions and 19 deletions
+7 -5
View File
@@ -1,10 +1,12 @@
import * as _ from '../util/underscore'
import * as path from 'path'
import { anySeries } from '../util/promise'
import * as fs from 'fs'
import { stat, readFile } from 'fs'
const statFileAsync = <(filepath: string) => Promise<object>>_.promisify(fs.stat)
const readFileAsync = <(filepath: string, encoding: string) => Promise<string>>_.promisify(fs.readFile)
export const fs = {
stat: _.promisify(stat) as ((filepath: string) => Promise<object>),
readFile: _.promisify(readFile) as ((filepath: string, encoding: string) => Promise<string>)
}
export async function resolve (filepath, root, options) {
if (!path.extname(filepath)) {
@@ -15,7 +17,7 @@ export async function resolve (filepath, root, options) {
const paths = root.map(root => path.resolve(root, filepath))
return anySeries(paths, async path => {
try {
await statFileAsync(path)
await fs.stat(path)
return path
} catch (e) {
e.message = `${e.code}: Failed to lookup ${filepath} in: ${root}`
@@ -25,5 +27,5 @@ export async function resolve (filepath, root, options) {
}
export async function read (filepath): Promise<string> {
return readFileAsync(filepath, 'utf8')
return fs.readFile(filepath, 'utf8')
}