Skip to content

Commit

Permalink
chore(test): fix unit tests (angular#5064)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnishina committed Dec 19, 2018
1 parent 761d003 commit ac34f77
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 41 deletions.
22 changes: 11 additions & 11 deletions spec/unit/driverProviders/local_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ var WriteTo = require('../../../built/logger').WriteTo;
var Local = require('../../../built/driverProviders').Local;
var webdriver, file;

describe('local connect', function() {
beforeEach(function() {
describe('local connect', () => {
beforeEach(() => {
ProtractorError.SUPRESS_EXIT_CODE = true;
Logger.setWrite(WriteTo.NONE);
});

afterEach(function() {
afterEach(() => {
ProtractorError.SUPRESS_EXIT_CODE = false;
Logger.setWrite(WriteTo.CONSOLE);
});

describe('without the selenium standalone jar', function() {
it('should throw an error jar file is not present', function() {
describe('without the selenium standalone jar', () => {
it('should throw an error jar file is not present', async () => {
var config = {
capabilities: { browserName: 'chrome' },
seleniumServerJar: '/foo/bar/selenium.jar'
};
var errorFound = false;
try {
webdriver = new Local(config);
webdriver.setupEnv();
await webdriver.setupEnv();
} catch(e) {
errorFound = true;
expect(e.code).toBe(BrowserError.CODE);
Expand All @@ -37,8 +37,8 @@ describe('local connect', function() {
});
});

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

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

describe('binary does not exist', () => {
it('should throw an error if the update-config.json does not exist', () => {
it('should throw an error if the update-config.json does not exist', async () => {
spyOn(fs, 'readFileSync').and.callFake(() => { return null; });
var config = {
capabilities: { browserName: 'chrome' },
Expand All @@ -82,7 +82,7 @@ describe('local connect', function() {
var errorFound = false;
try {
webdriver = new Local(config);
webdriver.setupDriverEnv();
await webdriver.setupDriverEnv();
} catch(e) {
errorFound = true;
expect(e.code).toBe(BrowserError.CODE);
Expand Down
62 changes: 32 additions & 30 deletions spec/unit/runner_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,71 @@ var Runner = require('../../built/runner').Runner;
var Logger = require('../../built/logger').Logger,
WriteTo = require('../../built/logger').WriteTo;

describe('the Protractor runner', function() {
beforeAll(function() {
describe('the Protractor runner', () => {
beforeAll(() => {
Logger.writeTo = WriteTo.NONE;
});

afterAll(function() {
afterAll(() => {
Logger.writeTo = WriteTo.CONSOLE;
});
it('should export its config', function() {
var config = {
it('should export its config', () => {
const config = {
foo: 'bar'
};

var runner = new Runner(config);
const runner = new Runner(config);

expect(runner.getConfig()).toEqual(config);
});

it('should run', function(done) {
var config = {
it('should run', async () => {
const config = {
mockSelenium: true,
specs: ['*.js'],
framework: 'debugprint'
};
var exitCode;
var runner = new Runner(config);
let exitCode;
const runner = new Runner(config);
runner.exit_ = function(exit) {
exitCode = exit;
};

runner.run().then(function() {
expect(exitCode).toEqual(0);
done();
});
await runner.run()
expect(exitCode).toEqual(0);
});

it('should fail with no specs', function() {
var config = {
it('should fail with no specs', async () => {
const config = {
mockSelenium: true,
specs: [],
framework: 'debugprint'
};
var exitCode;
Runner.prototype.exit_ = function(exit) {
exitCode = exit;
};
var runner = new Runner(config);

expect(function() {
runner.run();
}).toThrow();
const runner = new Runner(config);
let errMessage = 'No error found';
try {
await runner.run()
} catch (err) {
errMessage = err.message;
}
expect(errMessage).not.toBe('No error found');
});

it('should fail when no custom framework is defined', function(done) {
var config = {
it('should fail when no custom framework is defined', async () => {
const config = {
mockSelenium: true,
specs: ['*.js'],
framework: 'custom'
};

var runner = new Runner(config);
runner.run().then(function() {
done.fail('expected error when no custom framework is defined');
}, done);
const runner = new Runner(config);
let errMessage = 'No error found';
try {
await runner.run()
} catch (err) {
errMessage = err.message;
}
expect(errMessage).not.toBe('No error found');
});
});

0 comments on commit ac34f77

Please sign in to comment.