This commit is contained in:
Tiệp Sunflower
2023-03-06 14:23:39 +07:00
commit aa9c76c82f
2234 changed files with 449471 additions and 0 deletions

33
node_modules/@testim/chrome-version/.eslintrc.json generated vendored Normal file
View File

@@ -0,0 +1,33 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
}

View File

@@ -0,0 +1,19 @@
name: Tests
on: [push, pull_request]
jobs:
test:
name: 'Test on Node.js v${{ matrix.node }} / ${{ matrix.os }}'
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node: [10, 12, 14, 16]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm test

76
node_modules/@testim/chrome-version/CODE_OF_CONDUCT.md generated vendored Normal file
View File

@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at benji@testim.io. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

21
node_modules/@testim/chrome-version/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018-2019 Testim.io
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,51 @@
const { execSync } = require('child_process');
const path = require('path').posix;
const { canAccess, newLineRegex, sort } = require('./util');
function darwin(includeChromium = false) {
const suffixes = [
// '/Contents/MacOS/Google Chrome Canary',
'/Contents/MacOS/Google Chrome',
... includeChromium ? ['/Contents/MacOS/Chromium'] : []
];
const LSREGISTER = '/System/Library/Frameworks/CoreServices.framework' +
'/Versions/A/Frameworks/LaunchServices.framework' +
'/Versions/A/Support/lsregister';
const installations = [];
execSync(
`${LSREGISTER} -dump` +
' | grep -E -i \'(google chrome( canary)?' + (includeChromium ? '|chromium' : '') + ').app(\\s\\(0x[0-9a-f]+\\))?$\'' +
' | awk \'sub(/\\(0x[0-9a-f]+\\)/, "")\'' +
' | awk \'{$1=""; print $0}\'' +
' | awk \'{ gsub(/^[ \\t]+|[ \\t]+$/, ""); print }\'')
.toString()
.split(newLineRegex)
.forEach((inst) => {
suffixes.forEach(suffix => {
const execPath = path.join(inst.trim(), suffix);
if (canAccess(execPath)) {
installations.push(execPath);
}
});
});
// Retains one per line to maintain readability.
const priorities = [
{ regex: new RegExp(`^${process.env.HOME}/Applications/.*Chromium.app`), weight: 49 },
{ regex: new RegExp(`^${process.env.HOME}/Applications/.*Chrome.app`), weight: 50 },
// { regex: new RegExp(`^${process.env.HOME}/Applications/.*Chrome Canary.app`), weight: 51 },
{ regex: /^\/Applications\/.*Chromium.app/, weight: 99 },
{ regex: /^\/Applications\/.*Chrome.app/, weight: 100 },
// { regex: /^\/Applications\/.*Chrome Canary.app/, weight: 101 },
{ regex: /^\/Volumes\/.*Chromium.app/, weight: -3 },
{ regex: /^\/Volumes\/.*Chrome.app/, weight: -2 },
// { regex: /^\/Volumes\/.*Chrome Canary.app/, weight: -1 }
];
return sort(installations, priorities);
}
module.exports = darwin;

View File

@@ -0,0 +1,9 @@
/**
* find a executable chrome for all support system
* @returns {string} executable chrome full path
* @throws
* if no executable chrome find, ERROR_NO_INSTALLATIONS_FOUND will be throw
* if platform is not one if ['win32','darwin','linux'], ERROR_PLATFORM_NOT_SUPPORT will be throw
*/
declare function findChrome(): string;
export = findChrome;

View File

