Commit ef3b8cd5 authored by Miguel Rincon's avatar Miguel Rincon

Force CI schema URL to be absolute

In order for workers loaded from `data://` as the
ones loaded by monaco, we use absolute URLs to fetch
schema files, hence the `location.origin` reference.
This prevents error: "Failed to execute 'fetch' on 'WorkerGlobalScope'"
parent 9f7b9738
......@@ -24,8 +24,16 @@ export class CiSchemaExtension extends EditorLiteExtension {
.replace(':filename', EXTENSION_CI_SCHEMA_FILE_NAME_MATCH);
const modelFileName = this.getModel().uri.path.split('/').pop();
// In order for workers loaded from `data://` as the
// ones loaded by monaco, we use absolute URLs to fetch
// schema files, hence the `location.origin` reference.
// This prevents error:
// "Failed to execute 'fetch' on 'WorkerGlobalScope'"
// eslint-disable-next-line no-restricted-globals
const absoluteSchemaUrl = location.origin + ciSchemaUri;
registerSchema({
uri: ciSchemaUri,
uri: absoluteSchemaUrl,
fileMatch: [modelFileName],
});
}
......
import { languages } from 'monaco-editor';
import { TEST_HOST } from 'helpers/test_constants';
import EditorLite from '~/editor/editor_lite';
import { CiSchemaExtension } from '~/editor/extensions/editor_ci_schema_ext';
import { EXTENSION_CI_SCHEMA_FILE_NAME_MATCH } from '~/editor/constants';
......@@ -73,7 +74,7 @@ describe('~/editor/editor_ci_config_ext', () => {
});
expect(getConfiguredYmlSchema()).toEqual({
uri: `/${mockProjectNamespace}/${mockProjectPath}/-/schema/${mockRef}/${EXTENSION_CI_SCHEMA_FILE_NAME_MATCH}`,
uri: `${TEST_HOST}/${mockProjectNamespace}/${mockProjectPath}/-/schema/${mockRef}/${EXTENSION_CI_SCHEMA_FILE_NAME_MATCH}`,
fileMatch: [defaultBlobPath],
});
});
......@@ -87,7 +88,7 @@ describe('~/editor/editor_ci_config_ext', () => {
});
expect(getConfiguredYmlSchema()).toEqual({
uri: `/${mockProjectNamespace}/${mockProjectPath}/-/schema/master/${EXTENSION_CI_SCHEMA_FILE_NAME_MATCH}`,
uri: `${TEST_HOST}/${mockProjectNamespace}/${mockProjectPath}/-/schema/master/${EXTENSION_CI_SCHEMA_FILE_NAME_MATCH}`,
fileMatch: ['another-ci-filename.yml'],
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment