forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsourceMapSupport.unit.test.ts
More file actions
114 lines (107 loc) · 5.26 KB
/
sourceMapSupport.unit.test.ts
File metadata and controls
114 lines (107 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// tslint:disable:no-any no-unused-expression chai-vague-errors no-unnecessary-override max-func-body-length max-classes-per-file
import { expect } from 'chai';
import * as path from 'path';
import { ConfigurationTarget, Disposable } from 'vscode';
import { Diagnostics } from '../client/common/utils/localize';
import { EXTENSION_ROOT_DIR } from '../client/constants';
import { initialize, SourceMapSupport } from '../client/sourceMapSupport';
import { noop, sleep } from './core';
suite('Source Map Support', () => {
function createVSCStub(isEnabled: boolean = false, selectDisableButton: boolean = false) {
const stubInfo = {
configValueRetrieved: false,
configValueUpdated: false,
messageDisplayed: false
};
const vscode = {
workspace: {
getConfiguration: (setting: string, _defaultValue: any) => {
if (setting !== 'python.diagnostics') {
return;
}
return {
get: (prop: string) => {
stubInfo.configValueRetrieved = prop === 'sourceMapsEnabled';
return isEnabled;
},
update: (prop: string, value: boolean, scope: ConfigurationTarget) => {
if (prop === 'sourceMapsEnabled' && value === false && scope === ConfigurationTarget.Global) {
stubInfo.configValueUpdated = true;
}
}
};
}
},
window: {
showWarningMessage: () => {
stubInfo.messageDisplayed = true;
return Promise.resolve(selectDisableButton ? Diagnostics.disableSourceMaps() : undefined);
}
},
ConfigurationTarget: ConfigurationTarget
};
return { stubInfo, vscode };
}
const disposables: Disposable[] = [];
teardown(() => {
disposables.forEach(disposable => {
try {
disposable.dispose();
} catch { noop(); }
});
});
test('Test message is not displayed when source maps are not enabled', async () => {
const stub = createVSCStub(false);
initialize(stub.vscode as any);
await sleep(100);
expect(stub.stubInfo.configValueRetrieved).to.be.equal(true, 'Config Value not retrieved');
expect(stub.stubInfo.messageDisplayed).to.be.equal(false, 'Message displayed');
});
test('Test message is not displayed when source maps are not enabled', async () => {
const stub = createVSCStub(true);
const instance = new class extends SourceMapSupport {
protected async enableSourceMaps(_enable: boolean) {
noop();
}
}(stub.vscode as any);
await instance.initialize();
expect(stub.stubInfo.configValueRetrieved).to.be.equal(true, 'Config Value not retrieved');
expect(stub.stubInfo.messageDisplayed).to.be.equal(true, 'Message displayed');
expect(stub.stubInfo.configValueUpdated).to.be.equal(false, 'Config Value updated');
});
test('Test message is not displayed when source maps are not enabled', async () => {
const stub = createVSCStub(true, true);
const instance = new class extends SourceMapSupport {
protected async enableSourceMaps(_enable: boolean) {
noop();
}
}(stub.vscode as any);
await instance.initialize();
expect(stub.stubInfo.configValueRetrieved).to.be.equal(true, 'Config Value not retrieved');
expect(stub.stubInfo.messageDisplayed).to.be.equal(true, 'Message displayed');
expect(stub.stubInfo.configValueUpdated).to.be.equal(true, 'Config Value not updated');
});
async function testRenamingFilesWhenEnablingDisablingSourceMaps(enableSourceMaps: boolean) {
const stub = createVSCStub(true, true);
const sourceFilesPassed: string[] = [];
const instance = new class extends SourceMapSupport {
public async enableSourceMaps(enable: boolean) {
return super.enableSourceMaps(enable);
}
public async enableSourceMap(enable: boolean, sourceFile: string) {
expect(enable).to.equal(enableSourceMaps);
sourceFilesPassed.push(sourceFile);
return Promise.resolve();
}
}(stub.vscode as any);
await instance.enableSourceMaps(enableSourceMaps);
const extensionSourceMap = path.join(EXTENSION_ROOT_DIR, 'out', 'client', 'extension.js');
const debuggerSourceMap = path.join(EXTENSION_ROOT_DIR, 'out', 'client', 'debugger', 'debugAdapter', 'main.js');
expect(sourceFilesPassed).to.deep.equal([extensionSourceMap, debuggerSourceMap]);
}
test('Rename extension and debugger source maps when enabling source maps', () => testRenamingFilesWhenEnablingDisablingSourceMaps(true));
test('Rename extension and debugger source maps when disabling source maps', () => testRenamingFilesWhenEnablingDisablingSourceMaps(false));
});