|
| 1 | +import { entryPaths, entries, flatten } from './../src/parse' |
| 2 | + |
| 3 | +describe('Parse entry paths', () => { |
| 4 | + it('returns an empty array by default', () => { |
| 5 | + expect(entryPaths()).toEqual([]) |
| 6 | + }) |
| 7 | + |
| 8 | + it('returns an object as itself', () => { |
| 9 | + const o = { a: ['a', 'b', 'c'] } |
| 10 | + expect(entryPaths(o)).toEqual(o) |
| 11 | + }) |
| 12 | + |
| 13 | + it('puts a string inside an array', () => { |
| 14 | + const str = 'foobar' |
| 15 | + expect(entryPaths(str)).toEqual([str]) |
| 16 | + }) |
| 17 | +}) |
| 18 | + |
| 19 | +describe('Flatten entry paths', () => { |
| 20 | + it('returns an array as itself', () => { |
| 21 | + const a = ['a', 'b', 'c'] |
| 22 | + expect(flatten(a)).toEqual(a) |
| 23 | + }) |
| 24 | + |
| 25 | + it('returns an object of arrays as one flat array', () => { |
| 26 | + const o = { a: ['a', 'b'], b: ['c', 'd'] } |
| 27 | + expect(flatten(o)).toEqual(['a', 'b', 'c', 'd']) |
| 28 | + }) |
| 29 | +}) |
| 30 | + |
| 31 | +describe('Parse entries', () => { |
| 32 | + it('returns paths if there is no chunk name', () => { |
| 33 | + const paths = ['a', 'b', 'c'] |
| 34 | + expect(entries(paths)).toEqual(paths) |
| 35 | + }) |
| 36 | + |
| 37 | + it('returns paths if paths are an array already', () => { |
| 38 | + const paths = ['a', 'b', 'c'] |
| 39 | + expect(entries(paths, 'foobar')).toEqual(paths) |
| 40 | + }) |
| 41 | + |
| 42 | + it('returns chunk paths', () => { |
| 43 | + const entryPaths = ['a', 'b', 'c'] |
| 44 | + const paths = { |
| 45 | + foobar: entryPaths |
| 46 | + } |
| 47 | + expect(entries(paths, 'foobar')).toEqual(entryPaths) |
| 48 | + }) |
| 49 | + |
| 50 | + it('returns chunk path wrapped in an array', () => { |
| 51 | + const entryPaths = 'a' |
| 52 | + const paths = { |
| 53 | + foobar: entryPaths |
| 54 | + } |
| 55 | + expect(entries(paths, 'foobar')).toEqual([entryPaths]) |
| 56 | + }) |
| 57 | + |
| 58 | + it('returns an empty array if failed to find entry', () => { |
| 59 | + const paths = { |
| 60 | + foobar: 'a' |
| 61 | + } |
| 62 | + expect(entries(paths, 'barbar')).toEqual([]) |
| 63 | + }) |
| 64 | + |
| 65 | + it('returns an empty array if failed to find entry with multiple paths', () => { |
| 66 | + const paths = { |
| 67 | + foobar: 'a', |
| 68 | + barbar: 'b' |
| 69 | + } |
| 70 | + expect(entries(paths, 'foofoo')).toEqual([]) |
| 71 | + }) |
| 72 | +}) |
0 commit comments