Skip to content

Instantly share code, notes, and snippets.

@piatra
Last active July 18, 2020 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piatra/8ae69dba1ed457455aa507df3bf8be82 to your computer and use it in GitHub Desktop.
Save piatra/8ae69dba1ed457455aa507df3bf8be82 to your computer and use it in GitHub Desktop.
wip bug 1618356
diff --git a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_docs.js b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_docs.js
index 7aff1422288a..6809d0093617 100644
--- a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_docs.js
+++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_docs.js
@@ -18,7 +18,7 @@ add_task(async function test_sma_docs() {
let request = await fetch(TEST_URL);
let docs = await request.text();
let headings = getHeadingsFromDocs(docs);
- const schemaTypes = (await fetchSMASchema).anyOf.map(
+ const schemaTypes = (await fetchSMASchema()).anyOf.map(
s => s.properties.type.enum[0]
);
for (let schemaType of schemaTypes) {
diff --git a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/head.js b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/head.js
index 72c129c8b1b2..6c8ab49c9bd1 100644
--- a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/head.js
+++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/head.js
@@ -19,7 +19,7 @@ ChromeUtils.defineModuleGetter(
"resource://testing-common/ajv-4.1.1.js"
);
-XPCOMUtils.defineLazyGetter(this, "fetchSMASchema", async () => {
+async function fetchSMASchema() {
const response = await fetch(
"resource://testing-common/SpecialMessageActionSchemas.json"
);
@@ -28,6 +28,12 @@ XPCOMUtils.defineLazyGetter(this, "fetchSMASchema", async () => {
throw new Error("Failed to load SpecialMessageActionSchemas");
}
return schema.definitions.SpecialMessageActionSchemas;
+}
+
+XPCOMUtils.defineLazyGetter(this, "fetchValidator", async () => {
+ const ajv = new Ajv({ async: "co*" });
+ const schema = await fetchSMASchema();
+ return ajv.compile(schema);
});
const EXAMPLE_URL = "https://example.com/";
@@ -38,9 +44,7 @@ const SMATestUtils = {
* @param {SpecialMessageAction} action
*/
async validateAction(action) {
- const schema = await fetchSMASchema;
- const ajv = new Ajv({ async: "co*" });
- const validator = ajv.compile(schema);
+ const validator = await fetchValidator;
if (!validator(action)) {
throw new Error(`Action with type ${action.type} was not valid.`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment