Move to logger from appium-support
MODIFY
docs/en/contributing-to-appium/appium-packages.md
docs/en/contributing-to-appium/appium-packages.md
- contains all available and supported CLI arguments
- check for deprecation and mutual exclusion
- put logging together
- - mixture out of npmlog, winston and appium-logger
+ - mixture out of npmlog, winston and a custom logger
- initiates AppiumDriver (extends Basedriver)
- assigns iOS/Android/Selendroid/Fake driver to session
- creates/deletes Appium session

MODIFY
lib/logger.js
lib/logger.js
-import { getLogger } from 'appium-logger';
+import { logger } from 'appium-support';
-let logger = getLogger('Appium');
-export default logger;
+let log = logger.getLogger('Appium');
+
+export default log;

MODIFY
lib/logsink.js
lib/logsink.js
import npmlog from 'npmlog';
-import { patchLogger } from 'appium-logger';
import winston from 'winston';
-import { fs } from 'appium-support';
+import { fs, logger } from 'appium-support';
import 'date-utils';
import _ from 'lodash';
// set up distributed logging before everything else
-patchLogger(npmlog);
+logger.patchLogger(npmlog);
global._global_npmlog = npmlog;
// npmlog is used only for emitting, we use winston for output
@@ -36,7 +35,7 @@ const npmToWinstonLevels = {
error: 'error',
};
-let logger = null;
+let log = null;
let timeZone = null;
function timestamp () {
@@ -184,7 +183,7 @@ async function init (args) {
// object
clear();
- logger = new (winston.Logger)({
+ log = new (winston.Logger)({
transports: await _createTransports(args)
});
@@ -196,7 +195,7 @@ async function init (args) {
let prefix = `[${logObj.prefix}]`;
msg = `${prefix.magenta} ${msg}`;
}
- logger[winstonLevel](msg);
+ log[winstonLevel](msg);
if (args.logHandler && typeof args.logHandler === "function") {
args.logHandler(logObj.level, msg);
}
@@ -204,21 +203,21 @@ async function init (args) {
});
- logger.setLevels(levels);
+ log.setLevels(levels);
// 8/19/14 this is a hack to force Winston to print debug messages to stdout rather than stderr.
// TODO: remove this if winston provides an API for directing streams.
- if (levels[logger.transports.console.level] === levels.debug) {
- logger.debug = function (msg) {
- logger.info('[debug] ' + msg);
+ if (levels[log.transports.console.level] === levels.debug) {
+ log.debug = function (msg) {
+ log.info('[debug] ' + msg);
};
}
}
function clear () {
- if (logger) {
- for (let transport of _.keys(logger.transports)) {
- logger.remove(transport);
+ if (log) {
+ for (let transport of _.keys(log.transports)) {
+ log.remove(transport);
}
}
npmlog.removeAllListeners('log');

MODIFY
package.json
package.json
"appium-base-driver": "2.x",
"appium-fake-driver": "0.x",
"appium-ios-driver": "1.x",
- "appium-logger": "2.x",
"appium-selendroid-driver": "1.x",
"appium-support": "2.x",
"appium-uiautomator2-driver": "0.x",
"mocha": "2.x",
"pre-commit": "1.x",
"sinon": "1.x",
- "wd": "0.x"
+ "wd": "1.x"
},
"optionalDependencies": {
"fsevents": "1.x"

MODIFY
test/driver-specs.js
test/driver-specs.js
@@ -15,6 +15,7 @@ chai.should();
chai.use(chaiAsPromised);
const BASE_CAPS = {platformName: 'Fake', deviceName: 'Fake', app: TEST_FAKE_APP};
+const SESSION_ID = 1;
describe('AppiumDriver', () => {
describe('getAppiumRouter', () => {
@@ -37,20 +38,20 @@ describe('AppiumDriver', () => {
return [appium, mockFakeDriver];
}
describe('createSession', () => {
- let appium
- , mockFakeDriver;
+ let appium;
+ let mockFakeDriver;
beforeEach(() => {
[appium, mockFakeDriver] = getDriverAndFakeDriver();
});
- afterEach(() => {
+ afterEach(async () => {
mockFakeDriver.restore();
- appium.args.defaultCapabilities = {};
+ await appium.deleteSession(SESSION_ID);
});
it('should call inner driver\'s createSession with desired capabilities', async () => {
mockFakeDriver.expects("createSession")
.once().withExactArgs(BASE_CAPS, undefined, [])
- .returns([1, BASE_CAPS]);
+ .returns([SESSION_ID, BASE_CAPS]);
await appium.createSession(BASE_CAPS);
mockFakeDriver.verify();
});
@@ -60,7 +61,7 @@ describe('AppiumDriver', () => {
appium.args.defaultCapabilities = defaultCaps;
mockFakeDriver.expects("createSession")
.once().withArgs(allCaps)
- .returns([1, allCaps]);
+ .returns([SESSION_ID, allCaps]);
await appium.createSession(BASE_CAPS);
mockFakeDriver.verify();
});
@@ -71,7 +72,7 @@ describe('AppiumDriver', () => {
appium.args.defaultCapabilities = defaultCaps;
mockFakeDriver.expects("createSession")
.once().withArgs(BASE_CAPS)
- .returns([1, BASE_CAPS]);
+ .returns([SESSION_ID, BASE_CAPS]);
await appium.createSession(BASE_CAPS);
mockFakeDriver.verify();
});
@@ -99,7 +100,7 @@ describe('AppiumDriver', () => {
mockFakeDriver.expects("createSession")
.once().withExactArgs(BASE_CAPS, undefined, [])
- .returns([1, BASE_CAPS]);
+ .returns([SESSION_ID, BASE_CAPS]);
await appium.createSession(BASE_CAPS);
sessions = await appium.getSessions();
@@ -112,14 +113,13 @@ describe('AppiumDriver', () => {
});
});
describe('deleteSession', () => {
- let appium
- , mockFakeDriver;
+ let appium;
+ let mockFakeDriver;
beforeEach(() => {
[appium, mockFakeDriver] = getDriverAndFakeDriver();
});
afterEach(() => {
mockFakeDriver.restore();
- appium.args.defaultCapabilities = {};
});
it('should remove the session if it is found', async () => {
let [sessionId] = await appium.createSession(BASE_CAPS);
@@ -136,22 +136,32 @@ describe('AppiumDriver', () => {
.returns();
await appium.deleteSession(sessionId);
mockFakeDriver.verify();
+
+ // cleanup, since we faked the delete session call
+ await mockFakeDriver.object.deleteSession();
});
});
describe('getSessions', () => {
let appium;
+ let sessions;
before(() => {
appium = new AppiumDriver({});
});
+ afterEach(async () => {
+ for (let session of sessions) {
+ await appium.deleteSession(session.id);
+ }
+ });
it('should return an empty array of sessions', async () => {
- let sessions = await appium.getSessions();
+ sessions = await appium.getSessions();
sessions.should.be.an.array;
sessions.should.be.empty;
});
it('should return sessions created', async () => {
let session1 = await appium.createSession(_.extend(_.clone(BASE_CAPS), {cap: 'value'}));
let session2 = await appium.createSession(_.extend(_.clone(BASE_CAPS), {cap: 'other value'}));
- let sessions = await appium.getSessions();
+
+ sessions = await appium.getSessions();
sessions.should.be.an.array;
sessions.should.have.length(2);
sessions[0].id.should.equal(session1[0]);
@@ -159,6 +169,7 @@ describe('AppiumDriver', () => {
sessions[1].id.should.equal(session2[0]);
sessions[1].capabilities.should.eql(session2[1]);
});
+ });
describe('getStatus', () => {
let appium;
before(() => {
@@ -170,7 +181,6 @@ describe('AppiumDriver', () => {
status.build.version.should.exist;
});
});
- });
describe('sessionExists', () => {
});
describe('attachUnexpectedShutdownHandler', () => {
@@ -179,7 +189,8 @@ describe('AppiumDriver', () => {
beforeEach(() => {
[appium, mockFakeDriver] = getDriverAndFakeDriver();
});
- afterEach(() => {
+ afterEach(async () => {
+ await mockFakeDriver.object.deleteSession();
mockFakeDriver.restore();
appium.args.defaultCapabilities = {};
});

MODIFY
test/logger-specs.js
test/logger-specs.js
import { init as logsinkInit, clear as logsinkClear } from '../lib/logsink';
import sinon from 'sinon';
-import { getLogger } from 'appium-logger';
+import { logger } from 'appium-support';
// temporarily turn on logging to stdio, so we can catch and query
let forceLogs = process.env._FORCE_LOGS;
process.env._FORCE_LOGS = 1;
-let logger = getLogger('Appium');
+let log = logger.getLogger('Appium');
-describe('Logger', () => {
+describe('logging', () => {
let stderrSpy;
let stdoutSpy;
beforeEach(() => {
@@ -31,9 +31,9 @@ describe('Logger', () => {
const debugMsg = 'some debug';
function doLogging () {
- logger.error(errorMsg);
- logger.warn(warnMsg);
- logger.debug(debugMsg);
+ log.error(errorMsg);
+ log.warn(warnMsg);
+ log.debug(debugMsg);
}
it('should send error, info and debug when loglevel is debug', async () => {

Move to logger from appium-support