@@ -0,0 +1,39 @@
'use strict';
const ERROR_PLATFORM_NOT_SUPPORT = new Error('platform not support');
const ERROR_NO_INSTALLATIONS_FOUND = new Error('no chrome installations found');
/**
* Find a executable Chrome (or Chromium) for all supported systems.
*
* Supports macOS, Linux, and Windows.
*
* @param {boolean} includeChromium true if we should consider Chromium in our search, false otherwise.
* @returns {string} the first full path to an executable Chrome (or Chromium)
* @throws
* if no executable Chrome (or Chromium) find, ERROR_NO_INSTALLATIONS_FOUND will be throw
* if platform is not one if ['win32','darwin','linux'], ERROR_PLATFORM_NOT_SUPPORT will be throw
*/
function findChrome(includeChromium = false) {
const { platform } = process;
let installations = [];
switch (platform) {
case 'win32':
installations = require('./win32')(includeChromium);
break;
case 'darwin':
installations = require('./darwin')(includeChromium);
break;
case 'linux':
installations = require('./linux')(includeChromium);
break;
default:
throw ERROR_PLATFORM_NOT_SUPPORT;
}
if (installations.length) {
return installations[0];
} else {
throw ERROR_NO_INSTALLATIONS_FOUND;
}
}
module.exports = findChrome;

View File

@@ -0,0 +1,112 @@
const { execSync, execFileSync } = require('child_process');
const path = require('path').posix;
const fs = require('fs');
const { canAccess, sort, isExecutable, newLineRegex } = require('./util');
function findChromeExecutablesForLinuxDesktop(folder, includeChromium = false) {
const argumentsRegex = /(^[^ ]+).*/; // Take everything up to the first space
const chromeExecRegex = '^Exec=\/.*\/(google|chrome' + (includeChromium ? '|chromium' : '') + ')-.*';
let installations = [];
if (canAccess(folder)) {
// Output of the grep & print looks like:
// /opt/google/chrome/google-chrome --profile-directory
// /home/user/Downloads/chrome-linux/chrome-wrapper %U
let execPaths;
execPaths = execSync(`find "${folder}" -type f -exec grep -E "${chromeExecRegex}" "{}" \\; | awk -F '=' '{print $2}'`);
execPaths = execPaths
.toString()
.split(newLineRegex)
.map((execPath) => execPath.replace(argumentsRegex, '$1'));
execPaths.forEach((execPath) => canAccess(execPath) && installations.push(execPath));
}
return installations;
}
function findChromeExecutablesForLinux(validChromePaths, includeChromium = false) {
const executables = [
'google-chrome-stable',
'google-chrome',
... includeChromium ? ['chromium', 'chromium-browser', 'chromium/chrome'] : [] // chromium/chrome is for toradex machines where "chromium" is a directory. seen on Angstrom v2016.12
];
return executables.map(executable => {
const existingPaths = validChromePaths.map(possiblePath => {
try {
const chromePathToTest = possiblePath + '/' + executable;
if (fs.existsSync(chromePathToTest) && canAccess(chromePathToTest) && isExecutable(chromePathToTest)) {
return [ chromePathToTest ];
}
} catch (err) {
// not installed on this path or inaccessible
}
return [];
}).reduce((acc, val) => acc.concat(val), []); //.filter((foundChromePath) => foundChromePath);
// skip asking "which" command if the binary was found by searching the known paths.
if (existingPaths && existingPaths.length > 0) {
return existingPaths;
}
try {
const chromePath = execFileSync('which', [executable]).toString().split(newLineRegex)[0];
if (canAccess(chromePath)) {
return [ chromePath ];
}
} catch (err) {
// cmd which not installed.
}
return [];
}).reduce((acc, val) => acc.concat(val), []);
}
/**
* Look for linux executables in 2 ways
* 1. Look into the directories where .desktop are saved on gnome based distro's
* 2. Look for google-chrome-stable and google-chrome executables by using the which command
* If includeChromium is set, also look for chromium, chromium-browser, and chromium/chrome executables by using the which command
*/
function linux(includeChromium = false) {
let installations = [];
// 1. Look into the directories where .desktop are saved on gnome based distro's
const desktopInstallationFolders = [
path.join(require('os').homedir(), '.local/share/applications/'),
'/usr/share/applications/',
];
desktopInstallationFolders.forEach(folder => {
installations = installations.concat(findChromeExecutablesForLinuxDesktop(folder, includeChromium));
});
// 2. Look for google-chrome-stable and google-chrome (and optionally chromium, chromium-browser, and chromium-chrome) executables by using the which command
// see http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/
const validChromePaths = [
'/usr/bin',
'/usr/local/bin',
'/usr/sbin',
'/usr/local/sbin',
'/opt/bin',
'/usr/bin/X11',
'/usr/X11R6/bin'
];
installations = installations.concat(findChromeExecutablesForLinux(validChromePaths, includeChromium));
const priorities = [
{ regex: /chromium$/, weight: 52 },
{ regex: /chrome-wrapper$/, weight: 51 },
{ regex: /google-chrome-stable$/, weight: 50 },
{ regex: /google-chrome$/, weight: 49 },
{ regex: /chromium-browser$/, weight: 48 },
{ regex: /chrome$/, weight: 47 },
];
return sort(Array.from(new Set(installations.filter(Boolean))), priorities);
}
module.exports = linux;

