Skip to content

Commit

Permalink
Add VSCode launch configurations (appium#10683)
Browse files Browse the repository at this point in the history
* 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/'
  • Loading branch information
dpgraham authored May 15, 2018
1 parent 812a6bf commit 001e2f3
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 11 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ coverage/
commands-yml/
docs/
sample-code/
.vscode/

_vimrc_local.vim
*.swp
Expand Down
46 changes: 46 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"args": [
"."
]
},
{
"name": "Attach Debug",
"type": "node",
"request": "attach",
"cwd": "${workspaceFolder}",
"port": 9229
},
{
"name": "Test All",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/_mocha",
"args": [
"--require", "babel-core/register",
"--timeout", "999999",
"--colors",
"${workspaceFolder}/test"
]
},
{
"name": "Test Current File",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/_mocha",
"args": [
"--require", "babel-core/register",
"--timeout", "999999",
"--colors",
"${file}"
]
}
]
}
13 changes: 13 additions & 0 deletions docs/en/contributing-to-appium/appium-from-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ Appium is running in another window with `node .`) with:
npm run e2e-test
```
### Debugging Node
This project has multiple launch configurations for running NodeJS code from within [VSCode](https://code.visualstudio.com/)
* _Debug_: Runs Appium server in debug mode so you can set breakpoints inside VSCode source files
* _Attach Debug_: Attach to a currently running Appium server
* Example Usage
* From root, run `node --inspect-brk . --port 5555`
* Run `attach debug`
* Setup breakpoints in VSCode
* _Test All_: Runs all mocha tests in `test/`. Can setup breakpoints in test code and source code
* _Test Current File_: Runs the currently focused-on mocha file. Fails if it's not valid mocha test
### Committing code
Each Appium package installs a pre-commit hook which will run the [linter](https://eslint.org/) and
Expand Down
8 changes: 3 additions & 5 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import _ from 'lodash';
import path from 'path';
import { mkdirp, fs } from 'appium-support';
import { exec } from 'teen_process';
import { rootDir } from './utils';
import logger from './logger';
import pkgObj from '../../package.json'; // eslint-disable-line import/no-unresolved


const APPIUM_VER = pkgObj.version;
const APPIUM_VER = require(path.resolve(rootDir, 'package.json')).version;

function getNodeVersion () {
// expect v<major>.<minor>.<patch>
Expand All @@ -16,10 +15,9 @@ function getNodeVersion () {
}

async function getGitRev () {
let cwd = path.resolve(__dirname, "..", "..");
let rev = null;
try {
let {stdout} = await exec("git", ["rev-parse", "HEAD"], {cwd});
let {stdout} = await exec("git", ["rev-parse", "HEAD"], {rootDir});
rev = stdout.trim();
} catch (ign) {}
return rev;
Expand Down
5 changes: 2 additions & 3 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import fs from 'fs';
import path from 'path';
import _ from 'lodash';
import { ArgumentParser } from 'argparse';
import pkgObj from '../../package.json'; // eslint-disable-line import/no-unresolved

import { rootDir } from './utils';

const args = [
[['--shell'], {
Expand Down Expand Up @@ -801,7 +800,7 @@ function parseDefaultCaps (caps) {

function getParser () {
let parser = new ArgumentParser({
version: pkgObj.version,
version: require(path.resolve(rootDir, 'package.json')).version,
addHelp: true,
description: 'A webdriver-compatible server for use with native and hybrid iOS and Android applications.',
prog: process.argv[1] || 'Appium'
Expand Down
6 changes: 4 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import logger from './logger';
import { processCapabilities, BaseDriver } from 'appium-base-driver';

import findRoot from 'find-root';

function inspectObject (args) {
function getValueArray (obj, indent = ' ') {
Expand Down Expand Up @@ -149,4 +149,6 @@ function insertAppiumPrefixes (caps) {
return prefixedCaps;
}

export { inspectObject, parseCapsForInnerDriver, insertAppiumPrefixes };
const rootDir = findRoot(__dirname);

export { inspectObject, parseCapsForInnerDriver, insertAppiumPrefixes, rootDir };
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"bluebird": "3.x",
"continuation-local-storage": "3.x",
"dateformat": "^3.0.3",
"find-root": "^1.1.0",
"lodash": "4.x",
"npmlog": "4.x",
"request": "^2.81.0",
Expand Down Expand Up @@ -84,7 +85,7 @@
"appium-gulp-plugins": "2.x",
"babel-cli": "^6.26.0",
"babel-eslint": "7.x",
"babel-preset-env": "^1.6.0",
"babel-preset-env": "^1.7.0",
"chai": "4.x",
"chai-as-promised": "7.x",
"eslint": "3.x",
Expand Down

0 comments on commit 001e2f3

Please sign in to comment.