Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Get rid of arrow functions in mocha aparatus
Browse files Browse the repository at this point in the history
  • Loading branch information
imurchie committed Jan 17, 2018
1 parent 0371942 commit 9d1f6c3
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 105 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"coverage": "gulp coveralls",
"precommit-msg": "echo 'Pre-commit checks...' && exit 0",
"precommit-test": "REPORTER=dot gulp once",
"lint": "gulp eslint"
"lint": "gulp eslint",
"lint:fix": "gulp eslint --fix"
},
"pre-commit": [
"precommit-msg",
Expand All @@ -67,7 +68,7 @@
"chai": "^3.0.0",
"chai-as-promised": "^5.1.0",
"eslint": "^3.10.2",
"eslint-config-appium": "^2.0.1",
"eslint-config-appium": "^2.1.0",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-mocha": "^4.7.0",
Expand Down
8 changes: 4 additions & 4 deletions test/image-util-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ async function getImage (file) {
return await fs.readFile(imagePath, 'utf8');
}

describe('image-util', () => {
describe('cropBase64Image', () => {
describe('image-util', function () {
describe('cropBase64Image', function () {
let originalImage = null;

before(async () => {
before(async function () {
const originalImage64 = await getImage('full-image.b64');
originalImage = await base64ToImage(originalImage64);

Expand All @@ -24,7 +24,7 @@ describe('image-util', () => {
originalImage.height.should.be.equal(1136, 'unexpected height');
});

it('should verify that an image is cropped correctly', async () => {
it('should verify that an image is cropped correctly', async function () {
const croppedImage = await cropImage(originalImage, {left: 35, top: 107, width: 323, height: 485});

// verify cropped image size, it should be less than original image according to crop region
Expand Down
18 changes: 9 additions & 9 deletions test/index-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ import chai from 'chai';
chai.should();
let { system, tempDir, util } = AppiumSupport;

describe('index', () => {
describe('default', () => {
it('should expose an object', () => {
describe('index', function () {
describe('default', function () {
it('should expose an object', function () {
AppiumSupport.should.exist;
AppiumSupport.should.be.an.instanceof(Object);
});
it('should expose system object', () => {
it('should expose system object', function () {
AppiumSupport.system.should.exist;
AppiumSupport.system.should.be.an.instanceof(Object);
});
it('should expose tempDir object', () => {
it('should expose tempDir object', function () {
AppiumSupport.tempDir.should.exist;
AppiumSupport.tempDir.should.be.an.instanceof(Object);
});
it('should expose util object', () => {
it('should expose util object', function () {
AppiumSupport.util.should.exist;
AppiumSupport.util.should.be.an.instanceof(Object);
});
});

it('should expose an object as "system" ', () => {
it('should expose an object as "system" ', function () {
system.should.be.an.instanceof(Object);
});

it('should expose an object as "tempDir" ', () => {
it('should expose an object as "tempDir" ', function () {
tempDir.should.be.an.instanceof(Object);
});

it('should expose an object as "util" ', () => {
it('should expose an object as "util" ', function () {
util.should.be.an.instanceof(Object);
});
});
8 changes: 4 additions & 4 deletions test/logger/logger-force-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
import { getDynamicLogger, restoreWriters, setupWriters,
assertOutputContains } from './helpers';

describe('logger with force log', () => {
describe('logger with force log', function () {
let writers, log;
before(() => {
before(function () {
writers = setupWriters();
log = getDynamicLogger(true, true);
log.level = 'silly';
});

after(() => {
after(function () {
restoreWriters(writers);
});

it('should not rewrite log levels even during testing', () => {
it('should not rewrite log levels even during testing', function () {
log.silly('silly');
assertOutputContains(writers, 'silly');
log.verbose('verbose');
Expand Down
18 changes: 9 additions & 9 deletions test/logger/logger-normal-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { getDynamicLogger, restoreWriters, setupWriters,

const LOG_LEVELS = ['silly', 'verbose', 'info', 'http', 'warn', 'error'];

describe('normal logger', () => {
describe('normal logger', function () {
let writers, log;
beforeEach(() => {
beforeEach(function () {
writers = setupWriters();
log = getDynamicLogger(false, false);
log.level = 'silly';
});

afterEach(() => {
afterEach(function () {
restoreWriters(writers);
});

Expand All @@ -39,17 +39,17 @@ describe('normal logger', () => {
});
});

describe('normal logger with static prefix', () => {
describe('normal logger with static prefix', function () {
let writers, log;
const PREFIX = 'my_static_prefix';

before(() => {
before(function () {
writers = setupWriters();
log = getDynamicLogger(false, false, PREFIX);
log.level = 'silly';
});

after(() => {
after(function () {
restoreWriters(writers);
});

Expand All @@ -67,17 +67,17 @@ describe('normal logger with static prefix', () => {
});
});

describe('normal logger with dynamic prefix', () => {
describe('normal logger with dynamic prefix', function () {
let writers, log;
const PREFIX = 'my_dynamic_prefix';

before(() => {
before(function () {
writers = setupWriters();
log = getDynamicLogger(false, false, () => PREFIX);
log.level = 'silly';
});

after(() => {
after(function () {
restoreWriters(writers);
});

Expand Down
12 changes: 6 additions & 6 deletions test/logger/logger-test-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
import { getDynamicLogger, restoreWriters, setupWriters,
assertOutputDoesntContain } from './helpers';

describe('test logger', () => {
describe('test logger', function () {
let writers, log;
before(() => {
before(function () {
writers = setupWriters();
log = getDynamicLogger(true);
});

after(() => {
after(function () {
restoreWriters(writers);
});

it('should contains levels', () => {
it('should contains levels', function () {
log.levels.should.have.length.above(3);
log.levels[2].should.equal('debug');
});

it('should unwrap', () => {
it('should unwrap', function () {
log.unwrap.should.exist;
log.unwrap().should.exist;
});

it('should rewrite npmlog levels during testing', () => {
it('should rewrite npmlog levels during testing', function () {
const text = 'hi';
log.silly(text);
log.verbose(text);
Expand Down
8 changes: 4 additions & 4 deletions test/plist-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ chai.should();

const plistPath = path.resolve('test', 'assets', 'sample.plist');

describe('plist', () => {
it('should parse plist file as binary', async () => {
describe('plist', function () {
it('should parse plist file as binary', async function () {
let content = await plist.parsePlistFile(plistPath);
content.should.have.property('com.apple.locationd.bundle-/System/Library/PrivateFrameworks/Parsec.framework');
});

it(`should return an empty object if file doesn't exist and mustExist is set to false`, async () => {
it(`should return an empty object if file doesn't exist and mustExist is set to false`, async function () {
let mustExist = false;
let content = await plist.parsePlistFile('doesntExist.plist', mustExist);
content.should.be.an.Object;
content.should.be.empty;
});

it('should write plist file as binary', async () => {
it('should write plist file as binary', async function () {
// create a temporary file, to which we will write
let plistFile = path.resolve(await tempDir.openDir(), 'sample.plist');
await fs.copyFile(plistPath, plistFile);
Expand Down
30 changes: 15 additions & 15 deletions test/process-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ chai.use(chaiAsPromised);

const SubProcess = teenProcess.SubProcess;

describe('process', () => {
describe('getProcessIds', () => {
describe('process', function () {
describe('getProcessIds', function () {
let proc;
before(async () => {
before(async function () {
proc = new SubProcess('tail', ['-f', __filename]);
await proc.start();
});
after(async () => {
after(async function () {
await proc.stop();
});
it('should get return an array for existing process', async () => {
it('should get return an array for existing process', async function () {
let pids = await process.getProcessIds('tail');
pids.should.be.an.instanceof(Array);
});
it('should get process identifiers for existing process', async () => {
it('should get process identifiers for existing process', async function () {
let pids = await process.getProcessIds('tail');
pids.should.have.length.at.least(1);
});
it('should get an empty array when the process does not exist', async () => {
it('should get an empty array when the process does not exist', async function () {
let pids = await process.getProcessIds('sadfgasdfasdf');
pids.should.have.length(0);
});
it('should throw an error if pgrep fails', async () => {
it('should throw an error if pgrep fails', async function () {
let tpMock = sinon.mock(teenProcess);
tpMock.expects('exec').throws({message: 'Oops', code: 2});

Expand All @@ -43,18 +43,18 @@ describe('process', () => {
});
});

describe('killProcess', async () => {
describe('killProcess', async function () {
let proc;
beforeEach(async () => {
beforeEach(async function () {
proc = new SubProcess('tail', ['-f', __filename]);
await proc.start();
});
afterEach(async () => {
afterEach(async function () {
if (proc.isRunning) {
await proc.stop();
}
});
it('should kill process that is running', async () => {
it('should kill process that is running', async function () {
proc.isRunning.should.be.true;
await process.killProcess('tail');

Expand All @@ -63,23 +63,23 @@ describe('process', () => {
proc.isRunning.should.be.false;
});
});
it('should do nothing if the process does not exist', async () => {
it('should do nothing if the process does not exist', async function () {
proc.isRunning.should.be.true;
await process.killProcess('asdfasdfasdf');

await retryInterval(10, 100, async () => {
proc.isRunning.should.be.false;
}).should.eventually.be.rejected;
});
it('should throw an error if pgrep fails', async () => {
it('should throw an error if pgrep fails', async function () {
let tpMock = sinon.mock(teenProcess);
tpMock.expects('exec').throws({message: 'Oops', code: 2});

await process.killProcess('tail').should.eventually.be.rejectedWith(/Oops/);

tpMock.restore();
});
it('should throw an error if pkill fails', async () => {
it('should throw an error if pkill fails', async function () {
let tpMock = sinon.mock(teenProcess);
tpMock.expects('exec').twice()
.onFirstCall().returns({stdout: '42\n'})
Expand Down
Loading

0 comments on commit 9d1f6c3

Please sign in to comment.