mirror of https://github.com/curbengh/hexo-yam
feat: show path that caused the error
This commit is contained in:
parent
c57e227efd
commit
51cc9b1d8d
|
@ -76,7 +76,7 @@ function minifyHtml (str, data) {
|
||||||
|
|
||||||
return result
|
return result
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(err)
|
throw new Error(`Path: ${path}\n${err}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ async function minifyCss (str, data) {
|
||||||
if (verbose) logFn.call(this, str, styles, path, 'css')
|
if (verbose) logFn.call(this, str, styles, path, 'css')
|
||||||
return styles
|
return styles
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(err)
|
throw new Error(`Path: ${path}\n${err}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ async function minifyJs (str, data) {
|
||||||
if (verbose) logFn.call(this, str, code, path, 'js')
|
if (verbose) logFn.call(this, str, code, path, 'js')
|
||||||
return code
|
return code
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(err)
|
throw new Error(`Path: ${path}\n${err}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ function minifySvg () {
|
||||||
if (verbose) logFn.call(this, assetTxt, data, path, 'svg')
|
if (verbose) logFn.call(this, assetTxt, data, path, 'svg')
|
||||||
resolve(route.set(path, data))
|
resolve(route.set(path, data))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reject(new Error(err))
|
reject(new Error(`Path: ${path}\n${err}`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
|
@ -181,7 +181,7 @@ function gzipFn () {
|
||||||
if (verbose) logFn.call(this, assetTxt, result, path, 'gzip')
|
if (verbose) logFn.call(this, assetTxt, result, path, 'gzip')
|
||||||
resolve(route.set(path + '.gz', result))
|
resolve(route.set(path + '.gz', result))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reject(new Error(err))
|
reject(new Error(`Path: ${path}\n${err}`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
|
@ -213,7 +213,7 @@ function brotliFn () {
|
||||||
if (verbose) logFn.call(this, assetTxt, result, path, 'brotli')
|
if (verbose) logFn.call(this, assetTxt, result, path, 'brotli')
|
||||||
resolve(route.set(path + '.br', result))
|
resolve(route.set(path + '.br', result))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reject(new Error(err))
|
reject(new Error(`Path: ${path}\n${err}`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
|
@ -243,7 +243,7 @@ function minifyXml () {
|
||||||
if (verbose) logFn.call(this, assetTxt, result, path, 'xml')
|
if (verbose) logFn.call(this, assetTxt, result, path, 'xml')
|
||||||
resolve(route.set(path, result))
|
resolve(route.set(path, result))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reject(new Error(err))
|
reject(new Error(`Path: ${path}\n${err}`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
|
@ -273,7 +273,7 @@ function minifyJson () {
|
||||||
if (verbose) logFn.call(this, assetTxt, result, path, 'json')
|
if (verbose) logFn.call(this, assetTxt, result, path, 'json')
|
||||||
resolve(route.set(path, result))
|
resolve(route.set(path, result))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reject(new Error(err))
|
reject(new Error(`Path: ${path}\n${err}`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
|
|
|
@ -76,11 +76,11 @@ describe('css', () => {
|
||||||
try {
|
try {
|
||||||
await new CleanCSS(customOpt).minify(input)
|
await new CleanCSS(customOpt).minify(input)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
expected = err.message
|
expected = err
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(expected).toBeDefined()
|
expect(expected).toBeDefined()
|
||||||
await expect(c(input, { path })).rejects.toThrow(expected)
|
await expect(c(input, { path })).rejects.toThrow(`Path: ${path}\n${expected}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('exclude - *.min.css', async () => {
|
test('exclude - *.min.css', async () => {
|
||||||
|
|
|
@ -103,10 +103,10 @@ describe('gzip', () => {
|
||||||
try {
|
try {
|
||||||
await gzip(input, customOpt)
|
await gzip(input, customOpt)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
expected = err.message
|
expected = err
|
||||||
}
|
}
|
||||||
expect(expected).toBeDefined()
|
expect(expected).toBeDefined()
|
||||||
await expect(g()).rejects.toThrow(expected)
|
await expect(g()).rejects.toThrow(`Path: ${path}\n${expected}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('include - exclude non-text file by default', async () => {
|
test('include - exclude non-text file by default', async () => {
|
||||||
|
|
|
@ -125,6 +125,6 @@ describe('html', () => {
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
h(invalid, { path })
|
h(invalid, { path })
|
||||||
}).toThrow('Parse Error')
|
}).toThrow(`Path: ${path}\nError: Parse Error`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -82,15 +82,15 @@ describe('js', () => {
|
||||||
}
|
}
|
||||||
hexo.config.minify.js = customOpt
|
hexo.config.minify.js = customOpt
|
||||||
|
|
||||||
let error
|
let expected
|
||||||
try {
|
try {
|
||||||
await terserMinify(input, customOpt)
|
await terserMinify(input, customOpt)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error = err.message
|
expected = err
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error).toBeDefined()
|
expect(expected).toBeDefined()
|
||||||
await expect(j(input, { path })).rejects.toThrow(error)
|
await expect(j(input, { path })).rejects.toThrow(`Path: ${path}\n${expected}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('exclude - *.min.js', async () => {
|
test('exclude - *.min.js', async () => {
|
||||||
|
@ -118,6 +118,6 @@ describe('js', () => {
|
||||||
test('invalid string', async () => {
|
test('invalid string', async () => {
|
||||||
const invalid = 'console.log("\\");'
|
const invalid = 'console.log("\\");'
|
||||||
|
|
||||||
await expect(j(invalid, { path })).rejects.toThrow('SyntaxError')
|
await expect(j(invalid, { path })).rejects.toThrow(`Path: ${path}\nSyntaxError`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -57,7 +57,7 @@ describe('xml', () => {
|
||||||
|
|
||||||
test('invalid input', async () => {
|
test('invalid input', async () => {
|
||||||
hexo.route.set(path, 'foo')
|
hexo.route.set(path, 'foo')
|
||||||
await expect(jsonFn()).rejects.toThrow(/SyntaxError/)
|
await expect(jsonFn()).rejects.toThrow(`Path: ${path}\nSyntaxError`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('empty file', async () => {
|
test('empty file', async () => {
|
||||||
|
|
|
@ -89,7 +89,7 @@ describe('svg', () => {
|
||||||
expected = err
|
expected = err
|
||||||
}
|
}
|
||||||
expect(expected).toBeDefined()
|
expect(expected).toBeDefined()
|
||||||
await expect(s()).rejects.toThrow(expected)
|
await expect(s()).rejects.toThrow(`Path: ${path}\n${expected}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('include - exclude *.min.svg by default', async () => {
|
test('include - exclude *.min.svg by default', async () => {
|
||||||
|
|
Loading…
Reference in New Issue