Skip to content

Commit

Permalink
fix: load static webview resources with the editor from the same doma…
Browse files Browse the repository at this point in the history
…in (#411)

Signed-off-by: vitaliy-guliy <[email protected]>
  • Loading branch information
vitaliy-guliy authored Sep 9, 2024
1 parent ed7034c commit e03223c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
4 changes: 2 additions & 2 deletions launcher/src/webview-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class WebviewResources {
async configure(): Promise<void> {
console.log('# Configuring Webview Resources location...');

if ('true' !== env.WEBVIEW_LOCAL_RESOURCES) {
console.log(` > env.WEBVIEW_LOCAL_RESOURCES is not set to 'true', skip this step`);
if (env.WEBVIEW_LOCAL_RESOURCES !== undefined && 'false' === env.WEBVIEW_LOCAL_RESOURCES) {
console.log(` > env.WEBVIEW_LOCAL_RESOURCES is set to 'false', skip this step`);
return;
}

Expand Down
42 changes: 18 additions & 24 deletions launcher/tests/webview-resources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@ import * as path from 'path';
import * as fs from '../src/fs-extra';
import { WebviewResources } from '../src/webview-resources';

describe('Test Configuring of WebView static resources:', () => {
test('should skip if WEBVIEW_LOCAL_RESOURCES is not set', async () => {
delete env.WEBVIEW_LOCAL_RESOURCES;
const getCheCodeEndpointMock = jest.fn();
jest.mock('../src/flattened-devfile', () => ({
FlattenedDevfile: function () {
return { getCheCodeEndpoint: getCheCodeEndpointMock };
},
}));

const getCheCodeEndpointMock = jest.fn();
jest.mock('../src/flattened-devfile', () => ({
FlattenedDevfile: function () {
return { getCheCodeEndpoint: getCheCodeEndpointMock };
},
}));
describe('Test Configuring of WebView static resources:', () => {
test('should get Webview resources URL from product.json', async () => {
// had to combine two tests in one due to some issues with mocking the '../src/flattened-devfile' module

const resources = new WebviewResources();
await resources.configure();
// the first part checks that the relocating of webview resoures is skipped because of WEBVIEW_LOCAL_RESOURCES environment variable
env.WEBVIEW_LOCAL_RESOURCES = 'false';
new WebviewResources().configure();
expect(getCheCodeEndpointMock).toHaveBeenCalledTimes(0);
});
delete env.WEBVIEW_LOCAL_RESOURCES;

// the second path tests the functionality of the WebviewResources module

test('should get Webview resources URL from product.json', async () => {
// load "out/vs/workbench/workbench.web.main.js"
const fileWorkbenchWebMain = await fs.readFile(path.resolve(__dirname, '_data', 'workbench.web.main.js'));

Expand All @@ -47,14 +49,9 @@ describe('Test Configuring of WebView static resources:', () => {
// load "product.json"
const fileProductJSON = await fs.readFile(path.resolve(__dirname, '_data', 'product.json'));

// load "flattened.devworkspace.yaml"
const fileDevworkspaceFlattenedDevfile = await fs.readFile(
path.resolve(__dirname, '_data', 'flattened.devworkspace.yaml')
);

// configure the environment variable
env.DEVWORKSPACE_FLATTENED_DEVFILE = 'flattened.devworkspace.yaml';
env.WEBVIEW_LOCAL_RESOURCES = 'true';
getCheCodeEndpointMock.mockImplementation(() => {
return 'https://che-dogfooding.apps.che-dev.x6e0.p1.openshiftapps.com/vgulyy/che-code-multiroot/3100/';
});

const webviewResources = new WebviewResources();

Expand All @@ -66,9 +63,6 @@ describe('Test Configuring of WebView static resources:', () => {
case 'product.json':
return fileProductJSON;

case 'flattened.devworkspace.yaml':
return fileDevworkspaceFlattenedDevfile;

case 'out/vs/workbench/workbench.web.main.js':
return fileWorkbenchWebMain;

Expand Down

0 comments on commit e03223c

Please sign in to comment.