Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Switch babel to typescript #753

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
{
"extends": "@appium/eslint-config-appium",
"extends": ["@appium/eslint-config-appium-ts"],
"overrides": [
{
"files": "test/**/*.js",
"rules": {
"func-names": "off"
"func-names": "off",
"@typescript-eslint/no-var-requires": "off"
}
},
{
"files": "Scripts/**/*.js",
"parserOptions": {"sourceType": "script"},
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
},
{
"files": "ci-jobs/scripts/*.js",
"parserOptions": {"sourceType": "script"},
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
]
],
"rules": {
"require-await": "error"
}
}
7 changes: 7 additions & 0 deletions .github/workflows/functional-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,12 @@ jobs:
npm install
mkdir -p ./Resources/WebDriverAgent.bundle
name: Install dev dependencies

- run: |
target_sim_id=$(xcrun simctl list devices available | grep "$DEVICE_NAME (" | cut -d "(" -f2 | cut -d ")" -f1)
open -Fn "$(xcode-select -p)/Applications/Simulator.app"
xcrun simctl bootstatus $target_sim_id -b
name: Preboot Simulator

- run: npm run e2e-test
name: Run functional tests
2 changes: 1 addition & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
require: ['@babel/register'],
require: ['ts-node/register'],
forbidOnly: Boolean(process.env.CI)
};
25 changes: 0 additions & 25 deletions babel.config.json

This file was deleted.

7 changes: 3 additions & 4 deletions lib/check-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ async function checkForDependencies () {
return false;
}

