Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

ReferenceError: _config is not defined #690

@cutterbl

Description

@cutterbl

Running my tests, and using the DEBUG=pw:api, my tests are running, but each test ultimately fails, stating ReferenceError: _config is not defined, with no further details. My setup does a login, in the globalSetup, then grabs all necessary storage bits to apply to contexts in tests. Initial pass I was originally creating a new browser, context, and page in a beforeEach, but am now trying to do this the jest-playwright way, which is when I started getting this error.

Here's the basics of my setup on macOS 10.14.6:

devDependencies:

 "@babel/core": "7.14.0", "@babel/plugin-transform-runtime": "7.13.15", "@babel/preset-env": "7.14.1", "babel-jest": "26.6.3", "config": "3.3.6", "core-js": "3.11.2", "expect-playwright": "0.3.4", "jest": "26.6.3", "jest-playwright-preset": "1.5.2", "playwright": "1.10.0", "prettier": "2.2.1", "regenerator-runtime": "0.13.7" 

Babel config:

{ "presets": [ [ "@babel/preset-env", { "targets": { "node": "current" } } ] ], "plugins": [ "@babel/plugin-transform-runtime" ] }

jest.config.js

process.env.JEST_PLAYWRIGHT_CONFIG = './jest-playwright.config.js'; module.exports = { preset: 'jest-playwright-preset', globalSetup: './__setups__/global-setup.js', globalTeardown: './__setups__/global-teardown.js', testEnvironment: './__setups__/CustomEnvironment.js', testMatch: ['**/__tests__/**/*.js?(x)', '**/?(*.)+(spec|test).js?(x)'], transform: { '^.+\\.jsx?$': 'babel-jest', }, setupFilesAfterEnv: ['./__setups__/regenerator.js', 'expect-playwright'], };

jest-playwright.config.js

