Skip to content

Commit 933dfc1

Browse files
Strum355claude
andcommitted
test: use esmock instead of env var manipulation for mvn-not-available test
Replace process.env.TRUSTIFY_DA_MVN_PATH save/restore pattern with esmock mocking of invokeCommand to simulate missing mvn binary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 230339f commit 933dfc1

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

test/providers/workspace.test.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,17 @@ suite('discoverMavenModules', function () {
229229

230230
test('returns root pom when mvn is not available', async () => {
231231
const root = path.resolve('test/providers/tst_manifests/maven/maven_multi_module')
232-
const saved = process.env.TRUSTIFY_DA_MVN_PATH
233-
try {
234-
process.env.TRUSTIFY_DA_MVN_PATH = '/nonexistent/mvn'
235-
process.env.TRUSTIFY_DA_PREFER_MVNW = 'false'
236-
const result = await discoverMavenModules(root)
237-
expect(result).to.be.an('array')
238-
expect(result).to.have.lengthOf(1)
239-
expect(result[0]).to.equal(path.join(root, 'pom.xml'))
240-
} finally {
241-
if (saved !== undefined) {
242-
process.env.TRUSTIFY_DA_MVN_PATH = saved
243-
} else {
244-
delete process.env.TRUSTIFY_DA_MVN_PATH
245-
}
246-
delete process.env.TRUSTIFY_DA_PREFER_MVNW
247-
}
232+
const { discoverMavenModules: discoverMocked } = await esmock('../../src/providers/java_maven.js', {
233+
'../../src/tools.js': {
234+
getCustomPath: () => '/nonexistent/mvn',
235+
getWrapperPreference: () => false,
236+
invokeCommand: () => { throw Object.assign(new Error('mvn not found'), { code: 'ENOENT' }) },
237+
},
238+
})
239+
const result = await discoverMocked(root)
240+
expect(result).to.be.an('array')
241+
expect(result).to.have.lengthOf(1)
242+
expect(result[0]).to.equal(path.join(root, 'pom.xml'))
248243
})
249244

250245
test('excludes paths matching workspaceDiscoveryIgnore', async () => {

0 commit comments

Comments
 (0)