@azure/microsoft-playwright-testing 1.0.0-alpha.20250212.1 → 1.0.0-alpha.20250213.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -99,7 +99,6 @@ const getServiceConfig = (config, options) => {
|
|
|
99
99
|
playwrightServiceConfig.setOptions(options);
|
|
100
100
|
(0, utils_1.emitReportingUrl)();
|
|
101
101
|
const globalFunctions = {};
|
|
102
|
-
performOneTimeOperation(options);
|
|
103
102
|
if ((options === null || options === void 0 ? void 0 : options.serviceAuthType) === constants_1.ServiceAuth.ACCESS_TOKEN) {
|
|
104
103
|
// mpt PAT requested and set by the customer, no need to setup entra lifecycle handlers
|
|
105
104
|
(0, utils_1.validateMptPAT)(utils_1.exitWithFailureMessage);
|
|
@@ -124,6 +123,7 @@ const getServiceConfig = (config, options) => {
|
|
|
124
123
|
globalFunctions.globalTeardown = require.resolve("./global/playwright-service-global-teardown");
|
|
125
124
|
}
|
|
126
125
|
}
|
|
126
|
+
performOneTimeOperation(options);
|
|
127
127
|
if ((options === null || options === void 0 ? void 0 : options.useCloudHostedBrowsers) === false) {
|
|
128
128
|
return Object.assign({}, globalFunctions);
|
|
129
129
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playwrightService.js","sourceRoot":"","sources":["../../src/core/playwrightService.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,mDAAgF;AAChF,sFAAsD;AACtD,+EAA4E;AAC5E,8FAA8D;AAE9D,0CAawB;AACxB,iDAAkE;AAGlE,MAAM,uBAAuB,GAAG,CAAC,OAA4C,EAAQ,EAAE;IACrF,MAAM,oBAAoB,GACxB,OAAO,CAAC,GAAG,CAAC,wCAA4B,CAAC,uBAAuB,CAAC,KAAK,MAAM,CAAC;IAC/E,IAAI,oBAAoB;QAAE,OAAO;IACjC,OAAO,CAAC,GAAG,CAAC,wCAA4B,CAAC,uBAAuB,CAAC,GA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xC,aAAa,EAAE,uBAAuB,CAAC,aAAa;gBACpD,MAAM,EAAE,uBAAuB,CAAC,MAAM;aACvC;SACF,IACE,eAAe,EAClB;AACJ,CAAC,CAAC;AAsDO,4CAAgB;AApDzB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,iBAAiB,GAAG,KAAK,EAC7B,OAAqE,EACrC,EAAE;IAClC,MAAM,uBAAuB,GAAG,IAAI,iDAAuB,EAAE,CAAC;IAC9D,uBAAuB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAE5C,MAAM,KAAK,GAAG,MAAM,IAAA,kCAA0B,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAC,CAAC;IACpE,OAAO;QACL,UAAU,EAAE,IAAA,4BAAoB,EAC9B,uBAAuB,CAAC,KAAK,EAC7B,uBAAuB,CAAC,SAAS,CAClC;QACD,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,KAAK,EAAE;gBAChC,sBAAsB,EAAE,uCAAuC,IAAA,yBAAiB,GAAE,EAAE;aACrF;YACD,OAAO,EAAE,uBAAuB,CAAC,OAAO;YACxC,aAAa,EAAE,uBAAuB,CAAC,aAAa;YACpD,MAAM,EAAE,uBAAuB,CAAC,MAAM;SACvC;KACF,CAAC;AACJ,CAAC,CAAC;AAEyB,8CAAiB","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { InternalEnvironmentVariables, ServiceAuth } from \"../common/constants\";\nimport customerConfig from \"../common/customerConfig\";\nimport { PlaywrightServiceConfig } from \"../common/playwrightServiceConfig\";\nimport playwrightServiceEntra from \"./playwrightServiceEntra\";\nimport type { PlaywrightServiceAdditionalOptions, BrowserConnectOptions } from \"../common/types\";\nimport {\n emitReportingUrl,\n fetchOrValidateAccessToken,\n getAccessToken,\n getServiceWSEndpoint,\n validateMptPAT,\n warnIfAccessTokenCloseToExpiry,\n validatePlaywrightVersion,\n validateServiceUrl,\n exitWithFailureMessage,\n getPackageVersion,\n getPlaywrightVersion,\n getVersionInfo,\n} from \"../utils/utils\";\nimport { ServiceErrorMessageConstants } from \"../common/messages\";\nimport type { PlaywrightTestConfig } from \"@playwright/test\";\n\nconst performOneTimeOperation = (options?: PlaywrightServiceAdditionalOptions): void => {\n const oneTimeOperationFlag =\n process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] === \"true\";\n if (oneTimeOperationFlag) return;\n process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] = \"true\";\n if (options?.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {\n warnIfAccessTokenCloseToExpiry();\n }\n};\n/**\n * @public\n *\n * Generate playwright configuration integrated with Microsoft Playwright Testing.\n *\n * @param config - base playwright configuration\n * @param options - additional options for the service\n * @returns PlaywrightConfig\n *\n * @example\n * ```\n * import { defineConfig } from \"playwright/test\";\n * import { getServiceConfig } from \"@azure/microsoft-playwright-testing\";\n * import playwrightConfig from \"./playwright.config\";\n *\n * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig));\n * ```\n *\n * @example\n * ```\n * import { defineConfig } from \"playwright/test\";\n * import { getServiceConfig, ServiceOS } from \"@azure/microsoft-playwright-testing\";\n * import playwrightConfig from \"./playwright.config\";\n *\n * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig, {\n * runId: \"custom run id\",\n * os: ServiceOS.WINDOWS\n * }));\n * ```\n */\nconst getServiceConfig = (\n config: PlaywrightTestConfig,\n options?: PlaywrightServiceAdditionalOptions,\n): PlaywrightTestConfig => {\n validatePlaywrightVersion();\n validateServiceUrl();\n const playwrightVersionInfo = getVersionInfo(getPlaywrightVersion());\n const isMultipleGlobalFileSupported =\n playwrightVersionInfo.major >= 1 && playwrightVersionInfo.minor >= 49;\n if (options?.credential) {\n playwrightServiceEntra.entraIdAccessToken = options.credential;\n }\n\n // if global setup/teardown is string -\n // 1. if multiple global file is supported, convert it to array\n // 2. wrap playwright-service global setup/teardown with customer provided global setup/teardown\n\n // if global setup/teardown is array -\n // 1. if multiple global file is not supported, throw error\n // 2. append playwright-service global setup/teardown with customer provided global setup/teardown\n if (config && config.globalSetup) {\n if (typeof config.globalSetup === \"string\") {\n if (isMultipleGlobalFileSupported) {\n customerConfig.globalSetup = [config.globalSetup];\n } else {\n customerConfig.globalSetup = config.globalSetup;\n }\n } else {\n if (!isMultipleGlobalFileSupported) {\n throw new Error(\n ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message,\n );\n }\n customerConfig.globalSetup = config.globalSetup;\n }\n }\n\n if (config && config.globalTeardown) {\n if (typeof config.globalTeardown === \"string\") {\n if (isMultipleGlobalFileSupported) {\n customerConfig.globalTeardown = [config.globalTeardown];\n } else {\n customerConfig.globalTeardown = config.globalTeardown;\n }\n } else {\n if (!isMultipleGlobalFileSupported) {\n throw new Error(\n ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message,\n );\n }\n customerConfig.globalTeardown = config.globalTeardown;\n }\n }\n\n const playwrightServiceConfig = new PlaywrightServiceConfig();\n playwrightServiceConfig.setOptions(options);\n emitReportingUrl();\n\n const globalFunctions: any = {};\n performOneTimeOperation(options);\n if (options?.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {\n // mpt PAT requested and set by the customer, no need to setup entra lifecycle handlers\n validateMptPAT(exitWithFailureMessage);\n } else {\n // If multiple global file is supported, append playwright-service global setup/teardown with customer provided global setup/teardown\n if (isMultipleGlobalFileSupported) {\n globalFunctions.globalSetup = [] as string[];\n globalFunctions.globalTeardown = [] as string[];\n if (customerConfig.globalSetup) {\n globalFunctions.globalSetup.push(...(customerConfig.globalSetup as string[]));\n }\n if (customerConfig.globalTeardown) {\n globalFunctions.globalTeardown.push(...(customerConfig.globalTeardown as string[]));\n }\n globalFunctions.globalSetup.push(require.resolve(\"./global/playwright-service-global-setup\"));\n globalFunctions.globalTeardown.push(\n require.resolve(\"./global/playwright-service-global-teardown\"),\n );\n } else {\n // If multiple global file is not supported, wrap playwright-service global setup/teardown with customer provided global setup/teardown\n globalFunctions.globalSetup = require.resolve(\"./global/playwright-service-global-setup\");\n globalFunctions.globalTeardown = require.resolve(\n \"./global/playwright-service-global-teardown\",\n );\n }\n }\n\n if (options?.useCloudHostedBrowsers === false) {\n return {\n ...globalFunctions,\n };\n }\n if (!process.env[InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED]) {\n process.env[InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED] = \"true\";\n console.log(\"\\nRunning tests using Microsoft Playwright Testing service.\");\n }\n\n return {\n use: {\n connectOptions: {\n wsEndpoint: getServiceWSEndpoint(\n playwrightServiceConfig.runId,\n playwrightServiceConfig.serviceOs,\n ),\n headers: {\n Authorization: `Bearer ${getAccessToken()}`,\n \"x-ms-package-version\": `@azure/microsoft-playwright-testing/${getPackageVersion()}`,\n },\n timeout: playwrightServiceConfig.timeout,\n exposeNetwork: playwrightServiceConfig.exposeNetwork,\n slowMo: playwrightServiceConfig.slowMo,\n },\n },\n ...globalFunctions,\n };\n};\n\n/**\n * @public\n *\n * Get connect options required to connect to Microsoft Playwright Testing's cloud hosted browsers.\n *\n * @param options - additional options for the service\n * @returns BrowserConnectOptions\n *\n * @example\n * ```\n * import playwright, { test, expect, BrowserType } from \"@playwright/test\";\n * import { getConnectOptions } from \"@azure/microsoft-playwright-testing\";\n *\n * test('has title', async ({ browserName }) => {\n * const { wsEndpoint, options } = await getConnectOptions();\n * const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);\n * const context = await browser.newContext();\n * const page = await context.newPage();\n *\n * await page.goto('https://playwright.dev/');\n * await expect(page).toHaveTitle(/Playwright/);\n *\n * await page.close();\n * await context.close();\n * await browser.close();\n * });\n * ```\n */\nconst getConnectOptions = async (\n options?: Omit<PlaywrightServiceAdditionalOptions, \"serviceAuthType\">,\n): Promise<BrowserConnectOptions> => {\n const playwrightServiceConfig = new PlaywrightServiceConfig();\n playwrightServiceConfig.setOptions(options);\n\n const token = await fetchOrValidateAccessToken(options?.credential);\n return {\n wsEndpoint: getServiceWSEndpoint(\n playwrightServiceConfig.runId,\n playwrightServiceConfig.serviceOs,\n ),\n options: {\n headers: {\n Authorization: `Bearer ${token}`,\n \"x-ms-package-version\": `@azure/microsoft-playwright-testing/${getPackageVersion()}`,\n },\n timeout: playwrightServiceConfig.timeout,\n exposeNetwork: playwrightServiceConfig.exposeNetwork,\n slowMo: playwrightServiceConfig.slowMo,\n },\n };\n};\n\nexport { getServiceConfig, getConnectOptions };\n"]}
|
|
1
|
+
{"version":3,"file":"playwrightService.js","sourceRoot":"","sources":["../../src/core/playwrightService.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAElC,mDAAgF;AAChF,sFAAsD;AACtD,+EAA4E;AAC5E,8FAA8D;AAE9D,0CAawB;AACxB,iDAAkE;AAGlE,MAAM,uBAAuB,GAAG,CAAC,OAA4C,EAAQ,EAAE;IACrF,MAAM,oBAAoB,GACxB,OAAO,CAAC,GAAG,CAAC,wCAA4B,CAAC,uBAAuB,CAAC,KAAK,MAAM,CAAC;IAC/E,IAAI,oBAAoB;QAAE,OAAO;IACjC,OAAO,CAAC,GAAG,CAAC,wCAA4B,CAAC,uBAAuB,CAAC,GAAG,MAAM,CAAC;IAC3E,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,MAAK,uBAAW,CAAC,YAAY,EAAE,CAAC;QAC1D,IAAA,sCAA8B,GAAE,CAAC;IACnC,CAAC;AACH,CAAC,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,gBAAgB,GAAG,CACvB,MAA4B,EAC5B,OAA4C,EACtB,EAAE;IACxB,IAAA,iCAAyB,GAAE,CAAC;IAC5B,IAAA,0BAAkB,GAAE,CAAC;IACrB,MAAM,qBAAqB,GAAG,IAAA,sB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B,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAC,CAAC;IACpE,OAAO;QACL,UAAU,EAAE,IAAA,4BAAoB,EAC9B,uBAAuB,CAAC,KAAK,EAC7B,uBAAuB,CAAC,SAAS,CAClC;QACD,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,KAAK,EAAE;gBAChC,sBAAsB,EAAE,uCAAuC,IAAA,yBAAiB,GAAE,EAAE;aACrF;YACD,OAAO,EAAE,uBAAuB,CAAC,OAAO;YACxC,aAAa,EAAE,uBAAuB,CAAC,aAAa;YACpD,MAAM,EAAE,uBAAuB,CAAC,MAAM;SACvC;KACF,CAAC;AACJ,CAAC,CAAC;AAEyB,8CAAiB","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { InternalEnvironmentVariables, ServiceAuth } from \"../common/constants\";\nimport customerConfig from \"../common/customerConfig\";\nimport { PlaywrightServiceConfig } from \"../common/playwrightServiceConfig\";\nimport playwrightServiceEntra from \"./playwrightServiceEntra\";\nimport type { PlaywrightServiceAdditionalOptions, BrowserConnectOptions } from \"../common/types\";\nimport {\n emitReportingUrl,\n fetchOrValidateAccessToken,\n getAccessToken,\n getServiceWSEndpoint,\n validateMptPAT,\n warnIfAccessTokenCloseToExpiry,\n validatePlaywrightVersion,\n validateServiceUrl,\n exitWithFailureMessage,\n getPackageVersion,\n getPlaywrightVersion,\n getVersionInfo,\n} from \"../utils/utils\";\nimport { ServiceErrorMessageConstants } from \"../common/messages\";\nimport type { PlaywrightTestConfig } from \"@playwright/test\";\n\nconst performOneTimeOperation = (options?: PlaywrightServiceAdditionalOptions): void => {\n const oneTimeOperationFlag =\n process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] === \"true\";\n if (oneTimeOperationFlag) return;\n process.env[InternalEnvironmentVariables.ONE_TIME_OPERATION_FLAG] = \"true\";\n if (options?.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {\n warnIfAccessTokenCloseToExpiry();\n }\n};\n/**\n * @public\n *\n * Generate playwright configuration integrated with Microsoft Playwright Testing.\n *\n * @param config - base playwright configuration\n * @param options - additional options for the service\n * @returns PlaywrightConfig\n *\n * @example\n * ```\n * import { defineConfig } from \"playwright/test\";\n * import { getServiceConfig } from \"@azure/microsoft-playwright-testing\";\n * import playwrightConfig from \"./playwright.config\";\n *\n * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig));\n * ```\n *\n * @example\n * ```\n * import { defineConfig } from \"playwright/test\";\n * import { getServiceConfig, ServiceOS } from \"@azure/microsoft-playwright-testing\";\n * import playwrightConfig from \"./playwright.config\";\n *\n * export default defineConfig(playwrightConfig, getServiceConfig(playwrightConfig, {\n * runId: \"custom run id\",\n * os: ServiceOS.WINDOWS\n * }));\n * ```\n */\nconst getServiceConfig = (\n config: PlaywrightTestConfig,\n options?: PlaywrightServiceAdditionalOptions,\n): PlaywrightTestConfig => {\n validatePlaywrightVersion();\n validateServiceUrl();\n const playwrightVersionInfo = getVersionInfo(getPlaywrightVersion());\n const isMultipleGlobalFileSupported =\n playwrightVersionInfo.major >= 1 && playwrightVersionInfo.minor >= 49;\n if (options?.credential) {\n playwrightServiceEntra.entraIdAccessToken = options.credential;\n }\n\n // if global setup/teardown is string -\n // 1. if multiple global file is supported, convert it to array\n // 2. wrap playwright-service global setup/teardown with customer provided global setup/teardown\n\n // if global setup/teardown is array -\n // 1. if multiple global file is not supported, throw error\n // 2. append playwright-service global setup/teardown with customer provided global setup/teardown\n if (config && config.globalSetup) {\n if (typeof config.globalSetup === \"string\") {\n if (isMultipleGlobalFileSupported) {\n customerConfig.globalSetup = [config.globalSetup];\n } else {\n customerConfig.globalSetup = config.globalSetup;\n }\n } else {\n if (!isMultipleGlobalFileSupported) {\n throw new Error(\n ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message,\n );\n }\n customerConfig.globalSetup = config.globalSetup;\n }\n }\n\n if (config && config.globalTeardown) {\n if (typeof config.globalTeardown === \"string\") {\n if (isMultipleGlobalFileSupported) {\n customerConfig.globalTeardown = [config.globalTeardown];\n } else {\n customerConfig.globalTeardown = config.globalTeardown;\n }\n } else {\n if (!isMultipleGlobalFileSupported) {\n throw new Error(\n ServiceErrorMessageConstants.MULTIPLE_SETUP_FILE_PLAYWRIGHT_VERSION_ERROR.message,\n );\n }\n customerConfig.globalTeardown = config.globalTeardown;\n }\n }\n\n const playwrightServiceConfig = new PlaywrightServiceConfig();\n playwrightServiceConfig.setOptions(options);\n emitReportingUrl();\n\n const globalFunctions: any = {};\n\n if (options?.serviceAuthType === ServiceAuth.ACCESS_TOKEN) {\n // mpt PAT requested and set by the customer, no need to setup entra lifecycle handlers\n validateMptPAT(exitWithFailureMessage);\n } else {\n // If multiple global file is supported, append playwright-service global setup/teardown with customer provided global setup/teardown\n if (isMultipleGlobalFileSupported) {\n globalFunctions.globalSetup = [] as string[];\n globalFunctions.globalTeardown = [] as string[];\n if (customerConfig.globalSetup) {\n globalFunctions.globalSetup.push(...(customerConfig.globalSetup as string[]));\n }\n if (customerConfig.globalTeardown) {\n globalFunctions.globalTeardown.push(...(customerConfig.globalTeardown as string[]));\n }\n globalFunctions.globalSetup.push(require.resolve(\"./global/playwright-service-global-setup\"));\n globalFunctions.globalTeardown.push(\n require.resolve(\"./global/playwright-service-global-teardown\"),\n );\n } else {\n // If multiple global file is not supported, wrap playwright-service global setup/teardown with customer provided global setup/teardown\n globalFunctions.globalSetup = require.resolve(\"./global/playwright-service-global-setup\");\n globalFunctions.globalTeardown = require.resolve(\n \"./global/playwright-service-global-teardown\",\n );\n }\n }\n performOneTimeOperation(options);\n if (options?.useCloudHostedBrowsers === false) {\n return {\n ...globalFunctions,\n };\n }\n if (!process.env[InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED]) {\n process.env[InternalEnvironmentVariables.MPT_CLOUD_HOSTED_BROWSER_USED] = \"true\";\n console.log(\"\\nRunning tests using Microsoft Playwright Testing service.\");\n }\n\n return {\n use: {\n connectOptions: {\n wsEndpoint: getServiceWSEndpoint(\n playwrightServiceConfig.runId,\n playwrightServiceConfig.serviceOs,\n ),\n headers: {\n Authorization: `Bearer ${getAccessToken()}`,\n \"x-ms-package-version\": `@azure/microsoft-playwright-testing/${getPackageVersion()}`,\n },\n timeout: playwrightServiceConfig.timeout,\n exposeNetwork: playwrightServiceConfig.exposeNetwork,\n slowMo: playwrightServiceConfig.slowMo,\n },\n },\n ...globalFunctions,\n };\n};\n\n/**\n * @public\n *\n * Get connect options required to connect to Microsoft Playwright Testing's cloud hosted browsers.\n *\n * @param options - additional options for the service\n * @returns BrowserConnectOptions\n *\n * @example\n * ```\n * import playwright, { test, expect, BrowserType } from \"@playwright/test\";\n * import { getConnectOptions } from \"@azure/microsoft-playwright-testing\";\n *\n * test('has title', async ({ browserName }) => {\n * const { wsEndpoint, options } = await getConnectOptions();\n * const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);\n * const context = await browser.newContext();\n * const page = await context.newPage();\n *\n * await page.goto('https://playwright.dev/');\n * await expect(page).toHaveTitle(/Playwright/);\n *\n * await page.close();\n * await context.close();\n * await browser.close();\n * });\n * ```\n */\nconst getConnectOptions = async (\n options?: Omit<PlaywrightServiceAdditionalOptions, \"serviceAuthType\">,\n): Promise<BrowserConnectOptions> => {\n const playwrightServiceConfig = new PlaywrightServiceConfig();\n playwrightServiceConfig.setOptions(options);\n\n const token = await fetchOrValidateAccessToken(options?.credential);\n return {\n wsEndpoint: getServiceWSEndpoint(\n playwrightServiceConfig.runId,\n playwrightServiceConfig.serviceOs,\n ),\n options: {\n headers: {\n Authorization: `Bearer ${token}`,\n \"x-ms-package-version\": `@azure/microsoft-playwright-testing/${getPackageVersion()}`,\n },\n timeout: playwrightServiceConfig.timeout,\n exposeNetwork: playwrightServiceConfig.exposeNetwork,\n slowMo: playwrightServiceConfig.slowMo,\n },\n };\n};\n\nexport { getServiceConfig, getConnectOptions };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/microsoft-playwright-testing",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20250213.1",
|
|
4
4
|
"description": "Package to integrate your Playwright test suite with Microsoft Playwright Testing service",
|
|
5
5
|
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/playwrighttesting/microsoft-playwright-testing/README.md",
|
|
6
6
|
"sdk-type": "client",
|