From 4986ed03989ad334d847bf6ad6be8d44ee0a57fe Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Tue, 24 Sep 2019 09:14:13 +0200 Subject: [PATCH 1/2] Test schema with "properties" and "additionalProperties". MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently fails with "oops – TypeError: Attempted to assign to readonly property.". --- integration/basic.test.js | 36 +++++++++++++++++++ integration/schemas/additionalProperties.json | 4 +++ 2 files changed, 40 insertions(+) create mode 100644 integration/schemas/additionalProperties.json diff --git a/integration/basic.test.js b/integration/basic.test.js index 11b01de..c73e111 100644 --- a/integration/basic.test.js +++ b/integration/basic.test.js @@ -13,6 +13,22 @@ const browser = puppeteer.launch({ headless: false }); const rootUrl = "http://localhost:3000/public/index.html"; +// Returns a promise that rejects and fails the test when the page produces an +// error message on the console, and never resolves (so don't await it but +// combine it using Promise.race() - if you don't, the test will still fail, but +// you'll get an UnhandledPromiseRejectionWarning from node). +function failOnErrorMessage(page) { + return new Promise((resolve, reject) => { + page.on('console', msg => { + if ((msg.type() === "error" && !msg.location().url.includes('favicon.ico')) || msg.text().startsWith('oops')) { + Promise.all(msg.args().map(h => h.evaluate(a => a.toString()))) + .then(args => expect({"console message": args}).toBeUndefined()) + .catch(e => reject(e)); + } + }); + }); +} + beforeAll( async () => { await server }, 50000 ); afterAll( async () => { ( await server ).close(); @@ -103,3 +119,23 @@ test('pretty big schema', async () => { expect(results).toContain( 'All documents and attachments related to the contract, including any notices.' ); }); + +test('additionalProperties', async () => { + const page = await ( await browser ).newPage(); + let errorOccurred = failOnErrorMessage(page); + + await page.goto( rootUrl + "#/integration/schemas/additionalProperties.json"); + + async function textAtPath(path) { + let element = await page.waitFor(path); + return await element.evaluate(e => e.textContent.trim()); + } + await Promise.race([ + Promise.all([ + expect(textAtPath('#doc .box .signature:nth-child(2) .property-name')).resolves.toBe('foo'), + expect(textAtPath('#doc .box .signature:nth-child(3) .property-name')).resolves.toBe('bar'), + expect(textAtPath('#doc .box .signature:nth-child(4) .box .signature-type')).resolves.toBe('boolean') + ]), + errorOccurred + ]); +}); diff --git a/integration/schemas/additionalProperties.json b/integration/schemas/additionalProperties.json new file mode 100644 index 0000000..c8527b1 --- /dev/null +++ b/integration/schemas/additionalProperties.json @@ -0,0 +1,4 @@ +{ + "properties": {"foo": {}, "bar": {}}, + "additionalProperties": {"type": "boolean"} +} From fa2c34f7dfb26d35ab29e56fcfa9c653f5762517 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Tue, 24 Sep 2019 10:08:51 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Fix=20"oops=20=E2=80=93=20TypeError:=20Atte?= =?UTF-8?q?mpted=20to=20assign=20to=20readonly=20property."?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error is encountered when rendering a schema containing both "properties" and "additionalProperties" and occurs because the "name" helper is invoked with Handlebars' nullContext, a read-only empty object. Checking for "additionalProperties" and then rendering "../additionalProperties" makes no sense. I'm not sure why this worked previously (apparently the parent context was the same as the current context at some point), it seems to have been broken in 7d17a0d where many dependencies were updated over several major versions. --- public/templates/box.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/templates/box.html b/public/templates/box.html index c39369d..e560a9e 100644 --- a/public/templates/box.html +++ b/public/templates/box.html @@ -142,7 +142,7 @@
additional
- {{schema ../additionalProperties}} + {{schema additionalProperties}}