View File

@@ -0,0 +1,56 @@
const fs = require('fs');
const newLineRegex = /\r?\n/;
function sort(installations, priorities) {
const defaultPriority = 10;
// assign priorities
return installations
.map((inst) => {
for (const pair of priorities) {
if (pair.regex.test(inst)) {
return { path: inst, weight: pair.weight };
}
}
return { path: inst, weight: defaultPriority };
})
// sort based on priorities
.sort((a, b) => (b.weight - a.weight))
// remove priority flag
.map(pair => pair.path);
}
function canAccess(file) {
if (!file) {
return false;
}
try {
fs.accessSync(file);
return true;
} catch (e) {
return false;
}
}
function isExecutable(file) {
if (!file) {
return false;
}
try {
var stat = fs.statSync(file);
return stat && typeof stat.isFile === "function" && stat.isFile();
} catch (e) {
return false;
}
}
module.exports = {
sort,
canAccess,
isExecutable,
newLineRegex,
}

View File

@@ -0,0 +1,30 @@
const path = require('path').win32;
const { canAccess } = require('./util');
const procesEnv = process.env;
function win32(includeChromium = false) {
const installations = [];
const suffixes = [
'\\Google\\Chrome SxS\\Application\\chrome.exe',
'\\Google\\Chrome\\Application\\chrome.exe',
'\\chrome-win32\\chrome.exe',
... includeChromium ? ['\\Chromium\\Application\\chrome.exe'] : [],
// '\\Google\\Chrome Beta\\Application\\chrome.exe',
];
const prefixes = [
procesEnv.LOCALAPPDATA,
procesEnv.PROGRAMFILES,
procesEnv['PROGRAMFILES(X86)']
].filter(prefix => prefix); // filter out undefined
prefixes.forEach(prefix => suffixes.forEach(suffix => {
const chromePath = path.join(prefix, suffix);
if (canAccess(chromePath)) {
installations.push(chromePath);
}
}));
return installations;
}
module.exports = win32;

6
node_modules/@testim/chrome-version/example.js generated vendored Normal file
View File

@@ -0,0 +1,6 @@
(async () => {
const { getChromeVersion } = require('./index');
const version = await getChromeVersion();
console.log(version);
})();

106
node_modules/@testim/chrome-version/index.js generated vendored Normal file
View File

