Skip to content

Commit 001e2f3

Browse files
authored
Add VSCode launch configurations (appium#10683)
* Added debug, attach to debug, test-all, and test-current-file * The debug and attach to debug allow you to run Appium server * Made some changes to how package.json is located to support being able to run Mocha tests directly from 'test/' instead of from 'build/test/'
1 parent 812a6bf commit 001e2f3

File tree

7 files changed

+71
-11
lines changed

7 files changed

+71
-11
lines changed

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ coverage/
55
commands-yml/
66
docs/
77
sample-code/
8+
.vscode/
89

910
_vimrc_local.vim
1011
*.swp

.vscode/launch.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug",
6+
"type": "node",
7+
"request": "launch",
8+
"cwd": "${workspaceFolder}",
9+
"console": "integratedTerminal",
10+
"args": [
11+
"."
12+
]
13+
},
14+
{
15+
"name": "Attach Debug",
16+
"type": "node",
17+
"request": "attach",
18+
"cwd": "${workspaceFolder}",
19+
"port": 9229
20+
},
21+
{
22+
"name": "Test All",
23+
"type": "node",
24+
"request": "launch",
25+
"program": "${workspaceFolder}/node_modules/.bin/_mocha",
26+
"args": [
27+
"--require", "babel-core/register",
28+
"--timeout", "999999",
29+
"--colors",
30+
"${workspaceFolder}/test"
31+
]
32+
},
33+
{
34+
"name": "Test Current File",
35+
"type": "node",
36+
"request": "launch",
37+
"program": "${workspaceFolder}/node_modules/.bin/_mocha",
38+
"args": [
39+
"--require", "babel-core/register",
40+
"--timeout", "999999",
41+
"--colors",
42+
"${file}"
43+
]
44+
}
45+
]
46+
}

docs/en/contributing-to-appium/appium-from-source.md

+13
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,19 @@ Appium is running in another window with `node .`) with:
177177
npm run e2e-test
178178
```
179179
180+
### Debugging Node
181+
182+
This project has multiple launch configurations for running NodeJS code from within [VSCode](https://code.visualstudio.com/)
183+
184+
* _Debug_: Runs Appium server in debug mode so you can set breakpoints inside VSCode source files
185+
* _Attach Debug_: Attach to a currently running Appium server
186+
* Example Usage
187+
* From root, run `node --inspect-brk . --port 5555`
188+
* Run `attach debug`
189+
* Setup breakpoints in VSCode
190+
* _Test All_: Runs all mocha tests in `test/`. Can setup breakpoints in test code and source code
191+
* _Test Current File_: Runs the currently focused-on mocha file. Fails if it's not valid mocha test
192+
180193
### Committing code
181194
182195
Each Appium package installs a pre-commit hook which will run the [linter](https://eslint.org/) and

lib/config.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import _ from 'lodash';
22
import path from 'path';
33
import { mkdirp, fs } from 'appium-support';
44
import { exec } from 'teen_process';
5+
import { rootDir } from './utils';
56
import logger from './logger';
6-
import pkgObj from '../../package.json'; // eslint-disable-line import/no-unresolved
77

8-
9-
const APPIUM_VER = pkgObj.version;
8+
const APPIUM_VER = require(path.resolve(rootDir, 'package.json')).version;
109

1110
function getNodeVersion () {
1211
// expect v<major>.<minor>.<patch>
@@ -16,10 +15,9 @@ function getNodeVersion () {
1615
}
1716

1817
async function getGitRev () {
19-
let cwd = path.resolve(__dirname, "..", "..");
2018
let rev = null;
2119
try {
22-
let {stdout} = await exec("git", ["rev-parse", "HEAD"], {cwd});
20+
let {stdout} = await exec("git", ["rev-parse", "HEAD"], {rootDir});
2321
rev = stdout.trim();
2422
} catch (ign) {}
2523
return rev;

lib/parser.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import _ from 'lodash';
44
import { ArgumentParser } from 'argparse';
5-
import pkgObj from '../../package.json'; // eslint-disable-line import/no-unresolved
6-
5+
import { rootDir } from './utils';
76

87
const args = [
98
[['--shell'], {
@@ -801,7 +800,7 @@ function parseDefaultCaps (caps) {
801800

802801
function getParser () {
803802
let parser = new ArgumentParser({
804-
version: pkgObj.version,
803+
version: require(path.resolve(rootDir, 'package.json')).version,
805804
addHelp: true,
806805
description: 'A webdriver-compatible server for use with native and hybrid iOS and Android applications.',
807806
prog: process.argv[1] || 'Appium'

lib/utils.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash';
22
import logger from './logger';
33
import { processCapabilities, BaseDriver } from 'appium-base-driver';
4-
4+
import findRoot from 'find-root';
55

66
function inspectObject (args) {
77
function getValueArray (obj, indent = ' ') {
@@ -149,4 +149,6 @@ function insertAppiumPrefixes (caps) {
149149
return prefixedCaps;
150150
}
151151

152-
export { inspectObject, parseCapsForInnerDriver, insertAppiumPrefixes };
152+
const rootDir = findRoot(__dirname);
153+
154+
export { inspectObject, parseCapsForInnerDriver, insertAppiumPrefixes, rootDir };

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"bluebird": "3.x",
5454
"continuation-local-storage": "3.x",
5555
"dateformat": "^3.0.3",
56+
"find-root": "^1.1.0",
5657
"lodash": "4.x",
5758
"npmlog": "4.x",
5859
"request": "^2.81.0",
@@ -84,7 +85,7 @@
8485
"appium-gulp-plugins": "2.x",
8586
"babel-cli": "^6.26.0",
8687
"babel-eslint": "7.x",
87-
"babel-preset-env": "^1.6.0",
88+
"babel-preset-env": "^1.7.0",
8889
"chai": "4.x",
8990
"chai-as-promised": "7.x",
9091
"eslint": "3.x",

0 commit comments

Comments
 (0)