Skip to content

Commit 7a79010

Browse files
committed
Add jest exception
1 parent df8ec42 commit 7a79010

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/firestore/rollup.config.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,22 @@ const util = require('./rollup.shared');
3535
// Customize how import.meta.url is polyfilled in cjs nodejs build. We use it to
3636
// be able to use require() in esm. It only generates the nodejs version of the
3737
// polyfill, as opposed to the default polyfill which supports both browser and
38-
// nodejs. The browser support is unnecessary and doesn't work well with Jest.
38+
// nodejs. The browser support doesn't work well with Jest.
3939
// See https://github.com/firebase/firebase-js-sdk/issues/5687
40+
// Although this is a cjs Node build and shouldn't require the browser option,
41+
// Vercel apps using this break on deployment, but work in local development.
42+
// See https://github.com/firebase/firebase-js-sdk/issues/5823
4043
function importMetaUrlPolyfillPlugin(filename) {
4144
return {
4245
name: 'import-meta-url-current-module',
4346
resolveImportMeta(property, { moduleId }) {
4447
if (property === 'url') {
45-
// copied from rollup output
48+
// Copied from rollup output
49+
// Added a check for Jest (see issue 5687 linked above)
4650
return (
47-
"(typeof document === 'undefined' ? new (require('url').URL)" +
51+
"((typeof document === 'undefined' || process.env.JEST_WORKER_ID " +
52+
"!== undefined || process.env.NODE_ENV === 'test') ?" +
53+
" new (require('url').URL)" +
4854
"('file:' + __filename).href : (document.currentScript && " +
4955
`document.currentScript.src || new URL('${filename}', ` +
5056
'document.baseURI).href))'

0 commit comments

Comments
 (0)