Skip to content

Commit 9c3e69e

Browse files
feat: Ditch bluebird and lodash
1 parent 86469ae commit 9c3e69e

6 files changed

Lines changed: 189 additions & 148 deletions

File tree

Scripts/build-webdriveragent.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const WDA_BUNDLE_TV_PATH = path.join(DERIVED_DATA_PATH, 'Build', 'Products', 'De
2020
const TARGETS = ['runner', 'tv_runner'];
2121
const SDKS = ['sim', 'tv_sim'];
2222

23+
/**
24+
* Build WebDriverAgent and pack the app bundle into a zip archive.
25+
*
26+
* @param {string} [xcodeVersion] Xcode version to include in archive name.
27+
*/
2328
async function buildWebDriverAgent (xcodeVersion) {
2429
const target = process.env.TARGET;
2530
const sdk = process.env.SDK;
@@ -77,10 +82,12 @@ async function buildWebDriverAgent (xcodeVersion) {
7782
}
7883

7984
if (isMainModule) {
80-
buildWebDriverAgent().catch((e) => {
85+
try {
86+
await buildWebDriverAgent();
87+
} catch (e) {
8188
LOG.error(e);
8289
process.exit(1);
83-
});
90+
}
8491
}
8592

8693
export default buildWebDriverAgent;

Scripts/fetch-prebuilt-wda.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const isMainModule = process.argv[1] && path.resolve(process.argv[1]) === __file
1212

1313
const log = logger.getLogger('WDA');
1414

15+
/**
16+
* Download all prebuilt WebDriverAgent archives for the current package version.
17+
*/
1518
async function fetchPrebuiltWebDriverAgentAssets () {
1619
const packageJson = JSON.parse(readFileSync(path.resolve(__dirname, '..', 'package.json'), 'utf8'));
1720
const tag = packageJson.version;
@@ -61,10 +64,12 @@ async function fetchPrebuiltWebDriverAgentAssets () {
6164
}
6265

6366
if (isMainModule) {
64-
fetchPrebuiltWebDriverAgentAssets().catch((e) => {
67+
try {
68+
await fetchPrebuiltWebDriverAgentAssets();
69+
} catch (e) {
6570
log.error(e);
6671
process.exit(1);
67-
});
72+
}
6873
}
6974

7075
export default fetchPrebuiltWebDriverAgentAssets;

lib/check-dependencies.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,9 @@ import {WDA_SCHEME, SDK_SIMULATOR, WDA_RUNNER_APP} from './constants';
55
import {BOOTSTRAP_PATH} from './utils';
66
import type {XcodeBuild} from './xcodebuild';
77

8-
async function buildWDASim(): Promise<void> {
9-
const args = [
10-
'-project',
11-
path.join(BOOTSTRAP_PATH, 'WebDriverAgent.xcodeproj'),
12-
'-scheme',
13-
WDA_SCHEME,
14-
'-sdk',
15-
SDK_SIMULATOR,
16-
'CODE_SIGN_IDENTITY=""',
17-
'CODE_SIGNING_REQUIRED="NO"',
18-
'GCC_TREAT_WARNINGS_AS_ERRORS=0',
19-
];
20-
await exec('xcodebuild', args);
21-
}
22-
8+
/**
9+
* Ensure simulator WDA is built and return the resulting app bundle path.
10+
*/
2311
export async function bundleWDASim(xcodebuild: XcodeBuild): Promise<string> {
2412
const derivedDataPath = await xcodebuild.retrieveDerivedDataPath();
2513
if (!derivedDataPath) {
@@ -38,3 +26,18 @@ export async function bundleWDASim(xcodebuild: XcodeBuild): Promise<string> {
3826
await buildWDASim();
3927
return wdaBundlePath;
4028
}
29+
30+
async function buildWDASim(): Promise<void> {
31+
const args = [
32+
'-project',
33+
path.join(BOOTSTRAP_PATH, 'WebDriverAgent.xcodeproj'),
34+
'-scheme',
35+
WDA_SCHEME,
36+
'-sdk',
37+
SDK_SIMULATOR,
38+
'CODE_SIGN_IDENTITY=""',
39+
'CODE_SIGNING_REQUIRED="NO"',
40+
'GCC_TREAT_WARNINGS_AS_ERRORS=0',
41+
];
42+
await exec('xcodebuild', args);
43+
}

lib/utils.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ const getModuleRoot = _.memoize(function getModuleRoot(): string {
4646

4747
export const BOOTSTRAP_PATH = getModuleRoot();
4848

49+
/**
50+
* Arguments for setting xctestrun file
51+
*/
52+
export interface XctestrunFileArgs {
53+
deviceInfo: DeviceInfo;
54+
sdkVersion: string;
55+
bootstrapPath: string;
56+
wdaRemotePort: number | string;
57+
wdaBindingIP?: string;
58+
}
59+
60+
/**
61+
* Find and terminate all processes matching the given pgrep pattern.
62+
*/
4963
export async function killAppUsingPattern(pgrepPattern: string): Promise<void> {
5064
const signals = [2, 15, 9];
5165
for (const signal of signals) {
@@ -66,13 +80,16 @@ export async function killAppUsingPattern(pgrepPattern: string): Promise<void> {
6680
try {
6781
await waitForCondition(
6882
async () => {
69-
const pidCheckPromises = matchedPids.map((pid) =>
70-
exec('kill', ['-0', pid])
83+
const pidCheckPromises = matchedPids.map(async (pid) => {
84+
try {
85+
await exec('kill', ['-0', pid]);
7186
// the process is still alive
72-
.then(() => false)
87+
return false;
88+
} catch {
7389
// the process is dead
74-
.catch(() => true),
75-
);
90+
return true;
91+
}
92+
});
7693
return (await B.all(pidCheckPromises)).every((x) => x === true);
7794
},
7895
{
@@ -96,6 +113,9 @@ export function isTvOS(platformName: string): boolean {
96113
return _.toLower(platformName) === _.toLower(PLATFORM_NAME_TVOS);
97114
}
98115

116+
/**
117+
* Configure keychain access required for real-device code signing.
118+
*/
99119
export async function setRealDeviceSecurity(
100120
keychainPath: string,
101121
keychainPassword: string,
@@ -106,17 +126,6 @@ export async function setRealDeviceSecurity(
106126
await exec('security', ['set-keychain-settings', '-t', '3600', '-l', keychainPath]);
107127
}
108128

109-
/**
110-
* Arguments for setting xctestrun file
111-
*/
112-
export interface XctestrunFileArgs {
113-
deviceInfo: DeviceInfo;
114-
sdkVersion: string;
115-
bootstrapPath: string;
116-
wdaRemotePort: number | string;
117-
wdaBindingIP?: string;
118-
}
119-
120129
/**
121130
* Creates xctestrun file per device & platform version.
122131
* We expects to have WebDriverAgentRunner_iphoneos${sdkVersion|platformVersion}-arm64.xctestrun for real device

0 commit comments

Comments
 (0)