-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
508be0d
commit 66ef392
Showing
7 changed files
with
154 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ lib/ | |
jest-report.json | ||
drivers/ | ||
/docs/api.json | ||
.android-sdk/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
SDKDIR=$PWD/.android-sdk | ||
export ANDROID_SDK_ROOT=${SDKDIR} | ||
export ANDROID_HOME=${SDKDIR} | ||
export ANDROID_AVD_HOME=${SDKDIR}/avd | ||
|
||
mkdir ${SDKDIR} | ||
mkdir ${SDKDIR}/cmdline-tools | ||
|
||
echo Downloading Android SDK... | ||
cd ${SDKDIR}/cmdline-tools | ||
curl https://dl.google.com/android/repository/commandlinetools-mac-6858069_latest.zip -o commandlinetools-mac-6858069_latest.zip | ||
unzip commandlinetools-mac-6858069_latest.zip | ||
mv cmdline-tools latest | ||
|
||
echo Installing emulator... | ||
yes | ${SDKDIR}/cmdline-tools/latest/bin/sdkmanager platform-tools emulator | ||
|
||
echo Installing system image... | ||
${SDKDIR}/cmdline-tools/latest/bin/sdkmanager "system-images;android-30;google_apis;x86" | ||
|
||
echo Installing platform SDK... | ||
${SDKDIR}/cmdline-tools/latest/bin/sdkmanager "platforms;android-30" | ||
|
||
echo Starting ADB... | ||
${SDKDIR}/platform-tools/adb devices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
SDKDIR=$PWD/.android-sdk | ||
export ANDROID_SDK_ROOT=${SDKDIR} | ||
export ANDROID_HOME=${SDKDIR} | ||
export ANDROID_AVD_HOME=${SDKDIR}/avd | ||
|
||
${SDKDIR}/cmdline-tools/latest/bin/avdmanager delete avd --name android30 | ||
echo -ne '\n' | ${SDKDIR}/cmdline-tools/latest/bin/avdmanager create avd --name android30 --device pixel_4_xl --package "system-images;android-30;google_apis;x86" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
SDKDIR=$PWD/.android-sdk | ||
export ANDROID_SDK_ROOT=${SDKDIR} | ||
export ANDROID_HOME=${SDKDIR} | ||
export ANDROID_AVD_HOME=${SDKDIR}/avd | ||
|
||
${SDKDIR}/emulator/emulator -avd android30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const { _clank } = require('..'); | ||
const assert = require('assert'); | ||
const childProcess = require('child_process'); | ||
const path = require('path'); | ||
const readline = require('readline'); | ||
|
||
(async () => { | ||
setTimeout(() => { | ||
console.error('Timed out starting emulator'); | ||
process.exit(1); | ||
}, 60000); | ||
const proc = childProcess.spawn(path.join(process.cwd(), '.android-sdk/emulator/emulator'), ['-no-window', '-avd', 'android30', '-verbose'], { | ||
env: { | ||
...process.env, | ||
ANDROID_SDK_ROOT: path.join(process.cwd(), '.android-sdk'), | ||
ANDROID_HOME: path.join(process.cwd(), '.android-sdk'), | ||
} | ||
}); | ||
proc.stdout.on('data', data => console.log(data.toString())); | ||
proc.stderr.on('data', data => console.log(data.toString())); | ||
await waitForLine(proc, /boot completed/); | ||
|
||
const context = await _clank.launchPersistentContext(''); | ||
const [page] = context.pages(); | ||
await page.goto('data:text/html,<title>Hello world</title>'); | ||
assert(await page.title() === 'Hello world'); | ||
await context.close(); | ||
process.exit(0); | ||
})(); | ||
|
||
async function waitForLine(proc, regex) { | ||
return new Promise((resolve, reject) => { | ||
const rl = readline.createInterface({ input: proc.stdout }); | ||
const failError = new Error('Process failed to launch!'); | ||
rl.on('line', onLine); | ||
rl.on('close', reject.bind(null, failError)); | ||
proc.on('exit', reject.bind(null, failError)); | ||
proc.on('error', reject.bind(null, failError)); | ||
|
||
function onLine(line) { | ||
const match = line.match(regex); | ||
if (!match) | ||
return; | ||
resolve(match); | ||
} | ||
}); | ||
} |