Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit e9622f4

Browse files
authored
chore(test): fix unit tests (#5064)
1 parent 47abbb4 commit e9622f4

File tree

2 files changed

+43
-41
lines changed

2 files changed

+43
-41
lines changed

spec/unit/driverProviders/local_test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@ var WriteTo = require('../../../built/logger').WriteTo;
88
var Local = require('../../../built/driverProviders').Local;
99
var webdriver, file;
1010

11-
describe('local connect', function() {
12-
beforeEach(function() {
11+
describe('local connect', () => {
12+
beforeEach(() => {
1313
ProtractorError.SUPRESS_EXIT_CODE = true;
1414
Logger.setWrite(WriteTo.NONE);
1515
});
1616

17-
afterEach(function() {
17+
afterEach(() => {
1818
ProtractorError.SUPRESS_EXIT_CODE = false;
1919
Logger.setWrite(WriteTo.CONSOLE);
2020
});
2121

22-
describe('without the selenium standalone jar', function() {
23-
it('should throw an error jar file is not present', function() {
22+
describe('without the selenium standalone jar', () => {
23+
it('should throw an error jar file is not present', async () => {
2424
var config = {
2525
capabilities: { browserName: 'chrome' },
2626
seleniumServerJar: '/foo/bar/selenium.jar'
2727
};
2828
var errorFound = false;
2929
try {
3030
webdriver = new Local(config);
31-
webdriver.setupEnv();
31+
await webdriver.setupEnv();
3232
} catch(e) {
3333
errorFound = true;
3434
expect(e.code).toBe(BrowserError.CODE);
@@ -37,8 +37,8 @@ describe('local connect', function() {
3737
});
3838
});
3939

40-
describe('with the selenium standalone jar', function() {
41-
it('should throw an error if the jar file does not work', function() {
40+
describe('with the selenium standalone jar', () => {
41+
it('should throw an error if the jar file does not work', async () => {
4242
var jarFile = '';
4343
beforeEach(function() {
4444
// add files to selenium folder
@@ -54,7 +54,7 @@ describe('local connect', function() {
5454
}
5555
});
5656

57-
it('should throw an error if the selenium sever jar cannot be used', function() {
57+
it('should throw an error if the selenium sever jar cannot be used', () => {
5858
var config = {
5959
capabilities: { browserName: 'foobar explorer' },
6060
seleniumServerJar: jarFile
@@ -73,7 +73,7 @@ describe('local connect', function() {
7373
});
7474

7575
describe('binary does not exist', () => {
76-
it('should throw an error if the update-config.json does not exist', () => {
76+
it('should throw an error if the update-config.json does not exist', async () => {
7777
spyOn(fs, 'readFileSync').and.callFake(() => { return null; });
7878
var config = {
7979
capabilities: { browserName: 'chrome' },
@@ -82,7 +82,7 @@ describe('local connect', function() {
8282
var errorFound = false;
8383
try {
8484
webdriver = new Local(config);
85-
webdriver.setupDriverEnv();
85+
await webdriver.setupDriverEnv();
8686
} catch(e) {
8787
errorFound = true;
8888
expect(e.code).toBe(BrowserError.CODE);

spec/unit/runner_test.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,71 @@ var Runner = require('../../built/runner').Runner;
22
var Logger = require('../../built/logger').Logger,
33
WriteTo = require('../../built/logger').WriteTo;
44

5-
describe('the Protractor runner', function() {
6-
beforeAll(function() {
5+
describe('the Protractor runner', () => {
6+
beforeAll(() => {
77
Logger.writeTo = WriteTo.NONE;
88
});
99

10-
afterAll(function() {
10+
afterAll(() => {
1111
Logger.writeTo = WriteTo.CONSOLE;
1212
});
13-
it('should export its config', function() {
14-
var config = {
13+
it('should export its config', () => {
14+
const config = {
1515
foo: 'bar'
1616
};
1717

18-
var runner = new Runner(config);
18+
const runner = new Runner(config);
1919

2020
expect(runner.getConfig()).toEqual(config);
2121
});
2222

23-
it('should run', function(done) {
24-
var config = {
23+
it('should run', async () => {
24+
const config = {
2525
mockSelenium: true,
2626
specs: ['*.js'],
2727
framework: 'debugprint'
2828
};
29-
var exitCode;
30-
var runner = new Runner(config);
29+
let exitCode;
30+
const runner = new Runner(config);
3131
runner.exit_ = function(exit) {
3232
exitCode = exit;
3333
};
3434

35-
runner.run().then(function() {
36-
expect(exitCode).toEqual(0);
37-
done();
38-
});
35+
await runner.run()
36+
expect(exitCode).toEqual(0);
3937
});
4038

41-
it('should fail with no specs', function() {
42-
var config = {
39+
it('should fail with no specs', async () => {
40+
const config = {
4341
mockSelenium: true,
4442
specs: [],
4543
framework: 'debugprint'
4644
};
47-
var exitCode;
48-
Runner.prototype.exit_ = function(exit) {
49-
exitCode = exit;
50-
};
51-
var runner = new Runner(config);
5245

53-
expect(function() {
54-
runner.run();
55-
}).toThrow();
46+
const runner = new Runner(config);
47+
let errMessage = 'No error found';
48+
try {
49+
await runner.run()
50+
} catch (err) {
51+
errMessage = err.message;
52+
}
53+
expect(errMessage).not.toBe('No error found');
5654
});
5755

58-
it('should fail when no custom framework is defined', function(done) {
59-
var config = {
56+
it('should fail when no custom framework is defined', async () => {
57+
const config = {
6058
mockSelenium: true,
6159
specs: ['*.js'],
6260
framework: 'custom'
6361
};
6462

65-
var runner = new Runner(config);
66-
runner.run().then(function() {
67-
done.fail('expected error when no custom framework is defined');
68-
}, done);
63+
const runner = new Runner(config);
64+
let errMessage = 'No error found';
65+
try {
66+
await runner.run()
67+
} catch (err) {
68+
errMessage = err.message;
69+
}
70+
expect(errMessage).not.toBe('No error found');
6971
});
7072
});

0 commit comments

Comments
 (0)