Skip to content

Commit 4267947

Browse files
authored
Mock vs code before attempting to setup venv (#1747)
1 parent 97c996a commit 4267947

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

extension/src/test/cli/index.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { mkdirp } from 'fs-extra'
2-
import { URI } from 'vscode-uri'
3-
import { stub } from 'sinon'
4-
import mock from 'mock-require'
52
import { TEMP_DIR, ENV_DIR } from './constants'
3+
require('../../vscode/mockModule')
64

75
const importModulesAfterMockingVsCode = () => {
86
const { removeDir } = require('../../fileSystem')
@@ -12,32 +10,6 @@ const importModulesAfterMockingVsCode = () => {
1210
return { removeDir, runMocha, setupVenv }
1311
}
1412

15-
class MockEventEmitter {
16-
public fire() {
17-
return stub()
18-
}
19-
20-
public event() {
21-
return stub()
22-
}
23-
}
24-
25-
mock('vscode', {
26-
EventEmitter: MockEventEmitter,
27-
Uri: {
28-
file: URI.file
29-
}
30-
})
31-
32-
mock('@hediet/std/disposable', {
33-
Disposable: {
34-
fn: () => ({
35-
track: <T>(disposable: T): T => disposable,
36-
untrack: () => undefined
37-
})
38-
}
39-
})
40-
4113
const { setupVenv, removeDir, runMocha } = importModulesAfterMockingVsCode()
4214

4315
async function main() {

extension/src/vscode/mockModule.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { URI } from 'vscode-uri'
2+
import { stub } from 'sinon'
3+
import mock from 'mock-require'
4+
5+
class MockEventEmitter {
6+
public fire() {
7+
return stub()
8+
}
9+
10+
public event() {
11+
return stub()
12+
}
13+
}
14+
15+
mock('vscode', {
16+
EventEmitter: MockEventEmitter,
17+
Uri: {
18+
file: URI.file
19+
}
20+
})
21+
22+
mock('@hediet/std/disposable', {
23+
Disposable: {
24+
fn: () => ({
25+
track: <T>(disposable: T): T => disposable,
26+
untrack: () => undefined
27+
})
28+
}
29+
})

scripts/virtualenv-install.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { join, resolve } from 'path'
2-
import { setupVenv } from 'dvc/src/python'
2+
require('dvc/src/vscode/mockModule')
3+
4+
const importModuleAfterMockingVsCode = () => {
5+
const { setupVenv } = require('dvc/src/python')
6+
7+
return setupVenv
8+
}
9+
10+
const setupVenv = importModuleAfterMockingVsCode()
311

412
const cwd = resolve(__dirname, '..', 'demo')
513

0 commit comments

Comments
 (0)