Skip to content

Commit 79bbbf2

Browse files
authored
test: verify that umd bundles load successfully (#1171)
1 parent 2685b95 commit 79bbbf2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/umd.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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

Comments
 (0)