Skip to content

Commit 50a681b

Browse files
eleanorjboydCopilot
andcommitted
Fix pep723 test setup: stub require('fs-extra') instead of namespace wrapper
TypeScript's __importStar wraps CommonJS modules in a new object where every property is a non-configurable sinon cannot stub them.getter Stub the underlying require('fs-extra') object instead; the namespace wrapper's getters delegate to it, so the stub is picked up by the source-under-test transparently. All 7 pep723 tests now pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a01a406 commit 50a681b

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/test/features/execution/pep723.unit.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import * as assert from 'assert';
22
import * as sinon from 'sinon';
3-
import * as fse from 'fs-extra';
43
import { isPep723Script } from '../../../features/execution/pep723';
54

65
suite('isPep723Script Tests', () => {
76
let readFileStub: sinon.SinonStub;
87

98
setup(() => {
10-
readFileStub = sinon.stub(fse, 'readFile');
9+
// TypeScript compiles `import * as fse from 'fs-extra'` into a namespace wrapper whose
10+
// properties are non-configurable getters — sinon cannot stub them directly. The actual
11+
// `require('fs-extra')` object has writable/configurable properties AND the namespace
12+
// wrapper's getters delegate to it, so stubbing the real module object is intercepted by
13+
// the source-under-test as well.
14+
// eslint-disable-next-line @typescript-eslint/no-require-imports
15+
readFileStub = sinon.stub(require('fs-extra'), 'readFile');
1116
});
1217

1318
teardown(() => {

0 commit comments

Comments
 (0)