@react-native-windows/automation 0.2.19 → 0.3.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.
@@ -5,9 +5,10 @@
5
5
  * @format
6
6
  */
7
7
  /// <reference types="webdriverio/webdriverio-core" />
8
- import NodeEnvironment = require('jest-environment-node');
8
+ import NodeEnvironment from 'jest-environment-node';
9
9
  import { RemoteOptions } from 'webdriverio';
10
- import { Config } from '@jest/types';
10
+ import { JestEnvironmentConfig } from '@jest/environment';
11
+ import type { EnvironmentContext } from '@jest/environment';
11
12
  export declare type EnvironmentOptions = {
12
13
  /**
13
14
  * The application to launch. Can be a path to an exe, or a package identity
@@ -32,7 +33,7 @@ export default class AutomationEnvironment extends NodeEnvironment {
32
33
  private winAppDriverProcess;
33
34
  private browser;
34
35
  private automationClient;
35
- constructor(config: Config.ProjectConfig);
36
+ constructor(config: JestEnvironmentConfig, context: EnvironmentContext);
36
37
  setup(): Promise<void>;
37
38
  teardown(): Promise<void>;
38
39
  }
@@ -37,14 +37,14 @@ const child_process_1 = require("child_process");
37
37
  const fs_1 = __importDefault(require("@react-native-windows/fs"));
38
38
  const path_1 = __importDefault(require("path"));
39
39
  const readline_sync_1 = __importDefault(require("readline-sync"));
40
- const NodeEnvironment = require("jest-environment-node");
40
+ const jest_environment_node_1 = __importDefault(require("jest-environment-node"));
41
41
  const webdriverio = __importStar(require("webdriverio"));
42
42
  const automation_channel_1 = require("@react-native-windows/automation-channel");
43
- class AutomationEnvironment extends NodeEnvironment {
44
- constructor(config) {
43
+ class AutomationEnvironment extends jest_environment_node_1.default {
44
+ constructor(config, context) {
45
45
  var _a;
46
- super(config);
47
- const passedOptions = config.testEnvironmentOptions;
46
+ super(config, context);
47
+ const passedOptions = config.projectConfig.testEnvironmentOptions;
48
48
  if (!passedOptions.app) {
49
49
  throw new Error('"app" must be specified in testEnvironmentOptions');
50
50
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AutomationEnvironment.js","s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,CAAC,sBAAsB,CAAC,EAAE;gBACtC,OAAO,CAAC,OAAO,CAAC,CAAC;aAClB;iBAAM,IAAI,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE;gBAC7C,MAAM,CAAC,IAAI,KAAK,CAAC,gCAAgC,GAAG,CAAC,CAAC,CAAC,CAAC;aACzD;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE;YAChC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE;YAC9B,MAAM,CACJ,IAAI,KAAK,CACP,sDAAsD,QAAQ,GAAG,CAClE,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,OAAe;IACrC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC5B,OAAO,OAAO,CAAC;KAChB;IAED,IAAI;QACF,MAAM,iBAAiB,GAAG,IAAA,wBAAQ,EAChC,qCAAqC,OAAO,qBAAqB,CAClE;aACE,QAAQ,EAAE;aACV,IAAI,EAAE,CAAC;QAEV,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;YAClC,iBAAiB;YACjB,MAAM,IAAI,KAAK,EAAE,CAAC;SACnB;QAED,OAAO,GAAG,iBAAiB,MAAM,CAAC;KACnC;IAAC,WAAM;QACN,MAAM,IAAI,KAAK,CAAC,6CAA6C,OAAO,GAAG,CAAC,CAAC;KAC1E;AACH,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport chalk from 'chalk';\nimport {execSync, spawn, ChildProcess} from 'child_process';\nimport fs from '@react-native-windows/fs';\nimport path from 'path';\nimport readlineSync from 'readline-sync';\n\nimport NodeEnvironment = require('jest-environment-node');\n\nimport * as webdriverio from 'webdriverio';\nimport {BrowserObject, RemoteOptions} from 'webdriverio';\nimport {Config} from '@jest/types';\nimport {\n waitForConnection,\n AutomationClient,\n} from '@react-native-windows/automation-channel';\n\nexport type EnvironmentOptions = {\n /**\n * The application to launch. Can be a path to an exe, or a package identity\n * name (e.g. Microsoft.WindowsAlarms)\n */\n app?: string;\n\n /**\n * Arguments to be passed to your application when launched\n */\n appArguments?: string;\n\n enableAutomationChannel?: boolean;\n automationChannelPort?: number;\n winAppDriverBin?: string;\n breakOnStart?: boolean;\n webdriverOptions?: RemoteOptions;\n};\n\ntype AutomationChannelOptions = {\n enable: boolean;\n port: number;\n};\n\nexport default class AutomationEnvironment extends NodeEnvironment {\n private readonly webDriverOptions: RemoteOptions;\n private readonly channelOptions: AutomationChannelOptions;\n private readonly winappdriverBin: string;\n private readonly breakOnStart: boolean;\n private winAppDriverProcess: ChildProcess | undefined;\n private browser: BrowserObject | undefined;\n private automationClient: AutomationClient | undefined;\n\n constructor(config: Config.ProjectConfig) {\n super(config);\n const passedOptions: EnvironmentOptions = config.testEnvironmentOptions;\n\n if (!passedOptions.app) {\n throw new Error('\"app\" must be specified in testEnvironmentOptions');\n }\n\n this.winappdriverBin =\n passedOptions.winAppDriverBin ||\n path.join(\n process.env['PROGRAMFILES(X86)']!,\n 'Windows Application Driver\\\\WinAppDriver.exe',\n );\n\n if (!fs.existsSync(this.winappdriverBin)) {\n throw new Error(\n `Could not find WinAppDriver at searched location: \"${this.winappdriverBin}\"`,\n );\n }\n\n const baseOptions: RemoteOptions = {\n port: 4723,\n capabilities: {\n app: resolveAppName(passedOptions.app),\n\n ...(passedOptions.appArguments && {\n appArguments: passedOptions.appArguments,\n }),\n\n // @ts-ignore\n 'ms:experimental-webdriver': true,\n },\n // Level of logging verbosity: trace | debug | info | warn | error\n logLevel: 'error',\n\n // Default timeout for all waitFor* commands.\n waitforTimeout: 30000,\n\n // Default timeout in milliseconds for request\n connectionRetryTimeout: 30000,\n\n // Default request retries count\n connectionRetryCount: 5,\n };\n\n this.webDriverOptions = Object.assign(\n {},\n baseOptions,\n passedOptions.webdriverOptions,\n );\n\n this.webDriverOptions.capabilities = Object.assign(\n this.webDriverOptions.capabilities!,\n passedOptions.webdriverOptions?.capabilities,\n );\n\n this.channelOptions = {\n enable: passedOptions.enableAutomationChannel === true,\n port: passedOptions.automationChannelPort || 8603,\n };\n\n this.breakOnStart = passedOptions.breakOnStart === true;\n }\n\n async setup() {\n await super.setup();\n this.winAppDriverProcess = await spawnWinAppDriver(\n this.winappdriverBin,\n this.webDriverOptions.port!,\n );\n\n this.browser = await webdriverio.remote(this.webDriverOptions);\n\n if (this.breakOnStart) {\n readlineSync.question(\n chalk.bold.yellow('Breaking before tests start\\n') +\n 'Press Enter to resume...',\n );\n }\n\n if (this.channelOptions.enable) {\n this.automationClient = await waitForConnection({\n port: this.channelOptions.port,\n });\n this.global.automationClient = this.automationClient;\n }\n\n this.global.remote = webdriverio.remote;\n this.global.browser = this.browser;\n this.global.$ = this.browser.$.bind(this.browser);\n this.global.$$ = this.browser.$$.bind(this.browser);\n }\n\n async teardown() {\n if (this.browser) {\n await this.browser.deleteSession();\n }\n\n if (this.automationClient) {\n this.automationClient.close();\n }\n\n this.winAppDriverProcess?.kill('SIGINT');\n await super.teardown();\n }\n}\n\n/**\n * Starts a WinAppdriver process and resolves a promise with the process once\n * it is ready to accept commands\n *\n * Inspired-by/stolen from https://github.com/licanhua/wdio-winappdriver-service\n */\nasync function spawnWinAppDriver(\n winappdriverBin: string,\n port: number,\n): Promise<ChildProcess> {\n if (!fs.existsSync(winappdriverBin)) {\n throw new Error(\n `Could not locate WinAppDriver binary at \"${winappdriverBin}\"`,\n );\n }\n\n return new Promise((resolve, reject) => {\n const process = spawn(winappdriverBin, [port.toString()], {stdio: 'pipe'});\n\n process.stdout.on('data', data => {\n const s = data.toString('utf16le');\n if (s.includes('Press ENTER to exit.')) {\n resolve(process);\n } else if (s.includes('Failed to initialize')) {\n reject(new Error('Failed to start WinAppDriver: ' + s));\n }\n });\n\n process.stderr.once('data', err => {\n console.warn(err);\n });\n\n process.once('exit', exitCode => {\n reject(\n new Error(\n `WinAppDriver CLI exited before timeout (exit code: ${exitCode})`,\n ),\n );\n });\n });\n}\n\n/**\n * Convert a package identity or path to exe to the form expected by a WinAppDriver capability\n */\nfunction resolveAppName(appName: string): string {\n if (appName.endsWith('.exe')) {\n return appName;\n }\n\n try {\n const packageFamilyName = execSync(\n `powershell (Get-AppxPackage -Name ${appName}).PackageFamilyName`,\n )\n .toString()\n .trim();\n\n if (packageFamilyName.length === 0) {\n // Rethrown below\n throw new Error();\n }\n\n return `${packageFamilyName}!App`;\n } catch {\n throw new Error(`Could not locate a package with identity \"${appName}\"`);\n }\n}\n"]}
1
+ {"version":3,"file":"AutomationEnvironment.js","sourceRoot":"","sources":["../src/AutomationEnvironment.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAA0B;AAC1B,iDAA4D;AAC5D,kEAA0C;AAC1C,gDAAwB;AACxB,kEAAyC;AAEzC,kFAAoD;AACpD,yDAA2C;AAI3C,iFAGkD;AA0BlD,MAAqB,qBAAsB,SAAQ,+BAAe;IAShE,YAAY,MAA6B,EAAE,OAA2B;;QACpE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvB,MAAM,aAAa,GACjB,MAAM,CAAC,aAAa,CAAC,sBAAsB,CAAC;QAE9C,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;SACtE;QAED,IAAI,CAAC,eAAe;YAClB,aAAa,CAAC,eAAe;gBAC7B,cAAI,CAAC,IAAI,CACP,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAE,EACjC,8CAA8C,CAC/C,CAAC;QAEJ,IAAI,CAAC,YAAE,CAAC,UAAU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,CAAC,MAAM,CAAC,EAAE;QAC5B,OAAO,OAAO,CAAC;KAChB;IAED,IAAI;QACF,MAAM,iBAAiB,GAAG,IAAA,wBAAQ,EAChC,qCAAqC,OAAO,qBAAqB,CAClE;aACE,QAAQ,EAAE;aACV,IAAI,EAAE,CAAC;QAEV,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;YAClC,iBAAiB;YACjB,MAAM,IAAI,KAAK,EAAE,CAAC;SACnB;QAED,OAAO,GAAG,iBAAiB,MAAM,CAAC;KACnC;IAAC,WAAM;QACN,MAAM,IAAI,KAAK,CAAC,6CAA6C,OAAO,GAAG,CAAC,CAAC;KAC1E;AACH,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport chalk from 'chalk';\nimport {execSync, spawn, ChildProcess} from 'child_process';\nimport fs from '@react-native-windows/fs';\nimport path from 'path';\nimport readlineSync from 'readline-sync';\n\nimport NodeEnvironment from 'jest-environment-node';\nimport * as webdriverio from 'webdriverio';\nimport {BrowserObject, RemoteOptions} from 'webdriverio';\nimport {JestEnvironmentConfig} from '@jest/environment';\nimport type {EnvironmentContext} from '@jest/environment';\nimport {\n waitForConnection,\n AutomationClient,\n} from '@react-native-windows/automation-channel';\n\nexport type EnvironmentOptions = {\n /**\n * The application to launch. Can be a path to an exe, or a package identity\n * name (e.g. Microsoft.WindowsAlarms)\n */\n app?: string;\n\n /**\n * Arguments to be passed to your application when launched\n */\n appArguments?: string;\n\n enableAutomationChannel?: boolean;\n automationChannelPort?: number;\n winAppDriverBin?: string;\n breakOnStart?: boolean;\n webdriverOptions?: RemoteOptions;\n};\n\ntype AutomationChannelOptions = {\n enable: boolean;\n port: number;\n};\n\nexport default class AutomationEnvironment extends NodeEnvironment {\n private readonly webDriverOptions: RemoteOptions;\n private readonly channelOptions: AutomationChannelOptions;\n private readonly winappdriverBin: string;\n private readonly breakOnStart: boolean;\n private winAppDriverProcess: ChildProcess | undefined;\n private browser: BrowserObject | undefined;\n private automationClient: AutomationClient | undefined;\n\n constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {\n super(config, context);\n const passedOptions: EnvironmentOptions =\n config.projectConfig.testEnvironmentOptions;\n\n if (!passedOptions.app) {\n throw new Error('\"app\" must be specified in testEnvironmentOptions');\n }\n\n this.winappdriverBin =\n passedOptions.winAppDriverBin ||\n path.join(\n process.env['PROGRAMFILES(X86)']!,\n 'Windows Application Driver\\\\WinAppDriver.exe',\n );\n\n if (!fs.existsSync(this.winappdriverBin)) {\n throw new Error(\n `Could not find WinAppDriver at searched location: \"${this.winappdriverBin}\"`,\n );\n }\n\n const baseOptions: RemoteOptions = {\n port: 4723,\n capabilities: {\n app: resolveAppName(passedOptions.app),\n\n ...(passedOptions.appArguments && {\n appArguments: passedOptions.appArguments,\n }),\n\n // @ts-ignore\n 'ms:experimental-webdriver': true,\n },\n // Level of logging verbosity: trace | debug | info | warn | error\n logLevel: 'error',\n\n // Default timeout for all waitFor* commands.\n waitforTimeout: 30000,\n\n // Default timeout in milliseconds for request\n connectionRetryTimeout: 30000,\n\n // Default request retries count\n connectionRetryCount: 5,\n };\n\n this.webDriverOptions = Object.assign(\n {},\n baseOptions,\n passedOptions.webdriverOptions,\n );\n\n this.webDriverOptions.capabilities = Object.assign(\n this.webDriverOptions.capabilities!,\n passedOptions.webdriverOptions?.capabilities,\n );\n\n this.channelOptions = {\n enable: passedOptions.enableAutomationChannel === true,\n port: passedOptions.automationChannelPort || 8603,\n };\n\n this.breakOnStart = passedOptions.breakOnStart === true;\n }\n\n async setup() {\n await super.setup();\n this.winAppDriverProcess = await spawnWinAppDriver(\n this.winappdriverBin,\n this.webDriverOptions.port!,\n );\n\n this.browser = await webdriverio.remote(this.webDriverOptions);\n\n if (this.breakOnStart) {\n readlineSync.question(\n chalk.bold.yellow('Breaking before tests start\\n') +\n 'Press Enter to resume...',\n );\n }\n\n if (this.channelOptions.enable) {\n this.automationClient = await waitForConnection({\n port: this.channelOptions.port,\n });\n this.global.automationClient = this.automationClient;\n }\n\n this.global.remote = webdriverio.remote;\n this.global.browser = this.browser;\n this.global.$ = this.browser.$.bind(this.browser);\n this.global.$$ = this.browser.$$.bind(this.browser);\n }\n\n async teardown() {\n if (this.browser) {\n await this.browser.deleteSession();\n }\n\n if (this.automationClient) {\n this.automationClient.close();\n }\n\n this.winAppDriverProcess?.kill('SIGINT');\n await super.teardown();\n }\n}\n\n/**\n * Starts a WinAppdriver process and resolves a promise with the process once\n * it is ready to accept commands\n *\n * Inspired-by/stolen from https://github.com/licanhua/wdio-winappdriver-service\n */\nasync function spawnWinAppDriver(\n winappdriverBin: string,\n port: number,\n): Promise<ChildProcess> {\n if (!fs.existsSync(winappdriverBin)) {\n throw new Error(\n `Could not locate WinAppDriver binary at \"${winappdriverBin}\"`,\n );\n }\n\n return new Promise((resolve, reject) => {\n const process = spawn(winappdriverBin, [port.toString()], {stdio: 'pipe'});\n\n process.stdout.on('data', data => {\n const s = data.toString('utf16le');\n if (s.includes('Press ENTER to exit.')) {\n resolve(process);\n } else if (s.includes('Failed to initialize')) {\n reject(new Error('Failed to start WinAppDriver: ' + s));\n }\n });\n\n process.stderr.once('data', err => {\n console.warn(err);\n });\n\n process.once('exit', exitCode => {\n reject(\n new Error(\n `WinAppDriver CLI exited before timeout (exit code: ${exitCode})`,\n ),\n );\n });\n });\n}\n\n/**\n * Convert a package identity or path to exe to the form expected by a WinAppDriver capability\n */\nfunction resolveAppName(appName: string): string {\n if (appName.endsWith('.exe')) {\n return appName;\n }\n\n try {\n const packageFamilyName = execSync(\n `powershell (Get-AppxPackage -Name ${appName}).PackageFamilyName`,\n )\n .toString()\n .trim();\n\n if (packageFamilyName.length === 0) {\n // Rethrown below\n throw new Error();\n }\n\n return `${packageFamilyName}!App`;\n } catch {\n throw new Error(`Could not locate a package with identity \"${appName}\"`);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-windows/automation",
3
- "version": "0.2.19",
3
+ "version": "0.3.1",
4
4
  "description": "UI Automation Suite for React Native Windows Applications",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "repository": "https://github.com/microsoft/react-native-windows",
@@ -14,8 +14,8 @@
14
14
  "watch": "rnw-scripts watch"
15
15
  },
16
16
  "dependencies": {
17
- "@react-native-windows/automation-channel": "^0.4.8",
18
- "@react-native-windows/fs": "^0.0.0-canary.7",
17
+ "@react-native-windows/automation-channel": "^0.5.1",
18
+ "@react-native-windows/fs": "^0.0.0-canary.8",
19
19
  "@typescript-eslint/eslint-plugin": "^5.30.5",
20
20
  "@typescript-eslint/parser": "^5.30.5",
21
21
  "chalk": "^4.1.2",
@@ -23,11 +23,13 @@
23
23
  "webdriverio": "^6.9.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@jest/types": "^26.6.2",
26
+ "@jest/create-cache-key-function": "^29.0.3",
27
+ "@jest/environment": "^29.3.0",
28
+ "@jest/types": "^29.2.1",
27
29
  "@rnw-scripts/eslint-config": "1.1.14",
28
- "@rnw-scripts/just-task": "2.2.6",
30
+ "@rnw-scripts/just-task": "2.3.0",
29
31
  "@rnw-scripts/ts-config": "2.0.2",
30
- "@types/jest": "^26.0.20",
32
+ "@types/jest": "^29.2.2",
31
33
  "@types/node": "^14.14.22",
32
34
  "@types/readline-sync": "^1.4.4",
33
35
  "eslint": "^8.19.0",
@@ -35,8 +37,8 @@
35
37
  "typescript": "^4.4.4"
36
38
  },
37
39
  "peerDependencies": {
38
- "jest": ">=26.0.0",
39
- "jest-environment-node": ">=26.0.0"
40
+ "jest": ">=29.0.3",
41
+ "jest-environment-node": ">=29.2.2"
40
42
  },
41
43
  "files": [
42
44
  "lib-commonjs",