@@ -0,0 +1,106 @@
'use strict';
const findChrome = require('./chrome-finder');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const path = require('path');
const readdir = util.promisify(require('fs').readdir);
const { execSync } = require('child_process');
async function getChromeVersionFromCli(includeChromium) {
let chromePath;
try {
chromePath = findChrome(includeChromium);
} catch (err) {
return null;
}
const res = await exec(chromePath.replace(/ /g, '\\ ') + ' --version');
const version = extractChromeVersionNumer(res.stdout);
return version;
}
function extractChromeVersionNumer(chromeVersionString) {
return chromeVersionString.replace(/\D*(([0-9]+\.?)+)\s?.*/, '$1');
}
async function getChromeVersionWin(includeChromium) {
let chromePath;
try {
chromePath = findChrome(includeChromium);
} catch (err) {
return null;
}
const versionPath = path.dirname(chromePath);
const contents = await readdir(versionPath);
const versions = contents.filter(a => /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/g.test(a));
// returning oldest in case there is an updated version and chrome still hasn't relaunched
const oldest = versions.sort((a, b) => a > b)[0];
return oldest;
}
function getChromeVersionFromOsa(includeChromium) {
try {
const version = execSync('osascript -e \'tell application "Google Chrome" to get version\'').toString().trim();
return version;
} catch (err) {
if (!includeChromium) {
return null;
}
// else fall-through to check for Chromium below
}
try {
const version = execSync('osascript -e \'tell application "Chromium" to get version\'').toString().trim();
return version;
} catch (err) {
return null;
}
}
async function innerGetChromeVersion(includeChromium = false) {
const os = process.platform;
if (os === 'darwin') return getChromeVersionFromOsa(includeChromium);
if (os === 'linux') return getChromeVersionFromCli(includeChromium);
if (os.includes('win')) return getChromeVersionWin(includeChromium);
console.log(`${os} is not supported`);
return null;
}
/**
* Gets the version of Chrome (or Chromium) that is installed.
*
* Supports macOS, Linux, and Windows.
*
* @param {boolean} includeChromium true if we should consider Chromium in our search, false otherwise.
* @returns {string} the version number of Chrome (or Chromium), or null if the OS is not supported.
*/
async function getChromeVersion(includeChromium = false) {
const res = await innerGetChromeVersion(includeChromium);
if (typeof res === 'string') {
return res.trim();
}
return res;
}
if (require.main == module) {
getChromeVersion().then(v => console.log(v));
}
module.exports = {
getChromeVersion
};

27
node_modules/@testim/chrome-version/package.json generated vendored Normal file
View File

@@ -0,0 +1,27 @@
{
"name": "@testim/chrome-version",
"version": "1.1.3",
"description": "Finds the version of Chrome that is installed on your machine",
"main": "index.js",
"scripts": {
"lint": "eslint *.js --fix",
"test": "mocha"
},
"repository": {
"type": "git",
"url": "https://github.com/testimio/chrome-version.git"
},
"author": "Testim",
"license": "MIT",
"homepage": "https://github.com/testimio/chrome-version",
"keywords": [
"chrome",
"version"
],
"devDependencies": {
"chai": "4.3.4",
"eslint": "8.7.0",
"mocha": "9.1.4",
"rewire": "6.0.0"
}
}

27
node_modules/@testim/chrome-version/readme.MD generated vendored Normal file
View File

