-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
test: add test for browser compatibility #721
Conversation
Coverage report
Test suite run success674 tests passing in 95 suites. Report generated by 🧪jest coverage report action from 854db46 |
4da7bc5
to
854db46
Compare
const requireRegex = /(?:^|[^.])\brequire\s*\(\s*(["'])(.+?)\1\s*\)/g; | ||
let match; | ||
while ((match = requireRegex.exec(formattedBundleContent))) { | ||
const moduleName = match[2]; | ||
listOfModules.add(moduleName); | ||
} | ||
|
||
const importRegex = /import\s+(?:.+\s+from\s+)?["'](.+)["'];?/g; | ||
let importMatch; | ||
while ((importMatch = importRegex.exec(formattedBundleContent))) { | ||
const moduleName = importMatch[1]; | ||
listOfModules.add(moduleName); | ||
} | ||
|
||
const exportRegex = /export\s+(?:.+\s+from\s+)?["'](.+)["'];?/g; | ||
let exportMatch; | ||
while ((exportMatch = exportRegex.exec(formattedBundleContent))) { | ||
const moduleName = exportMatch[1]; | ||
listOfModules.add(moduleName); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach that I have gone with is scanning the bundled files for require
and import
statements to check for any references to Node.js built-in modules that are only available in a Node environment and not in a browser. I am not sure if this is the absolute best way to go about this, but I have checked that it does get the job done.
The moment I tried importing something from a module like fs
, used it in a function and exported that function from one of the child packages, the test failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rationale is valid, but it'd be hard to have certainty about the complete required stack, since we don't control all the libraries in use. For example, we can import an NPM package that uses some native module, which might be hard or impossible to detect, especially if we consider multiple nested dependencies.
In the end, I believe a declarative approach will suit us better.
One inspiration is how jest-runner-groups does it using manual tags.
Closing this in favor of #728 |
browser compatibility
#284fuels
package that scans the browser bundles of all the child packages exported by the umbrellafuels
package for any references to Node.js built-in modules that may cause the package to break in a browser environment.Keeping this a draft for now. Just an idea.