Skip to content

Commit db945ce

Browse files
authored
VSCODE-123: Use asWebviewUri to load our bundled webview js file (#174)
1 parent 64faeec commit db945ce

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/test/suite/views/webviewController.test.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ suite('Connect Form View Test Suite', () => {
3333
const stubOnDidRecieveMessage = sinon.stub();
3434
const fakeWebview = {
3535
html: '',
36-
onDidReceiveMessage: stubOnDidRecieveMessage
36+
onDidReceiveMessage: stubOnDidRecieveMessage,
37+
asWebviewUri: sinon.fake.returns('')
3738
};
3839
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
3940
webview: fakeWebview
@@ -74,11 +75,16 @@ suite('Connect Form View Test Suite', () => {
7475
});
7576
}
7677

78+
const fakeWebview: any = {
79+
asWebviewUri: (jsUri) => {
80+
return jsUri;
81+
}
82+
};
83+
7784
const extensionPath = mdbTestExtension.testExtensionContext.extensionPath;
78-
const appUri = getReactAppUri(extensionPath);
85+
const appUri = getReactAppUri(extensionPath, fakeWebview);
7986
const htmlString = getConnectWebviewContent(appUri);
8087

81-
assert(htmlString.includes('vscode-resource:/'));
8288
assert(htmlString.includes('dist/webviewApp.js'));
8389

8490
const webviewAppFileName = (): string => 'dist/webviewApp.js';
@@ -121,7 +127,8 @@ suite('Connect Form View Test Suite', () => {
121127
onDidReceiveMessage: (callback): void => {
122128
messageRecieved = callback;
123129
messageRecievedSet = true;
124-
}
130+
},
131+
asWebviewUri: sinon.fake.returns('')
125132
};
126133
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
127134
webview: fakeWebview
@@ -193,7 +200,8 @@ suite('Connect Form View Test Suite', () => {
193200
onDidReceiveMessage: (callback): void => {
194201
messageRecieved = callback;
195202
messageRecievedSet = true;
196-
}
203+
},
204+
asWebviewUri: sinon.fake.returns('')
197205
};
198206
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
199207
webview: fakeWebview
@@ -259,7 +267,8 @@ suite('Connect Form View Test Suite', () => {
259267
},
260268
onDidReceiveMessage: (callback): void => {
261269
messageRecieved = callback;
262-
}
270+
},
271+
asWebviewUri: sinon.fake.returns('')
263272
};
264273
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
265274
webview: fakeWebview
@@ -318,7 +327,8 @@ suite('Connect Form View Test Suite', () => {
318327
},
319328
onDidReceiveMessage: (callback): void => {
320329
messageRecieved = callback;
321-
}
330+
},
331+
asWebviewUri: sinon.fake.returns('')
322332
};
323333
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
324334
webview: fakeWebview
@@ -388,7 +398,8 @@ suite('Connect Form View Test Suite', () => {
388398
},
389399
onDidReceiveMessage: (callback): void => {
390400
messageRecieved = callback;
391-
}
401+
},
402+
asWebviewUri: sinon.fake.returns('')
392403
};
393404

394405
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
@@ -442,7 +453,8 @@ suite('Connect Form View Test Suite', () => {
442453
},
443454
onDidReceiveMessage: (callback): void => {
444455
messageRecieved = callback;
445-
}
456+
},
457+
asWebviewUri: sinon.fake.returns('')
446458
};
447459
const fakeVSCodeCreateWebviewPanel = sinon.fake.returns({
448460
webview: fakeWebview
@@ -494,7 +506,8 @@ suite('Connect Form View Test Suite', () => {
494506
html: '',
495507
onDidReceiveMessage: (callback): void => {
496508
messageRecieved = callback;
497-
}
509+
},
510+
asWebviewUri: sinon.fake.returns('')
498511
};
499512
const fakeVSCodeExecuteCommand = sinon.fake.resolves(false);
500513

src/views/webviewController.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ export const getConnectWebviewContent = (jsAppFileUrl: vscode.Uri): string => {
4141
</html>`;
4242
};
4343

44-
export const getReactAppUri = (extensionPath: string): vscode.Uri => {
45-
const jsAppFilePath = vscode.Uri.file(
44+
export const getReactAppUri = (extensionPath: string, webview: vscode.Webview): vscode.Uri => {
45+
const localFilePathUri = vscode.Uri.file(
4646
path.join(extensionPath, 'dist', 'webviewApp.js')
4747
);
48-
return jsAppFilePath.with({ scheme: 'vscode-resource' });
48+
const jsAppFileWebviewUri = webview.asWebviewUri(localFilePathUri);
49+
return jsAppFileWebviewUri;
4950
};
5051

5152
export default class WebviewController {
@@ -177,7 +178,7 @@ export default class WebviewController {
177178
path.join(extensionPath, 'images', 'leaf.svg')
178179
);
179180

180-
const reactAppUri = getReactAppUri(extensionPath);
181+
const reactAppUri = getReactAppUri(extensionPath, panel.webview);
181182
panel.webview.html = getConnectWebviewContent(reactAppUri);
182183

183184
// Handle messages from the webview.

0 commit comments

Comments
 (0)