@@ -0,0 +1,27 @@
# chrome-version
[![Build Status](https://github.com/testimio/chrome-version/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/testimio/chrome-version/actions/workflows/ci.yml)
Finds the version of Chrome (or Chromium) that is installed on your machine.
## Installation
```sh
npm install @testim/chrome-version
```
## Use
```js
(async () => {
const { getChromeVersion } = require('@testim/chrome-version');
const includeChromium = false; // NOTE: set to true to also search for Chromium
const version = await getChromeVersion(includeChromium);
console.log(version);
})();
```
## Testing
```sh
npm test
```
* If no version of chrome is installed on your machine `getChromeVersion` will return null.

370
node_modules/@testim/chrome-version/test/test.js generated vendored Normal file
View File

@@ -0,0 +1,370 @@
const chai = require('chai');
const expect = chai.expect;
const Buffer = require('buffer').Buffer;
// rewrite to get access for testing
const rewire = require("rewire");
const chromeVersionModule = rewire("../index.js");
const extractChromeVersionNumer = chromeVersionModule.__get__('extractChromeVersionNumer');
const getChromeVersionFromOsa = chromeVersionModule.__get__('getChromeVersionFromOsa');
const chromeFinderLinuxModule = rewire("../chrome-finder/linux.js");
const findChromeExecutablesForLinuxDesktop = chromeFinderLinuxModule.__get__('findChromeExecutablesForLinuxDesktop');
const findChromeExecutablesForLinux = chromeFinderLinuxModule.__get__('findChromeExecutablesForLinux');
const chromeFinderDarwinModule = rewire("../chrome-finder/darwin.js");
const findChromeForDarwin = chromeFinderDarwinModule.__get__('darwin');
const chromeFinderWin32Module = rewire("../chrome-finder/win32.js");
const findChromeForWin32 = chromeFinderWin32Module.__get__('win32');
describe('Chrome Finder', function() {
describe('extractChromeVersionNumer from Google Chrome 95.0.4638', function() {
it('should return "95.0.4638"', function() {
const versionString = 'Google Chrome 95.0.4638';
const versionNumber = extractChromeVersionNumer(versionString);
expect(versionNumber).to.equal('95.0.4638');
});
});
describe('extractChromeVersionNumer from Google Chrome 96.0.4664.110', function() {
it('should return "96.0.4664.110"', function() {
const versionString = 'Google Chrome 96.0.4664.110';
const versionNumber = extractChromeVersionNumer(versionString);
expect(versionNumber).to.equal('96.0.4664.110');
});
});
describe('extractChromeVersionNumer from Google Chrome 97.0.4692.71', function() {
it('should return "97.0.4692.71"', function() {
const versionString = 'Google Chrome 97.0.4692.71';
const versionNumber = extractChromeVersionNumer(versionString);
expect(versionNumber).to.equal('97.0.4692.71');
});
});
describe('extractChromiumVersionNumer from Chromium 105.0.5195.102 built on Debian 11.4, running on Debian 11.5', function() {
it('should return "105.0.5195.102"', function() {
const versionString = 'Chromium 105.0.5195.102 built on Debian 11.4, running on Debian 11.5';
const versionNumber = extractChromeVersionNumer(versionString);
expect(versionNumber).to.equal('105.0.5195.102');
});
});
describe('extractChromiumVersionNumer from Chromium 90.0.4430.212 Fedora Project', function() {
it('should return "90.0.4430.212"', function() {
const versionString = 'Chromium 90.0.4430.212 Fedora Project';
const versionNumber = extractChromeVersionNumer(versionString);
expect(versionNumber).to.equal('90.0.4430.212');
});
});
describe('extractChromiumVersionNumer from Chromium 98.0.4753.0', function() {
it('should return "98.0.4753.0"', function() {
const versionString = 'Chromium 98.0.4753.0';
const versionNumber = extractChromeVersionNumer(versionString);
expect(versionNumber).to.equal('98.0.4753.0');
});
});
describe('getChromeVersionFromOsa when includeChromium=false', function() {
it('should only find Chrome', function() {
const includeChromium = false;
const mockVersion = '97.0.4692.71';
var execSyncCommand;
chromeVersionModule.__set__('execSync', function(command) {
execSyncCommand = command;
return Buffer.from(mockVersion);
});
const version = getChromeVersionFromOsa(includeChromium);
expect(execSyncCommand).to.include('Google Chrome');
expect(execSyncCommand).to.not.include('Chromium');
expect(version).to.equal(mockVersion);
});
});
describe('getChromeVersionFromOsa when includeChromium=true', function() {
it('should only find Chromium', function() {
const includeChromium = true;
const mockVersion = '98.0.4753.0';
var execSyncCommands = [];
chromeVersionModule.__set__('execSync', function(command) {
execSyncCommands.push(command);
if (execSyncCommands.length == 1) {
throw "not found"
}
return Buffer.from(mockVersion);
});
const version = getChromeVersionFromOsa(includeChromium);
expect(execSyncCommands.length).equal(2);
expect(execSyncCommands[0]).to.include('Google Chrome');
expect(execSyncCommands[1]).to.include('Chromium');
expect(version).to.equal(mockVersion);
});
});
});
describe('Chrome Finder Linux Module', function() {
describe('Linux Desktop when includeChromium=false', function() {
it('should only find Chrome', function() {
const includeChromium = false;
const mockChromePaths = [
'/opt/google/chrome/google-chrome',
'/home/user/Downloads/chrome-linux/chrome-wrapper'
];
chromeFinderLinuxModule.__set__('canAccess', function(file) {
return true;
});
var execSyncCommand;
chromeFinderLinuxModule.__set__('execSync', function(command) {
execSyncCommand = command;
return Buffer.from(mockChromePaths.join('\n'));
});
const mockDesktopFolder = "mock-desktop-folder";
const executables = findChromeExecutablesForLinuxDesktop(mockDesktopFolder, includeChromium);
expect(execSyncCommand).to.include(mockDesktopFolder);
expect(execSyncCommand).to.not.include('|chromium');
expect(executables).to.have.lengthOf(2);
expect(executables).to.deep.equal(mockChromePaths);
});
});
describe('Linux Desktop when includeChromium=true', function() {
it('should find Chrome and Chromium', function() {
const includeChromium = true;
const mockChromePaths = [
'/opt/google/chrome/google-chrome',
'/home/user/Downloads/chrome-linux/chrome-wrapper',
'/usr/local/bin/chromium-browser'
];
chromeFinderLinuxModule.__set__('canAccess', function(file) {
return true;
});
var execSyncCommand;
chromeFinderLinuxModule.__set__('execSync', function(command) {
execSyncCommand = command;
return Buffer.from(mockChromePaths.join('\n'));
});
const mockDesktopFolder = "mock-desktop-folder";
const executables = findChromeExecutablesForLinuxDesktop(mockDesktopFolder, includeChromium);
expect(execSyncCommand).to.include(mockDesktopFolder);
expect(execSyncCommand).to.include('|chromium');
expect(executables).to.have.lengthOf(3);
expect(executables).to.deep.equal(mockChromePaths);
});
});
describe('Linux when includeChromium=false', function() {
it('should only find Chrome', function() {
const includeChromium = false;
const mockPaths = [
'/mock-path'
];
chromeFinderLinuxModule.__set__('fs', {
existsSync: function(file) {
return true;
}
});
chromeFinderLinuxModule.__set__('canAccess', function(file) {
return true;
});
chromeFinderLinuxModule.__set__('isExecutable', function(file) {
return true;
});
const executables = findChromeExecutablesForLinux(mockPaths, includeChromium);
expect(executables).to.have.lengthOf(2);
const expectedExecutables = mockPaths.map(mockPath => ['google-chrome-stable', 'google-chrome'].map(executable => mockPath + '/' + executable)).reduce((acc, val) => acc.concat(val), []);
expect(executables).to.deep.equal(expectedExecutables);
});
});
describe('Linux when includeChromium=true', function() {
it('should find Chrome and Chromium', function() {
const includeChromium = true;
const mockPaths = [
'/mock-path'
];
chromeFinderLinuxModule.__set__('fs', {
existsSync: function(file) {
return true;
}
});
chromeFinderLinuxModule.__set__('canAccess', function(file) {
return true;
});
chromeFinderLinuxModule.__set__('isExecutable', function(file) {
return true;
});
const executables = findChromeExecutablesForLinux(mockPaths, includeChromium);
expect(executables).to.have.lengthOf(5);
const expectedExecutables = mockPaths.map(mockPath => ['google-chrome-stable', 'google-chrome', 'chromium', 'chromium-browser', 'chromium/chrome'].map(executable => mockPath + '/' + executable)).reduce((acc, val) => acc.concat(val), []);
expect(executables).to.deep.equal(expectedExecutables);
});
});
});
describe('Chrome Finder Darwin Module', function() {
describe('Darwin when includeChromium=false', function() {
it('should only find Chrome', function() {
const includeChromium = false;
const mockChromePaths = [
'/Applications/Google Chrome.app'
];
chromeFinderDarwinModule.__set__('canAccess', function(file) {
return true;
});
var execSyncCommand;
chromeFinderDarwinModule.__set__('execSync', function(command) {
execSyncCommand = command;
return Buffer.from(mockChromePaths.join('\n'));
});
const executables = findChromeForDarwin(includeChromium);
expect(execSyncCommand).to.not.include('|chromium');
expect(executables).to.have.lengthOf(1);
expect(executables).to.deep.equal(mockChromePaths.map(mockChromePath => mockChromePath + '/Contents/MacOS/Google Chrome'));
});
});
describe('Darwin when includeChromium=true', function() {
it('should only find Chrome', function() {
const includeChromium = true;
const mockChromePaths = [
'/Applications/Google Chrome.app',
'/Applications/Chromium.app'
];
const expectedExecutables = [
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
'/Applications/Chromium.app/Contents/MacOS/Chromium'
];
chromeFinderDarwinModule.__set__('canAccess', function(file) {
return expectedExecutables.includes(file);
});
var execSyncCommand;
chromeFinderDarwinModule.__set__('execSync', function(command) {
execSyncCommand = command;
return Buffer.from(mockChromePaths.join('\n'));
});
const executables = findChromeForDarwin(includeChromium);
expect(execSyncCommand).to.include('|chromium');
expect(executables).to.have.lengthOf(2);
expect(executables).to.deep.equal(expectedExecutables);
});
});
});
describe('Chrome Finder Win32 Module', function() {
describe('Win32 when includeChromium=false', function() {
it('should only find Chrome', function() {
const includeChromium = false;
chromeFinderWin32Module.__set__('canAccess', function(file) {
return true;
});
chromeFinderWin32Module.__set__('procesEnv', {
LOCALAPPDATA: 'mock-local-app-data',
PROGRAMFILES: 'mock-program-files',
'PROGRAMFILES(X86)': 'mock-program-files-x86'
});
const executables = findChromeForWin32(includeChromium);
expect(executables).to.have.lengthOf(9);
expect(executables).to.deep.equal([
'mock-local-app-data\\Google\\Chrome SxS\\Application\\chrome.exe',
'mock-local-app-data\\Google\\Chrome\\Application\\chrome.exe',
'mock-local-app-data\\chrome-win32\\chrome.exe',
'mock-program-files\\Google\\Chrome SxS\\Application\\chrome.exe',
'mock-program-files\\Google\\Chrome\\Application\\chrome.exe',
'mock-program-files\\chrome-win32\\chrome.exe',
'mock-program-files-x86\\Google\\Chrome SxS\\Application\\chrome.exe',
'mock-program-files-x86\\Google\\Chrome\\Application\\chrome.exe',
'mock-program-files-x86\\chrome-win32\\chrome.exe'
]);
});
});
describe('Win32 when includeChromium=true', function() {
it('should only find Chrome', function() {
const includeChromium = true;
chromeFinderWin32Module.__set__('canAccess', function(file) {
return true;
});
chromeFinderWin32Module.__set__('procesEnv', {
LOCALAPPDATA: 'mock-local-app-data',
PROGRAMFILES: 'mock-program-files',
'PROGRAMFILES(X86)': 'mock-program-files-x86'
});
const executables = findChromeForWin32(includeChromium);
expect(executables).to.have.lengthOf(12);
expect(executables).to.deep.equal([
'mock-local-app-data\\Google\\Chrome SxS\\Application\\chrome.exe',
'mock-local-app-data\\Google\\Chrome\\Application\\chrome.exe',
'mock-local-app-data\\chrome-win32\\chrome.exe',
'mock-local-app-data\\Chromium\\Application\\chrome.exe',
'mock-program-files\\Google\\Chrome SxS\\Application\\chrome.exe',
'mock-program-files\\Google\\Chrome\\Application\\chrome.exe',
'mock-program-files\\chrome-win32\\chrome.exe',
'mock-program-files\\Chromium\\Application\\chrome.exe',
'mock-program-files-x86\\Google\\Chrome SxS\\Application\\chrome.exe',
'mock-program-files-x86\\Google\\Chrome\\Application\\chrome.exe',
'mock-program-files-x86\\chrome-win32\\chrome.exe',
'mock-program-files-x86\\Chromium\\Application\\chrome.exe'
]);
});
});
});