const config = require('config'); const { setup: { browsers, devices }, } = config; module.exports = { // jest-playwright config browsers, launchOptions: { headless: true, }, ...(devices && { devices }), };

regenerator.js

import "core-js/stable"; import "regenerator-runtime/runtime";

global-setup.js

import config from 'config'; import { globalSetup as playwrightGlobalSetup } from 'jest-playwright-preset'; import { chromium } from 'playwright'; import putStorageInProcess from '../src/helpers/putStorageInProcess.function'; const { protocol, domain, setup: { organization, username, password }, } = config; async function doLogin(page) { await page.goto(`${protocol}${domain}`); // fills in login form await Promise.all([ page.waitForNavigation(), page.press('input[type="password"]', 'Enter'), ]); } module.exports = async function globalSetup(globalConfig) { await playwrightGlobalSetup(globalConfig); const browser = await chromium.launch(); const context = await browser.newContext(); const page = await context.newPage(); await doLogin(page); await putStorageInProcess(page, context); };

putStorageInProcess.function.js

export default async function putStorageInProcess(page, context) { const storage = await context.storageState(); process.env.STORAGE = JSON.stringify(storage); const session = await page.evaluate(() => JSON.stringify(sessionStorage)); process.env.SESSION_STORAGE = session; const cookies = await context.cookies(); process.env.COOKIES = JSON.stringify(cookies); }

global-teardown.js looks just like example in the jest-playwright README
CustomEnvironment.js looks just like example in the jest-playwright README (and I've tried all of this with and without this)

In each of my .spec.js files, I have a beforeEach that looks like this:

beforeEach(() => { const storageState = JSON.parse(process.env.STORAGE); await jestPlaywright.resetContext({ storageState }); const sessionStorage = process.env.SESSION_STORAGE; await context.addInitScript((storage) => { if (window.location.hostname === config.domain) { const entries = JSON.parse(storage); Object.keys(entries).forEach((key) => { window.sessionStorage.setItem(key, entries[key]); }); } }, sessionStorage); const deserializedCookies = JSON.parse(process.env.COOKIES); await context.addCookies(deserializedCookies); await jestPlaywright.resetPage(); });

This applies all of my bits to maintain my login persistence across tests, and give me a fresh context and page.

Only after using the refreshContext() and refreshPage() did I start getting the error. Looking through the source code, the only reference I find is for the constructor of the PlaywrightEnvironment. And again, it's important to note that the DEBUG is showing me that all of the tests do run (under the hood) to completion, even though the final output is showing the tests failed on this ReferenceError.

Determining test suites to run... pw:api => browserType.launch started +0ms pw:api <= browserType.launch succeeded +209ms pw:api => browser.newContext started +1ms pw:api <= browser.newContext succeeded +4ms pw:api => browserContext.newPage started +0ms pw:api <= browserContext.newPage succeeded +143ms pw:api => page.goto started +0ms pw:api navigating to "https://my.domain.com", waiting until "load" +1ms pw:api navigated to "https://my.domain.com/" +819ms pw:api "load" event fired +4s pw:api <= page.goto succeeded +0ms pw:api => page.goto started +0ms pw:api navigating to "https://my.domain.com/login?returnTo=~2F", waiting until "load" +1ms pw:api "domcontentloaded" event fired +0ms pw:api navigated to "https://my.domain.com/login?returnTo=~2F" +198ms pw:api navigated to "https://my.domain.com/login/?returnTo=~2F" +52ms pw:api "domcontentloaded" event fired +312ms pw:api "load" event fired +41ms pw:api <= page.goto succeeded +0ms pw:api => page.fill started +1ms pw:api waiting for selector "input[type="text"]" +5ms pw:api selector resolved to visible <input type="text" autofocus="" maxlength="50" id="orga…/> +158ms pw:api elementHandle.fill("9") +4ms pw:api waiting for element to be visible, enabled and editable +0ms pw:api element is visible, enabled and editable +6ms pw:api <= page.fill succeeded +6ms pw:api => page.waitForNavigation started +0ms pw:api => page.click started +1ms pw:api waiting for navigation until "load" +1ms pw:api waiting for selector "text=Next" +0ms pw:api selector resolved to visible <button id="nextButton" translate="login.next" ng-click=…>Next</button> +248ms pw:api attempting click action +3ms pw:api waiting for element to be visible, enabled and stable +0ms pw:api element is visible, enabled and stable +23ms pw:api scrolling into view if needed +0ms pw:api done scrolling +1ms pw:api checking that element receives pointer events at (640,296) +1ms pw:api element does receive pointer events +3ms pw:api performing click action +1ms pw:api click action done +14ms pw:api waiting for scheduled navigations to finish +0ms pw:api navigations have finished +27ms pw:api <= page.click succeeded +0ms pw:api navigated to "https://my.domain.com/localLogin?returnTo=~2F" +48ms pw:api <= page.waitForNavigation succeeded +1ms pw:api => page.fill started +0ms pw:api navigated to "https://my.domain.com/localLogin?returnTo=~2F" +1ms pw:api waiting for selector "#username" +0ms pw:api selector resolved to visible <input type="text" id="username" ng-required="true" req…/> +4ms pw:api elementHandle.fill("cutter") +2ms pw:api waiting for element to be visible, enabled and editable +0ms pw:api element is visible, enabled and editable +4ms pw:api <= page.fill succeeded +3ms pw:api => page.fill started +0ms pw:api waiting for selector "input[type="password"]" +1ms pw:api selector resolved to visible <input id="password" type="password" ng-required="true"…/> +2ms pw:api elementHandle.fill("S4vy!22!") +1ms pw:api waiting for element to be visible, enabled and editable +0ms pw:api element is visible, enabled and editable +4ms pw:api <= page.fill succeeded +4ms pw:api => page.waitForNavigation started +0ms pw:api => page.press started +1ms pw:api waiting for navigation until "load" +0ms pw:api waiting for selector "input[type="password"]" +1ms pw:api selector resolved to visible <input id="password" type="password" ng-required="true"…/> +2ms pw:api elementHandle.press("Enter") +1ms pw:api <= page.press succeeded +8ms pw:api navigated to "https://my.domain.com/" +2s pw:api <= page.waitForNavigation succeeded +1ms pw:api => browserContext.storageState started +0ms pw:api navigated to "https://my.domain.com/" +2ms pw:api navigating to "https://my.domain.com", waiting until "load" +112ms pw:api navigated to "https://my.domain.com/" +9ms pw:api "load" event fired +1ms pw:api "domcontentloaded" event fired +0ms pw:api <= browserContext.storageState succeeded +10ms pw:api => page.evaluate started +1ms pw:api <= page.evaluate succeeded +3ms pw:api => browserContext.cookies started +1ms pw:api <= browserContext.cookies succeeded +0ms pw:api => browserType.connect started +270ms pw:api navigated to "https://my.domain.com/index" +15ms pw:api <= browserType.connect succeeded +4ms pw:api => browser.newContext started +0ms pw:api <= browser.newContext succeeded +10ms pw:api => browserContext.newPage started +1ms pw:api <= browserContext.newPage succeeded +96ms pw:api => browserContext.close started +1s pw:api navigated to "about:blank" +8ms pw:api "load" event fired +0ms pw:api "domcontentloaded" event fired +0ms pw:api navigated to "https://my.domain.com/index" +0ms pw:api <= browserContext.close succeeded +2ms pw:api => browser.newContext started +0ms pw:api navigating to "https://my.domain.com", waiting until "load" +95ms pw:api navigated to "https://my.domain.com/" +10ms pw:api "load" event fired +1ms pw:api "domcontentloaded" event fired +1ms pw:api <= browser.newContext succeeded +13ms pw:api => browserContext.newPage started +0ms pw:api <= browserContext.newPage succeeded +84ms pw:api => browserContext.addInitScript started +1ms pw:api <= browserContext.addInitScript succeeded +1ms pw:api => browserContext.addCookies started +0ms pw:api <= browserContext.addCookies succeeded +1ms pw:api => page.close started +1ms pw:api <= page.close succeeded +4ms pw:api => browserContext.newPage started +0ms pw:api <= browserContext.newPage succeeded +84ms pw:api => page.goto started +0ms pw:api navigating to "https://my.domain.com/encounter", waiting until "load" +7ms pw:api navigated to "https://my.domain.com/encounter/" +509ms pw:api "load" event fired +455ms pw:api "domcontentloaded" event fired +0ms pw:api "load" event fired +13ms pw:api <= page.goto succeeded +0ms pw:api => page.waitForResponse started +0ms pw:api "domcontentloaded" event fired +4ms pw:api <= page.waitForResponse succeeded +2s pw:api => page.waitForSelector started +1ms pw:api waiting for selector ".ui-grid-cell-contents" to be visible +4ms pw:api selector resolved to visible <div tabindex="0" role="button" col-index="renderInde…>…</div> +176ms pw:api <= page.waitForSelector succeeded +6ms pw:api => browserContext.close started +2ms pw:api <= browserContext.close succeeded +14ms pw:api => browser.newContext started +0ms pw:api navigating to "https://my.domain.com", waiting until "load" +128ms pw:api navigated to "https://my.domain.com/" +9ms pw:api "load" event fired +1ms pw:api "domcontentloaded" event fired +0ms pw:api <= browser.newContext succeeded +11ms pw:api => browserContext.newPage started +0ms pw:api <= browserContext.newPage succeeded +86ms pw:api => browserContext.addInitScript started +0ms pw:api <= browserContext.addInitScript succeeded +1ms pw:api => browserContext.addCookies started +0ms pw:api <= browserContext.addCookies succeeded +2ms pw:api => page.close started +0ms pw:api <= page.close succeeded +3ms pw:api => browserContext.newPage started +0ms pw:api <= browserContext.newPage succeeded +85ms pw:api => page.goto started +0ms pw:api navigating to "https://my.domain.com/encounter", waiting until "load" +1ms pw:api navigated to "https://my.domain.com/encounter/" +490ms pw:api "load" event fired +2s pw:api <= page.goto succeeded +1ms pw:api => page.waitForNavigation started +0ms pw:api => page.click started +2ms pw:api waiting for navigation until "load" +1ms pw:api waiting for selector "#createEncounterBtn" +2ms pw:api "domcontentloaded" event fired +0ms pw:api selector resolved to visible <button id="createEncounterBtn" href="/encounter/0/new" …>…</button> +729ms pw:api attempting click action +424ms pw:api waiting for element to be visible, enabled and stable +1ms pw:api element is visible, enabled and stable +82ms pw:api scrolling into view if needed +0ms pw:api done scrolling +1ms pw:api checking that element receives pointer events at (31,153) +1ms pw:api <div class="block-ui-overlay"></div> from <div block-ui-container="" class="block-ui-container …>…</div> subtree intercepts pointer events +3ms pw:api retrying click action, attempt #1 +0ms pw:api waiting for element to be visible, enabled and stable +0ms pw:api element is visible, enabled and stable +30ms pw:api scrolling into view if needed +0ms pw:api done scrolling +1ms pw:api checking that element receives pointer events at (31,153) +1ms pw:api <div class="block-ui-overlay"></div> from <div block-ui-container="" class="block-ui-container …>…</div> subtree intercepts pointer events +2ms pw:api retrying click action, attempt #2 +0ms pw:api waiting 20ms +0ms pw:api waiting for element to be visible, enabled and stable +22ms pw:api element is visible, enabled and stable +23ms pw:api scrolling into view if needed +0ms pw:api done scrolling +1ms pw:api checking that element receives pointer events at (31,153) +1ms pw:api <div class="block-ui-overlay"></div> from <div block-ui-container="" class="block-ui-container …>…</div> subtree intercepts pointer events +3ms pw:api retrying click action, attempt #3 +0ms pw:api waiting 100ms +0ms pw:api waiting for element to be visible, enabled and stable +102ms pw:api element is visible, enabled and stable +27ms pw:api scrolling into view if needed +0ms pw:api done scrolling +1ms pw:api checking that element receives pointer events at (31,92) +1ms pw:api <div class="block-ui-overlay"></div> from <div block-ui-container="" class="block-ui-container …>…</div> subtree intercepts pointer events +2ms pw:api retrying click action, attempt #4 +0ms pw:api waiting 100ms +0ms pw:api waiting for element to be visible, enabled and stable +212ms pw:api element is visible, enabled and stable +34ms pw:api scrolling into view if needed +1ms pw:api done scrolling +0ms pw:api checking that element receives pointer events at (31,92) +1ms pw:api <div class="block-ui-overlay"></div> from <div block-ui-container="" class="block-ui-container …>…</div> subtree intercepts pointer events +3ms pw:api retrying click action, attempt #5 +0ms pw:api waiting 500ms +0ms pw:api "networkidle" event fired +290ms pw:api waiting for element to be visible, enabled and stable +214ms pw:api element is visible, enabled and stable +24ms pw:api scrolling into view if needed +0ms pw:api done scrolling +1ms pw:api checking that element receives pointer events at (31,153) +1ms pw:api element does receive pointer events +3ms pw:api performing click action +0ms pw:api click action done +25ms pw:api waiting for scheduled navigations to finish +0ms pw:api navigations have finished +22ms pw:api <= page.click succeeded +1ms pw:api navigated to "https://my.domain.com/encounter/0/new" +138ms pw:api <= page.waitForNavigation succeeded +2ms pw:api => page.waitForSelector started +0ms pw:api navigated to "https://my.domain.com/encounter/0/new" +1ms pw:api waiting for selector "label:has-text("Person")" to be visible +1ms pw:api selector resolved to visible <label for="PersonSK">Person</label> +419ms pw:api <= page.waitForSelector succeeded +32ms pw:api => page.$ started +1ms pw:api <= page.$ succeeded +8ms pw:api => elementHandle.$ started +0ms pw:api <= elementHandle.$ succeeded +6ms pw:api => elementHandle.$ started +0ms pw:api <= elementHandle.$ succeeded +4ms pw:api => elementHandle.fill started +0ms pw:api elementHandle.fill("Derek") +1ms pw:api waiting for element to be visible, enabled and editable +0ms pw:api element is visible, enabled and editable +4ms pw:api <= elementHandle.fill succeeded +23ms pw:api => page.waitForResponse started +0ms pw:api <= page.waitForResponse succeeded +105ms pw:api => elementHandle.$ started +0ms pw:api <= elementHandle.$ succeeded +5ms pw:api => elementHandle.waitForSelector started +0ms pw:api waiting for selector "*:has-text("Derek")" +2ms pw:api selector resolved to visible <div class=" css-1mq14df">…</div> +1s pw:api <= elementHandle.waitForSelector succeeded +4ms pw:api => elementHandle.click started +0ms pw:api attempting click action +1ms pw:api waiting for element to be visible, enabled and stable +0ms pw:api element is visible, enabled and stable +35ms pw:api scrolling into view if needed +0ms pw:api done scrolling +1ms pw:api checking that element receives pointer events at (327.48,349) +1ms pw:api element does receive pointer events +4ms pw:api performing click action +0ms pw:api click action done +34ms pw:api waiting for scheduled navigations to finish +0ms pw:api navigations have finished +4ms pw:api <= elementHandle.click succeeded +0ms pw:api => page.$ started +0ms pw:api <= page.$ succeeded +6ms pw:api => elementHandle.$ started +0ms pw:api <= elementHandle.$ succeeded +5ms pw:api => elementHandle.$ started +0ms pw:api <= elementHandle.$ succeeded +4ms pw:api => elementHandle.type started +0ms pw:api elementHandle.type("imm") +1ms pw:api <= elementHandle.type succeeded +34ms pw:api => page.waitForResponse started +0ms pw:api <= page.waitForResponse succeeded +122ms pw:api => elementHandle.$ started +0ms pw:api <= elementHandle.$ succeeded +5ms pw:api => elementHandle.waitForSelector started +0ms pw:api waiting for selector "*:has-text("Immunization")" +1ms pw:api selector resolved to visible <div class=" css-1mq14df">…</div> +571ms pw:api <= elementHandle.waitForSelector succeeded +4ms pw:api => elementHandle.click started +0ms pw:api attempting click action +1ms pw:api waiting for element to be visible, enabled and stable +0ms pw:api element is visible, enabled and stable +34ms pw:api scrolling into view if needed +0ms pw:api done scrolling +1ms pw:api checking that element receives pointer events at (327.48,304) +1ms pw:api element does receive pointer events +3ms pw:api performing click action +0ms pw:api click action done +18ms pw:api waiting for scheduled navigations to finish +0ms pw:api navigations have finished +2ms pw:api <= elementHandle.click succeeded +1ms pw:api => page.waitForResponse started +0ms pw:api => page.click started +1ms pw:api waiting for selector ""Add"" +1ms pw:api selector resolved to visible <button disabled type="button" role="button" data-testid…>Add</button> +6ms pw:api attempting click action +2ms pw:api waiting for element to be visible, enabled and stable +0ms pw:api element is not enabled - waiting... +31ms pw:api element is visible, enabled and stable +479ms pw:api scrolling into view if needed +0ms pw:api done scrolling +1ms pw:api checking that element receives pointer events at (1224.98,689) +0ms pw:api element does receive pointer events +3ms pw:api performing click action +0ms pw:api click action done +21ms pw:api waiting for scheduled navigations to finish +0ms pw:api navigations have finished +1ms pw:api <= page.click succeeded +1ms pw:api <= page.waitForResponse succeeded +267ms pw:api => response.body started +0ms pw:api <= response.body succeeded +5ms pw:api => page.$ started +0ms pw:api <= page.$ succeeded +4ms pw:api => elementHandle.$ started +0ms pw:api <= elementHandle.$ succeeded +4ms pw:api => elementHandle.check started +0ms pw:api attempting click action +3ms pw:api waiting for element to be visible, enabled and stable +0ms pw:api element is not stable - waiting... +27ms pw:api element is visible, enabled and stable +270ms pw:api scrolling into view if needed +0ms pw:api done scrolling +0ms pw:api checking that element receives pointer events at (640,206) +1ms pw:api element does receive pointer events +4ms pw:api performing click action +1ms pw:api click action done +8ms pw:api waiting for scheduled navigations to finish +0ms pw:api navigations have finished +2ms pw:api <= elementHandle.check succeeded +2ms pw:api => elementHandle.$ started +0ms pw:api <= elementHandle.$ succeeded +5ms pw:api => elementHandle.click started +0ms pw:api attempting click action +1ms pw:api waiting for element to be visible, enabled and stable +0ms pw:api element is visible, enabled and stable +24ms pw:api scrolling into view if needed +0ms pw:api done scrolling +0ms pw:api checking that element receives pointer events at (1099.98,604) +1ms pw:api element does receive pointer events +3ms pw:api performing click action +0ms pw:api click action done +30ms pw:api waiting for scheduled navigations to finish +1ms pw:api navigations have finished +11ms pw:api <= elementHandle.click succeeded +0ms pw:api => page.waitForResponse started +0ms pw:api waiting for response "**/api/healthy/api/Encounter" +1ms pw:api <= page.waitForResponse succeeded +1s pw:api => response.body started +0ms pw:api navigated to "https://my.domain.com/encounter/44089" +19ms pw:api <= response.body succeeded +6ms pw:api => browserContext.close started +1ms pw:api <= browserContext.close succeeded +7ms pw:api => browser.newContext started +0ms pw:api navigating to "https://my.domain.com", waiting until "load" +107ms pw:api navigated to "https://my.domain.com/" +9ms pw:api "load" event fired +1ms pw:api "domcontentloaded" event fired +1ms pw:api <= browser.newContext succeeded +10ms pw:api => browserContext.newPage started +0ms pw:api <= browserContext.newPage succeeded +85ms pw:api => browserContext.addInitScript started +0ms pw:api <= browserContext.addInitScript succeeded +3ms pw:api => browserContext.addCookies started +0ms pw:api <= browserContext.addCookies succeeded +1ms pw:api => page.close started +0ms pw:api <= page.close succeeded +4ms pw:api => browserContext.newPage started +0ms pw:api <= browserContext.newPage succeeded +91ms pw:api => page.goto started +0ms pw:api navigating to "https://my.domain.com/encounter/44089", waiting until "load" +1ms pw:api navigated to "https://my.domain.com/encounter/44089/" +431ms pw:api "load" event fired +2s pw:api <= page.goto succeeded +1ms pw:api => page.waitForNavigation started +0ms pw:api waiting for navigation until "load" +3ms pw:api "domcontentloaded" event fired +0ms pw:api navigated to "https://my.domain.com/encounter/44089/order/58557/form" +1s pw:api <= page.waitForNavigation succeeded +1ms pw:api => page.waitForSelector started +0ms pw:api navigated to "https://my.domain.com/encounter/44089/order/58557/form" +1ms pw:api waiting for selector "button:has-text("Save and Complete")" to be visible +1ms pw:api selector resolved to visible <button id="completeOrder" disabled="disabled" primary-a…>…</button> +789ms pw:api <= page.waitForSelector succeeded +6ms pw:api => browser.close started +13ms pw:api <= browser.close succeeded +15ms 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions