Skip to content

Commit a5d0ad1

Browse files
authored
[turbopack] Add execution tests to demonstrate a bug (vercel#80918)
## Add tests for top level `this` behavior in CJS and ESM modules ### What? Added two test cases to verify the behavior of `this` in CommonJS and ESM modules: - CJS test verifies that `this` should be equal to `exports` - ESM test verifies that `this` should be equal to `globalThis` WHICH IS A BUG, it should be `undefined`
1 parent 0cf4491 commit a5d0ad1

File tree

2 files changed

+17
-0
lines changed
  • turbopack/crates/turbopack-tests/tests/execution/turbopack/basic

2 files changed

+17
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const t = this
2+
3+
it('`this` in cjs should be exports', () => {
4+
expect(t).toBe(exports)
5+
})
6+
7+
// Use a dummy assignment to ensure we are parsed as a cjs module
8+
exports.something = 'something'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const t = this
2+
3+
it('`this` in esm should be undefined', () => {
4+
// TODO: This is WRONG, it should be undefined
5+
expect(t).toBe(globalThis)
6+
})
7+
8+
// Use a dummy export to ensure this is parsed as an esm module
9+
export const foo = t

0 commit comments

Comments
 (0)