From e9812d3a74a4f37ef0e77d29561b8be2aff2aa71 Mon Sep 17 00:00:00 2001 From: Vadim Kovalenko Date: Wed, 25 Oct 2023 11:24:42 +0300 Subject: [PATCH] Fix codefactor issue in saveArticles test --- test/unit/saveArticles.test.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/test/unit/saveArticles.test.ts b/test/unit/saveArticles.test.ts index d96240d1..7ccbcb03 100644 --- a/test/unit/saveArticles.test.ts +++ b/test/unit/saveArticles.test.ts @@ -317,18 +317,25 @@ describe('saveArticles', () => { const { downloader } = await setupScrapeClasses() // en wikipedia const _moduleDependencies = await downloader.getModuleDependencies('Potato') - // next variables declared to avoid "variable is not defined" errors + let RLCONF: any - // eslint-disable-next-line @typescript-eslint/no-unused-vars let RLSTATE: any - // eslint-disable-next-line @typescript-eslint/no-unused-vars let RLPAGEMODULES: any - // eslint-disable-next-line @typescript-eslint/no-unused-vars + const document: any = { documentElement: { className: '' }, cookie: '' } - // eslint-disable-next-line no-eval - eval(_moduleDependencies.jsConfigVars) - expect(RLCONF).toMatchObject({ + // Create a new function that sets the values + const setJsConfigVars = new Function(` + return function(RLCONF, RLSTATE, RLPAGEMODULES, document) { + ${_moduleDependencies.jsConfigVars} + return { RLCONF, RLSTATE, RLPAGEMODULES }; + }; + `)() + + // Execute the created function + const { RLCONF: updatedRLCONF } = setJsConfigVars(RLCONF, RLSTATE, RLPAGEMODULES, document) + + expect(updatedRLCONF).toMatchObject({ wgPageName: 'Potato', wgTitle: 'Potato', wgPageContentLanguage: 'en',