test: cover all

This commit is contained in:
harttle
2018-08-27 23:27:42 +08:00
parent d6876bd9ec
commit 5378f2709b
9 changed files with 351 additions and 1133 deletions
+1 -1
View File
@@ -90,7 +90,7 @@ const _engine = {
function normalizeStringArray (value) {
if (_.isArray(value)) return value
if (_.isString(value)) return [value]
return []
throw new TypeError('illegal root: ' + value)
}
export default function Liquid (options) {
+5 -9
View File
@@ -3,10 +3,13 @@ import path from 'path'
import {anySeries} from './util/promise.js'
import {statFileAsync, readFileAsync} from './util/fs.js'
function lookup (filepath, root, options) {
export async function resolve (filepath, root, options) {
if (!path.extname(filepath)) {
filepath += options.extname
}
root = options.root.concat(root || [])
root = _.uniq(root)
const paths = root.map(root => path.resolve(root || location.href, filepath))
const paths = root.map(root => path.resolve(root, filepath))
return anySeries(paths, async path => {
try {
await statFileAsync(path)
@@ -18,13 +21,6 @@ function lookup (filepath, root, options) {
})
}
export async function resolve (filepath, root, options) {
if (!path.extname(filepath)) {
filepath += options.extname
}
return lookup(filepath, root, options)
}
export async function read (filepath) {
return readFileAsync(filepath)
}