Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: load static webview resources with the editor from the same domain #411

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading