Skip to content

Commit

Permalink
Fix interopDefault on jest object-proxy (vercel#37002)
Browse files Browse the repository at this point in the history
This fixes the interop default from vercel#36877 on the jest `object-proxy` as it currently causes the below error when running tests in our `with-jest` example:

```sh
    TypeError: 'get' on proxy: property '__esModule' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'true' but got 'false')
```

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

x-ref: vercel#36877
  • Loading branch information
ijjk authored and SukkaW committed May 18, 2022
1 parent 29b7189 commit 60dca6f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/next/taskfile-swc.js
Expand Up @@ -117,7 +117,7 @@ module.exports = function (task) {
if (output.map) {
if (interopClientDefaultExport) {
output.code += `
if (typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) {
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
Expand Down
4 changes: 3 additions & 1 deletion test/production/jest/index.test.ts
Expand Up @@ -21,10 +21,12 @@ describe('next/jest', () => {
return <h1>Hello Dynamic</h1>;
}
`,
'styles/index.module.css': '.home { color: orange }',
'pages/index.js': `
import dynamic from "next/dynamic";
import Image from "next/image";
import img from "../public/vercel.svg";
import styles from "../styles/index.module.css";
const Comp = dynamic(() => import("../components/comp"), {
loading: () => <h1>Loading...</h1>,
Expand All @@ -35,7 +37,7 @@ describe('next/jest', () => {
<Comp />
<Image src={img} alt="logo" placeholder="blur"/>
<Image src={img} alt="logo 2"/>
<p>hello world</p>
<p className={styles.home}>hello world</p>
</>
}
`,
Expand Down

0 comments on commit 60dca6f

Please sign in to comment.