async function bundleWDASim (xcodebuild, opts = {}) {
async function bundleWDASim (xcodebuild) {
if (xcodebuild && !_.isFunction(xcodebuild.retrieveDerivedDataPath)) {
xcodebuild = new XcodeBuild();
opts = xcodebuild;
xcodebuild = new XcodeBuild('', {});
}

const derivedDataPath = await xcodebuild.retrieveDerivedDataPath();
const wdaBundlePath = path.join(derivedDataPath, 'Build', 'Products', 'Debug-iphonesimulator', WDA_RUNNER_APP);
if (await fs.exists(wdaBundlePath)) {
return wdaBundlePath;
}
await buildWDASim(xcodebuild, opts);
await buildWDASim();
return wdaBundlePath;
}

Expand Down
17 changes: 10 additions & 7 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ CODE_SIGN_IDENTITY = ${signingId}
* @param {DeviceInfo} deviceInfo
* @param {string} sdkVersion - The Xcode SDK version of OS.
* @param {string} bootstrapPath - The folder path containing xctestrun file.
* @param {string} wdaRemotePort - The remote port WDA is listening on.
* @return {string} returns xctestrunFilePath for given device
* @param {number|string} wdaRemotePort - The remote port WDA is listening on.
* @return {Promise<string>} returns xctestrunFilePath for given device
* @throws if WebDriverAgentRunner_iphoneos${sdkVersion|platformVersion}-arm64.xctestrun for real device
* or WebDriverAgentRunner_iphonesimulator${sdkVersion|platformVersion}-x86_64.xctestrun for simulator is not found @bootstrapPath,
* then it will throw file not found exception
Expand All @@ -207,7 +207,7 @@ async function setXctestrunFile (deviceInfo, sdkVersion, bootstrapPath, wdaRemot
/**
* Return the WDA object which appends existing xctest runner content
* @param {string} platformName - The name of the platform
* @param {string} version - The Xcode SDK version of OS.
* @param {number|string} wdaRemotePort - The remote port number
* @return {object} returns a runner object which has USE_PORT
*/
function getAdditionalRunContent (platformName, wdaRemotePort) {
Expand All @@ -228,6 +228,7 @@ function getAdditionalRunContent (platformName, wdaRemotePort) {
* @param {DeviceInfo} deviceInfo
* @param {string} sdkVersion - The Xcode SDK version of OS.
* @param {string} bootstrapPath - The folder path containing xctestrun file.
* @returns {Promise<string>}
*/
async function getXctestrunFilePath (deviceInfo, sdkVersion, bootstrapPath) {
// First try the SDK path, for Xcode 10 (at least)
Expand Down Expand Up @@ -256,9 +257,11 @@ async function getXctestrunFilePath (deviceInfo, sdkVersion, bootstrapPath) {
}
}

log.errorAndThrow(`If you are using 'useXctestrunFile' capability then you ` +
throw new Error(
`If you are using 'useXctestrunFile' capability then you ` +
`need to have a xctestrun file (expected: ` +
`'${path.resolve(bootstrapPath, getXctestrunFileName(deviceInfo, sdkVersion))}')`);
`'${path.resolve(bootstrapPath, getXctestrunFileName(deviceInfo, sdkVersion))}')`
);
}


Expand Down Expand Up @@ -316,7 +319,7 @@ function randomInt (low, high) {
/**
* Retrieves WDA upgrade timestamp
*
* @return {?number} The UNIX timestamp of the package manifest. The manifest only gets modified on
* @return {Promise<number?>} The UNIX timestamp of the package manifest. The manifest only gets modified on
* package upgrade.
*/
async function getWDAUpgradeTimestamp () {
Expand Down Expand Up @@ -356,7 +359,7 @@ async function resetTestProcesses (udid, isSimulator) {
* listening on given port, and is expected to return
* either true or false to include/exclude the corresponding PID
* from the resulting array.
* @returns {Array<string>} - the list of matched process ids.
* @returns {Promise<string[]>} - the list of matched process ids.
*/
async function getPIDsListeningOnPort (port, filteringFunc = null) {
const result = [];
Expand Down
23 changes: 14 additions & 9 deletions lib/webdriveragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class WebDriverAgent {

/**
* Return boolean if WDA is running or not
* @return {boolean} True if WDA is running
* @return {Promise<boolean>} True if WDA is running
* @throws {Error} If there was invalid response code or body
*/
async isRunning () {
Expand Down Expand Up @@ -183,7 +183,7 @@ class WebDriverAgent {
* }
* }
*
* @return {?object} State Object
* @return {Promise<any?>} State Object
* @throws {Error} If there was invalid response code or body
*/
async getStatus () {
Expand Down Expand Up @@ -234,7 +234,7 @@ class WebDriverAgent {
const box = strongbox(packageInfo.name);
let boxItem = box.getItem(RECENT_MODULE_VERSION_ITEM_NAME);
if (!boxItem) {
const timestampPath = path.resolve(process.env.HOME, WDA_UPGRADE_TIMESTAMP_PATH);
const timestampPath = path.resolve(process.env.HOME ?? '', WDA_UPGRADE_TIMESTAMP_PATH);
if (await fs.exists(timestampPath)) {
// TODO: It is probably a bit ugly to hardcode the recent version string,
// TODO: hovewer it should do the job as a temporary transition trick
Expand Down Expand Up @@ -279,6 +279,7 @@ class WebDriverAgent {
`(${recentModuleVersion} < ${packageInfo.version})`
);
try {
// @ts-ignore xcodebuild should be set
await this.xcodebuild.cleanProject();
await boxItem.write(packageInfo.version);
} catch (e) {
Expand All @@ -289,7 +290,7 @@ class WebDriverAgent {
/**
* Launch WDA with preinstalled package without xcodebuild.
* @param {string} sessionId Launch WDA and establish the session with this sessionId
* @return {?object} State Object
* @return {Promise<any?>} State Object
*/
async launchWithPreinstalledWDA(sessionId) {
const xctestEnv = {
Expand Down Expand Up @@ -330,7 +331,7 @@ class WebDriverAgent {
* }
*
* @param {string} sessionId Launch WDA and establish the session with this sessionId
* @return {?object} State Object
* @return {Promise<any?>} State Object
* @throws {Error} If there was invalid response code or body
*/
async launch (sessionId) {
Expand Down Expand Up @@ -374,12 +375,15 @@ class WebDriverAgent {
return await this.startWithIDB();
}

// @ts-ignore xcodebuild should be set
await this.xcodebuild.init(this.noSessionProxy);

// Start the xcodebuild process
if (this.prebuildWDA) {
// @ts-ignore xcodebuild should be set
await this.xcodebuild.prebuild();
}
// @ts-ignore xcodebuild should be set
return await this.xcodebuild.start();
}

Expand Down Expand Up @@ -463,7 +467,9 @@ class WebDriverAgent {
}
} else if (!this.args.webDriverAgentUrl) {
this.log.info('Shutting down sub-processes');
// @ts-ignore xcodebuild should be set
await this.xcodebuild.quit();
// @ts-ignore xcodebuild should be set
await this.xcodebuild.reset();
} else {
this.log.debug('Do not stop xcodebuild nor XCTest session ' +
Expand Down Expand Up @@ -504,23 +510,22 @@ class WebDriverAgent {
return this.started;
}

set fullyStarted (started = false) {
this.started = started;
set fullyStarted (started) {
this.started = started ?? false;
}

async retrieveDerivedDataPath () {
if (this.canSkipXcodebuild) {
return;
}
// @ts-ignore xcodebuild should be set
return await this.xcodebuild.retrieveDerivedDataPath();
}

/**
* Reuse running WDA if it has the same bundle id with updatedWDABundleId.
* Or reuse it if it has the default id without updatedWDABundleId.
* Uninstall it if the method faces an exception for the above situation.
*
* @param {string} updatedWDABundleId BundleId you'd like to use
*/
async setupCaching () {
const status = await this.getStatus();
Expand Down
Loading
Loading