Skip to content

Commit cb7effc

Browse files
authored
chore: fix PR build (aws#35380)
It is mysteriously broken on PR builds, but not on my own machine. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 461621e commit cb7effc

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tools/@aws-cdk/lazify/test/no-double-getter.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as fs from 'fs-extra';
22
import * as path from 'path';
33
import { transformFileContents } from '../lib';
4-
import { parse } from 'cjs-module-lexer';
54

6-
// Write a .js file in this directory that will be imported by tests below
5+
// Write a .js file in this directory that will be imported by tests below (make it work on Windows).
6+
let someModulePath = path.join(__dirname, 'some-module.js').replace(/\\/g, '/');
77
beforeEach(async () => {
8-
await fs.writeFile(path.join(__dirname, 'some-module.js'), [
8+
await fs.writeFile(someModulePath, [
99
'Object.defineProperty(module.exports, "foo", {',
1010
// Necessary otherwise the way we find exported symbols (by actually including the file and iterating keys)
1111
// won't find this symbol.
@@ -21,14 +21,20 @@ beforeEach(async () => {
2121
test('replace re-export with getter', () => {
2222
const fakeFile = path.join(__dirname, 'index.ts');
2323
const transformed = transformFileContents(fakeFile, [
24-
'__exportStar(require("./some-module"), exports);'
24+
`__exportStar(require("${someModulePath}"), exports);`
2525
].join('\n'));
2626

2727
const mod = evalModule(transformed);
2828

2929
const logMock = jest.spyOn(console, 'log');
30-
expect(mod.foo).toEqual(42);
31-
expect(mod.foo).toEqual(42);
30+
31+
// If we do `expect(mod.foo).toEqual(...)` Jest has some magic somewhere to
32+
// detect that it's a getter, rather than evaluate the getter to get to the
33+
// number `42`. So do the getter evaluation outside of an `expect` statement.
34+
const access1 = mod.foo;
35+
expect(access1).toEqual(42);
36+
const access2 = mod.foo;
37+
expect(access2).toEqual(42);
3238

3339
expect(logMock).toHaveBeenCalledTimes(1);
3440
});

0 commit comments

Comments
 (0)