From 491614c7f8cfa50b902d0275064e611c2a48c3b2 Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Sat, 11 Sep 2021 23:31:08 +0200 Subject: [PATCH] fix(types): allow evaluate functions to take a readonly array as an argument (#7072) --- 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..b400f44b5fb47 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 = 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 () {