Skip to content

Commit

Permalink
Add jest exception (#5858)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 committed Jan 8, 2022
1 parent df8ec42 commit b333c0a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/firestore/rollup.config.js
Expand Up @@ -35,19 +35,30 @@ const util = require('./rollup.shared');
// Customize how import.meta.url is polyfilled in cjs nodejs build. We use it to
// be able to use require() in esm. It only generates the nodejs version of the
// polyfill, as opposed to the default polyfill which supports both browser and
// nodejs. The browser support is unnecessary and doesn't work well with Jest.
// nodejs. The browser support doesn't work well with Jest.
// See https://github.com/firebase/firebase-js-sdk/issues/5687
// Although this is a cjs Node build and shouldn't require the browser option,
// Vercel apps using this break on deployment, but work in local development.
// See https://github.com/firebase/firebase-js-sdk/issues/5823
function importMetaUrlPolyfillPlugin(filename) {
return {
name: 'import-meta-url-current-module',
resolveImportMeta(property, { moduleId }) {
if (property === 'url') {
// copied from rollup output
// Added a check for Jest (see issue 5687 linked above)
// See https://jestjs.io/docs/environment-variables - apparently
// these are not always both set.
const JEST_CHECK =
`typeof process !== 'undefined' && process.env !== undefined` +
` && (process.env.JEST_WORKER_ID !== undefined || ` +
`process.env.NODE_ENV === 'test')`;
// Copied from rollup output
return (
"(typeof document === 'undefined' ? new (require('url').URL)" +
"('file:' + __filename).href : (document.currentScript && " +
`((typeof document === 'undefined' || (${JEST_CHECK})) ?` +
` new (require('url').URL)` +
`('file:' + __filename).href : (document.currentScript && ` +
`document.currentScript.src || new URL('${filename}', ` +
'document.baseURI).href))'
`document.baseURI).href))`
);
}
return null;
Expand Down

0 comments on commit b333c0a

Please sign in to comment.