Skip to content

Commit

Permalink
test: verify that umd bundles load successfully (#1171)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhayab authored Aug 2, 2023
1 parent 2685b95 commit 79bbbf2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/umd.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
});
});

0 comments on commit 79bbbf2

Please sign in to comment.