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
81 lines (77 loc) · 3.53 KB
/
sourceMapSupport.unit.test.ts
File metadata and controls
81 lines (77 loc) · 3.53 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// tslint:disable:no-any
import { expect } from 'chai';
import { ConfigurationTarget } from 'vscode';
import { Diagnostics } from '../client/common/utils/localize';
import * as sourceMaps 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 };
}
test('Test message is not displayed when source maps are not enabled', async () => {
const stub = createVSCStub(false);
sourceMaps.default(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 sourceMaps.SourceMapSupport {
protected initializeSourceMaps() {
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 sourceMaps.SourceMapSupport {
protected initializeSourceMaps() {
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');
});
});