Skip to content

Commit

Permalink
Add unit test for browser helper (#428)
Browse files Browse the repository at this point in the history
* Add unit test for browser helper

* Update

* Update

* Update

* Update

* Update
  • Loading branch information
EzioLi01 authored Aug 25, 2023
1 parent fe3a0b6 commit 8665b78
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/browsers/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ function exec(cmd, opt_cwd) {
}

module.exports.launchBrowser = launchBrowser;
module.exports.getBrowser = getBrowser;
55 changes: 55 additions & 0 deletions test/browserHelper.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

const assert = require('assert');
var browser = require('../src/browsers/browser');

suite('browserHelper', function () {
const currentSystem = process.platform;
const chrome = 'chrome';
const edge = 'edge';
const url = 'http://localhost:8000/index.html';

test('Will get Chrome browser target with argument correctly for each system', async () => {
const browserInfo = await browser.getBrowser(chrome, undefined, url);
switch (currentSystem) {
case 'win32':
assert.strictEqual(browserInfo.includes('chrome'), true);
assert.strictEqual(browserInfo.includes(url), false);
assert.strictEqual(browserInfo.includes('--user-data-dir=\%TEMP\%\\cordova_simulate_temp_chrome_user_data_dir'), true);
break;
case 'darwin':
assert.strictEqual(browserInfo.includes('Google Chrome'), true);
assert.strictEqual(browserInfo.includes(url), false);
assert.strictEqual(browserInfo.includes('--user-data-dir=/tmp/cordova_simulate_temp_chrome_user_data_dir'), true);
break;
case 'linux':
assert.strictEqual(browserInfo.includes('google-chrome'), true);
assert.strictEqual(browserInfo.includes(url), false);
assert.strictEqual(browserInfo.includes('--user-data-dir=/tmp/cordova_simulate_temp_chrome_user_data_dir'), true);
break;
}
});

test('Will get Edge browser target with argument correctly for each system', async () => {
const browserInfo = await browser.getBrowser(edge, undefined, url);
switch (currentSystem) {
case 'win32':
assert.equal(browserInfo.includes('msedge'), true);
assert.strictEqual(browserInfo.includes(url), true);
assert.strictEqual(browserInfo.includes('--user-data-dir=\%TEMP\%\\cordova_simulate_temp_edge_user_data_dir'), true);
break;
case 'darwin':
assert.strictEqual(browserInfo.includes('Microsoft Edge'), true);
assert.strictEqual(browserInfo.includes(url), true);
assert.strictEqual(browserInfo.includes('--user-data-dir=/tmp/cordova_simulate_temp_edge_user_data_dir'), true);
break;
case 'linux':
assert.strictEqual(browserInfo.includes('microsoft-edge'), true);
assert.strictEqual(browserInfo.includes(url), true);
assert.strictEqual(browserInfo.includes('--user-data-dir=/tmp/cordova_simulate_temp_edge_user_data_dir'), true);
break;
}
});
});

0 comments on commit 8665b78

Please sign in to comment.