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