From 77b65e170fc80ff38bf34e2e687beca7d05711ec Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Thu, 8 Apr 2021 19:28:37 +0200 Subject: [PATCH] fix(types): allow evaluate functions to take a readonly array as an argument --- src/common/EvalTypes.ts | 2 +- test/frame.spec.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/common/EvalTypes.ts b/src/common/EvalTypes.ts index 200cf70129ab3..74b59f39b2c4d 100644 --- a/src/common/EvalTypes.ts +++ b/src/common/EvalTypes.ts @@ -54,7 +54,7 @@ export type Serializable = /** * @public */ -export type JSONArray = Serializable[]; +export type JSONArray = Serializable[] | readonly Serializable[]; /** * @public diff --git a/test/frame.spec.ts b/test/frame.spec.ts index 269da7d7f1be8..f1310f6905dfd 100644 --- a/test/frame.spec.ts +++ b/test/frame.spec.ts @@ -79,6 +79,17 @@ describe('Frame specs', function () { 'Execution context is not available in detached frame' ); }); + + it('allows readonly array to be an argument', async () => { + const { page, server } = getTestState(); + await page.goto(server.EMPTY_PAGE); + const mainFrame = page.mainFrame(); + + // This test checks if Frame.evaluate allows a readonly array to be an argument. + // See https://github.com/puppeteer/puppeteer/issues/6953. + const readonlyArray: readonly string[] = ['a', 'b', 'c']; + mainFrame.evaluate((arr) => arr, readonlyArray); + }); }); describe('Frame Management', function () {