|
| 1 | +const { join } = require('path'); |
| 2 | +const { access } = require('fs').promises; |
| 3 | +const { build } = require('./lib/cli'); |
| 4 | +const { subject } = require('./lib/output'); |
| 5 | + |
| 6 | +const formats = ['cjs', 'esm']; |
| 7 | + |
| 8 | +const prerenderUrlFiles = [ |
| 9 | + 'array.js', |
| 10 | + 'stringified-array.js', |
| 11 | + 'function-returning-array.js', |
| 12 | + 'function-returning-stringified-array.js', |
| 13 | +]; |
| 14 | + |
| 15 | +const preactConfigFiles = ['function.js', 'object.js']; |
| 16 | + |
| 17 | +describe('config files', () => { |
| 18 | + describe('prerender-urls', () => { |
| 19 | + it(`should load the 'prerender-urls.json' file`, async () => { |
| 20 | + let dir = await subject('multiple-config-files'); |
| 21 | + |
| 22 | + await build(dir); |
| 23 | + |
| 24 | + expect(await access(join(dir, 'build/index.html'))).toBeUndefined(); |
| 25 | + expect( |
| 26 | + await access(join(dir, 'build/custom/index.html')) |
| 27 | + ).toBeUndefined(); |
| 28 | + }); |
| 29 | + |
| 30 | + formats.forEach(moduleFormat => { |
| 31 | + prerenderUrlFiles.forEach(dataFormat => { |
| 32 | + it(`should load the '${dataFormat}' file in ${moduleFormat}`, async () => { |
| 33 | + let dir = await subject('multiple-config-files'); |
| 34 | + |
| 35 | + await build(dir, { |
| 36 | + prerenderUrls: `prerenderUrls/${moduleFormat}/${dataFormat}`, |
| 37 | + }); |
| 38 | + |
| 39 | + expect(await access(join(dir, 'build/index.html'))).toBeUndefined(); |
| 40 | + expect( |
| 41 | + await access(join(dir, 'build/custom/index.html')) |
| 42 | + ).toBeUndefined(); |
| 43 | + }); |
| 44 | + }); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + describe('preact.config', () => { |
| 49 | + formats.forEach(moduleFormat => { |
| 50 | + preactConfigFiles.forEach(dataFormat => { |
| 51 | + it(`should load the '${dataFormat}' file in ${moduleFormat}`, async () => { |
| 52 | + let dir = await subject('multiple-config-files'); |
| 53 | + |
| 54 | + await build(dir, { |
| 55 | + config: `preactConfig/${moduleFormat}/${dataFormat}`, |
| 56 | + }); |
| 57 | + |
| 58 | + expect(await access(join(dir, 'build/bundle.js'))).toBeUndefined(); |
| 59 | + }); |
| 60 | + }); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments