mirror of https://github.com/curbengh/hexo-yam
feat: add tests of minifyCssWithMap and minifyJsWithMap
This commit is contained in:
parent
da397b4504
commit
7907bfa6a4
|
|
@ -40,7 +40,10 @@ function minifyCssWithMap() {
|
||||||
/** @type {{ exclude: string[] }} */
|
/** @type {{ exclude: string[] }} */
|
||||||
const { exclude, globOptions, verbose } = options
|
const { exclude, globOptions, verbose } = options
|
||||||
const include = ['*.css', ...exclude.map(x => `!${x}`)]
|
const include = ['*.css', ...exclude.map(x => `!${x}`)]
|
||||||
const cleanCSS = new CleanCSS(options)
|
const cleanCSS = new CleanCSS({
|
||||||
|
...options,
|
||||||
|
sourceMap: true
|
||||||
|
})
|
||||||
|
|
||||||
return Promise.all((match(routeList, include, globOptions)).map(path => {
|
return Promise.all((match(routeList, include, globOptions)).map(path => {
|
||||||
return new Promise((/** @type {(value: void) => void} */ resolve, reject) => {
|
return new Promise((/** @type {(value: void) => void} */ resolve, reject) => {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ const CleanCSS = require('clean-css')
|
||||||
describe('css', () => {
|
describe('css', () => {
|
||||||
const hexo = new Hexo(__dirname)
|
const hexo = new Hexo(__dirname)
|
||||||
const c = require('../lib/css').minifyCss.bind(hexo)
|
const c = require('../lib/css').minifyCss.bind(hexo)
|
||||||
|
const cm = require('../lib/css').minifyCssWithMap.bind(hexo)
|
||||||
const input = 'foo { bar: baz; } foo { aaa: bbb; }'
|
const input = 'foo { bar: baz; } foo { aaa: bbb; }'
|
||||||
const path = 'foo.css'
|
const path = 'foo.css'
|
||||||
|
|
||||||
|
|
@ -20,6 +21,7 @@ describe('css', () => {
|
||||||
globOptions: { basename: true }
|
globOptions: { basename: true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hexo.route.set(path, input)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('default', async () => {
|
test('default', async () => {
|
||||||
|
|
@ -29,12 +31,32 @@ describe('css', () => {
|
||||||
expect(result).toBe(styles)
|
expect(result).toBe(styles)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('default with map', async () => {
|
||||||
|
await cm()
|
||||||
|
const { styles } = await new CleanCSS(hexo.config.minify.css).minify(input)
|
||||||
|
|
||||||
|
const output = hexo.route.get(path)
|
||||||
|
let result = ''
|
||||||
|
output.on('data', (chunk) => (result += chunk))
|
||||||
|
output.on('end', () => {
|
||||||
|
expect(result).toBe(styles + '\n/*# sourceMappingURL=foo.css.map */')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('empty file', async () => {
|
test('empty file', async () => {
|
||||||
const result = await c('', { path })
|
const result = await c('', { path })
|
||||||
|
|
||||||
expect(result).toBe('')
|
expect(result).toBe('')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('empty file with map', async () => {
|
||||||
|
hexo.route.set(path, '')
|
||||||
|
const result = await cm()
|
||||||
|
|
||||||
|
expect(result).toBeDefined()
|
||||||
|
expect(result[0]).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
test('option', async () => {
|
test('option', async () => {
|
||||||
const customOpt = {
|
const customOpt = {
|
||||||
level: {
|
level: {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ const { minify: terserMinify } = require('terser')
|
||||||
describe('js', () => {
|
describe('js', () => {
|
||||||
const hexo = new Hexo(__dirname)
|
const hexo = new Hexo(__dirname)
|
||||||
const j = require('../lib/js').minifyJs.bind(hexo)
|
const j = require('../lib/js').minifyJs.bind(hexo)
|
||||||
|
const jm = require('../lib/js').minifyJsWithMap.bind(hexo)
|
||||||
const input = 'var o = { "foo": 1, bar: 3 };'
|
const input = 'var o = { "foo": 1, bar: 3 };'
|
||||||
const path = 'foo.js'
|
const path = 'foo.js'
|
||||||
let expected = ''
|
let expected = ''
|
||||||
|
|
@ -28,6 +29,7 @@ describe('js', () => {
|
||||||
globOptions: { basename: true }
|
globOptions: { basename: true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hexo.route.set(path, input)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('default', async () => {
|
test('default', async () => {
|
||||||
|
|
@ -38,12 +40,33 @@ describe('js', () => {
|
||||||
expect(result).toBe(expected)
|
expect(result).toBe(expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('default with map', async () => {
|
||||||
|
await jm()
|
||||||
|
|
||||||
|
const output = hexo.route.get(path)
|
||||||
|
let result = ''
|
||||||
|
output.on('data', (chunk) => (result += chunk))
|
||||||
|
output.on('end', () => {
|
||||||
|
expect(result).toBeDefined()
|
||||||
|
expect(expected).toBeDefined()
|
||||||
|
expect(result).toBe(expected + '\n//# sourceMappingURL=foo.js.map')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('empty file', async () => {
|
test('empty file', async () => {
|
||||||
const result = await j('', { path })
|
const result = await j('', { path })
|
||||||
|
|
||||||
expect(result).toBe('')
|
expect(result).toBe('')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('empty file with map', async () => {
|
||||||
|
hexo.route.set(path, '')
|
||||||
|
const result = await jm()
|
||||||
|
|
||||||
|
expect(result).toBeDefined()
|
||||||
|
expect(result[0]).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
test('option', async () => {
|
test('option', async () => {
|
||||||
const customOpt = {
|
const customOpt = {
|
||||||
mangle: {
|
mangle: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue