Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jest exception #5858

Merged
merged 2 commits into from
Jan 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/firestore/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ 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
// Copied from rollup output
// Added a check for Jest (see issue 5687 linked above)
return (
"(typeof document === 'undefined' ? new (require('url').URL)" +
"((typeof document === 'undefined' || process.env.JEST_WORKER_ID " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check whether process and process.env are defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that seems important, added.

"!== undefined || process.env.NODE_ENV === 'test') ?" +
" new (require('url').URL)" +
"('file:' + __filename).href : (document.currentScript && " +
`document.currentScript.src || new URL('${filename}', ` +
'document.baseURI).href))'
Expand Down