From ea98780075b67be1c98cd5f8f23e3cc712b98666 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 1 Sep 2025 12:12:08 +0200 Subject: [PATCH 1/7] chore: fix PR build It is mysteriously broken on PR builds, but not on my own machine. --- tools/@aws-cdk/lazify/test/no-double-getter.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts index d6b0ee2752c38..e1dcae8982ba7 100644 --- a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts +++ b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts @@ -25,6 +25,7 @@ test('replace re-export with getter', () => { ].join('\n')); const mod = evalModule(transformed); + console.log(mod); const logMock = jest.spyOn(console, 'log'); expect(mod.foo).toEqual(42); From 23efe3fe5fb597316bdfd837b5b4f085dd83ae2b Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 1 Sep 2025 12:23:41 +0200 Subject: [PATCH 2/7] Use absolute path to make sure the require() works --- tools/@aws-cdk/lazify/test/no-double-getter.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts index e1dcae8982ba7..1aab104678c44 100644 --- a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts +++ b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts @@ -3,9 +3,10 @@ import * as path from 'path'; import { transformFileContents } from '../lib'; import { parse } from 'cjs-module-lexer'; -// Write a .js file in this directory that will be imported by tests below +// Write a .js file in this directory that will be imported by tests below (make it work on Windows). +let someModulePath = path.join(__dirname, 'some-module.js').replace(/\\/g, '/'); beforeEach(async () => { - await fs.writeFile(path.join(__dirname, 'some-module.js'), [ + await fs.writeFile(someModulePath, [ 'Object.defineProperty(module.exports, "foo", {', // Necessary otherwise the way we find exported symbols (by actually including the file and iterating keys) // won't find this symbol. @@ -21,11 +22,10 @@ beforeEach(async () => { test('replace re-export with getter', () => { const fakeFile = path.join(__dirname, 'index.ts'); const transformed = transformFileContents(fakeFile, [ - '__exportStar(require("./some-module"), exports);' + `__exportStar(require("${someModulePath}"), exports);` ].join('\n')); const mod = evalModule(transformed); - console.log(mod); const logMock = jest.spyOn(console, 'log'); expect(mod.foo).toEqual(42); From 220f1ee04a873d7a30bb7a0ad148040215c1f455 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 1 Sep 2025 12:25:08 +0200 Subject: [PATCH 3/7] Remove unused import --- tools/@aws-cdk/lazify/test/no-double-getter.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts index 1aab104678c44..091ec4c1593d6 100644 --- a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts +++ b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts @@ -1,7 +1,6 @@ import * as fs from 'fs-extra'; import * as path from 'path'; import { transformFileContents } from '../lib'; -import { parse } from 'cjs-module-lexer'; // Write a .js file in this directory that will be imported by tests below (make it work on Windows). let someModulePath = path.join(__dirname, 'some-module.js').replace(/\\/g, '/'); From e9701de044187ead398df2e2febfc50d19854c7e Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 1 Sep 2025 13:38:30 +0200 Subject: [PATCH 4/7] Add logs back --- tools/@aws-cdk/lazify/test/no-double-getter.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts index 091ec4c1593d6..a945598f7dafe 100644 --- a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts +++ b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts @@ -24,7 +24,11 @@ test('replace re-export with getter', () => { `__exportStar(require("${someModulePath}"), exports);` ].join('\n')); + console.log(transformed); + const mod = evalModule(transformed); + console.log(mod); + console.log(mod.foo); const logMock = jest.spyOn(console, 'log'); expect(mod.foo).toEqual(42); From ea00ff2416b65007fabe1098140e409e223c9e8c Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 1 Sep 2025 14:03:21 +0200 Subject: [PATCH 5/7] I wonder if it's Jest that's just too clever? --- tools/@aws-cdk/lazify/test/no-double-getter.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts index a945598f7dafe..320a022d5adbe 100644 --- a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts +++ b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts @@ -31,8 +31,10 @@ test('replace re-export with getter', () => { console.log(mod.foo); const logMock = jest.spyOn(console, 'log'); - expect(mod.foo).toEqual(42); - expect(mod.foo).toEqual(42); + const access1 = mod.foo; + expect(access1).toEqual(42); + const access2 = mod.foo; + expect(access2).toEqual(42); expect(logMock).toHaveBeenCalledTimes(1); }); From 8a25a7d8a0763318908b4dfdd4f8ffedf2125152 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 1 Sep 2025 14:03:39 +0200 Subject: [PATCH 6/7] Wait this will fail the tests for no good reason --- tools/@aws-cdk/lazify/test/no-double-getter.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts index 320a022d5adbe..622f028bca7d9 100644 --- a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts +++ b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts @@ -28,7 +28,6 @@ test('replace re-export with getter', () => { const mod = evalModule(transformed); console.log(mod); - console.log(mod.foo); const logMock = jest.spyOn(console, 'log'); const access1 = mod.foo; From e5053123baa67285d95405f47a0abf8fb57c4811 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 1 Sep 2025 14:23:53 +0200 Subject: [PATCH 7/7] Remove unnecessary logs --- tools/@aws-cdk/lazify/test/no-double-getter.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts index 622f028bca7d9..86ae1425bf802 100644 --- a/tools/@aws-cdk/lazify/test/no-double-getter.test.ts +++ b/tools/@aws-cdk/lazify/test/no-double-getter.test.ts @@ -24,12 +24,13 @@ test('replace re-export with getter', () => { `__exportStar(require("${someModulePath}"), exports);` ].join('\n')); - console.log(transformed); - const mod = evalModule(transformed); - console.log(mod); const logMock = jest.spyOn(console, 'log'); + + // If we do `expect(mod.foo).toEqual(...)` Jest has some magic somewhere to + // detect that it's a getter, rather than evaluate the getter to get to the + // number `42`. So do the getter evaluation outside of an `expect` statement. const access1 = mod.foo; expect(access1).toEqual(42); const access2 = mod.foo;