-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-mobile.js
48 lines (41 loc) · 1.2 KB
/
run-mobile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { exec } = require('child_process')
const os = require('os')
const createTestCafe = require('testcafe')
let runner = null
let testcafe = null
const run = platform => {
createTestCafe(os.hostname())
.then(tc => {
testcafe = tc
runner = testcafe.createRunner()
return testcafe.createBrowserConnection()
})
.then(remoteConnection => {
const testCommands = {
ios: `/usr/bin/xcrun simctl boot "iPhone X"; /usr/bin/xcrun simctl openurl booted ${
remoteConnection.url
}`,
android: `$ANDROID_HOME/platform-tools/adb shell am start -a "android.intent.action.VIEW" -d ${
remoteConnection.url
}`,
}
console.log('Starting browser', remoteConnection.url)
exec(testCommands[platform])
remoteConnection.once('ready', () => {
runner
.src('tests/**/*.js')
.browsers(remoteConnection)
.run()
.then(() => {
testcafe.close()
})
})
})
}
const PLATFORMS = ['ios', 'android']
const platform = process.argv[2]
if (PLATFORMS.indexOf(platform) > -1) {
run(platform)
} else {
throw new Error(`Usage: node run.js ${PLATFORMS.join('|')} `)
}