rsnext/test/unit/select-pages/select-pages.test.js
Joe Haddad c56e962918
Add lambda version of shared chunks (#6924)
* Add lambda version of shared chunks

* Fix test on Windows
2019-04-06 22:25:38 -04:00

66 lines
2 KiB
JavaScript

/* eslint-env jest */
import { getSpecifiedPages as _getSpecifiedPages } from 'next/dist/build'
const getSpecifiedPages = async (...args) =>
(await _getSpecifiedPages(...args)).map(pg => pg.replace(/\\+/g, '/'))
describe('getSpecifiedPages', () => {
it('should only choose selected', async () => {
expect(await getSpecifiedPages(__dirname, ['a'], ['js'])).toMatchSnapshot()
let err
try {
await getSpecifiedPages(__dirname, ['a', 'b'], ['js'])
} catch (e) {
err = e
}
expect(err).toBeTruthy()
expect(
await getSpecifiedPages(__dirname, ['a', 'b'], ['js', 'jsx'])
).toMatchSnapshot()
expect(
await getSpecifiedPages(__dirname, ['a', 'b'], ['js', 'jsx', 'mdx'])
).toMatchSnapshot()
expect(
await getSpecifiedPages(__dirname, ['a', 'b', 'c'], ['js', 'jsx', 'mdx'])
).toMatchSnapshot()
expect(
await getSpecifiedPages(__dirname, ['a', 'b', 'c'], ['js', 'jsx', 'mdx'])
).toEqual(
await getSpecifiedPages(__dirname, ['a,b,c'], ['js', 'jsx', 'mdx'])
)
expect(
await getSpecifiedPages(__dirname, ['a', 'b', 'c'], ['js', 'jsx', 'mdx'])
).toEqual(
await getSpecifiedPages(__dirname, ['a,c', 'b'], ['js', 'jsx', 'mdx'])
)
expect(
await getSpecifiedPages(__dirname, ['a', 'b', 'c'], ['js', 'jsx', 'mdx'])
).toEqual(
await getSpecifiedPages(__dirname, ['a', 'c,b'], ['js', 'jsx', 'mdx'])
)
})
it('should select all', async () => {
expect(await getSpecifiedPages(__dirname, ['**'], ['js'])).toMatchSnapshot()
expect(
await getSpecifiedPages(__dirname, ['**'], ['js', 'mdx', 'jsx'])
).toMatchSnapshot()
})
it('should filter pages', async () => {
expect(
await getSpecifiedPages(__dirname, ['**', '-a'], ['js'])
).toMatchSnapshot()
expect(
await getSpecifiedPages(__dirname, ['**', '-a'], ['js', 'mdx', 'jsx'])
).toMatchSnapshot()
expect(
await getSpecifiedPages(__dirname, ['**,-a', '-c'], ['js', 'mdx', 'jsx'])
).toMatchSnapshot()
})
})