|
| 1 | +import { readFileSync } from 'fs'; |
| 2 | +import { resolve } from 'path'; |
| 3 | + |
| 4 | +import { JSDOM } from 'jsdom'; |
| 5 | + |
| 6 | +describe('UMD bundle', () => { |
| 7 | + test.each([ |
| 8 | + 'autocomplete-core', |
| 9 | + 'autocomplete-js', |
| 10 | + 'autocomplete-plugin-algolia-insights', |
| 11 | + 'autocomplete-plugin-query-suggestions', |
| 12 | + 'autocomplete-plugin-recent-searches', |
| 13 | + 'autocomplete-plugin-redirect-url', |
| 14 | + 'autocomplete-plugin-tags', |
| 15 | + 'autocomplete-preset-algolia', |
| 16 | + ])('%s loads successfully', (name) => { |
| 17 | + const bundle = readFileSync( |
| 18 | + resolve(process.cwd(), `packages/${name}/dist/umd/index.production.js`), |
| 19 | + 'utf8' |
| 20 | + ); |
| 21 | + |
| 22 | + const { window } = new JSDOM('', { runScripts: 'dangerously' }); |
| 23 | + |
| 24 | + const errorFn = jest.fn(); |
| 25 | + window.addEventListener('error', errorFn); |
| 26 | + |
| 27 | + const script = window.document.createElement('script'); |
| 28 | + script.textContent = bundle; |
| 29 | + window.document.body.appendChild(script); |
| 30 | + |
| 31 | + expect(errorFn).not.toHaveBeenCalled(); |
| 32 | + expect(window[`@algolia/${name}`]).toBeDefined(); |
| 33 | + }); |
| 34 | +}); |
0 commit comments