appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
132 lines • 6.02 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../lib/utils");
const sinon_1 = require("sinon");
const support_1 = require("appium/support");
const chai_1 = __importStar(require("chai"));
const chai_as_promised_1 = __importDefault(require("chai-as-promised"));
chai_1.default.use(chai_as_promised_1.default);
const DERIVED_DATA_ROOT = '/path/to/DerivedData/WebDriverAgent-eoyoecqmiqfeodgstkwbxkfyagll';
describe('utils', function () {
describe('clearSystemFiles', function () {
let sandbox;
let mockFs;
beforeEach(function () {
sandbox = (0, sinon_1.createSandbox)();
mockFs = sandbox.mock(support_1.fs);
});
afterEach(function () {
sandbox.restore();
});
it('should delete logs', async function () {
const wda = {
retrieveDerivedDataPath() {
return DERIVED_DATA_ROOT;
},
};
mockFs.expects('glob').once().returns([]);
mockFs.expects('exists').atLeast(1).returns(true);
mockFs.expects('rimraf').once().withExactArgs(`${DERIVED_DATA_ROOT}/Logs`).resolves();
await (0, utils_1.clearSystemFiles)(wda);
mockFs.verify();
});
it('should only delete logs once if the same folder was marked twice for deletion', async function () {
const wda = {
retrieveDerivedDataPath() {
return DERIVED_DATA_ROOT;
},
};
mockFs.expects('glob').once().returns([]);
mockFs.expects('exists').atLeast(1).returns(true);
mockFs.expects('rimraf').once().withExactArgs(`${DERIVED_DATA_ROOT}/Logs`).resolves();
await (0, utils_1.markSystemFilesForCleanup)(wda);
await (0, utils_1.markSystemFilesForCleanup)(wda);
await (0, utils_1.clearSystemFiles)(wda);
await (0, utils_1.clearSystemFiles)(wda);
mockFs.verify();
});
it('should do nothing if no derived data path is found', async function () {
const wda = {
retrieveDerivedDataPath() {
return null;
},
};
mockFs.expects('rimraf').never();
await (0, utils_1.clearSystemFiles)(wda);
mockFs.verify();
});
});
describe('isLocalHost', function () {
it('should be false with invalid input, undefined', function () {
// @ts-expect-error invalid input
(0, chai_1.expect)((0, utils_1.isLocalHost)(undefined)).to.be.false;
});
it('should be false with invalid input, empty', function () {
(0, chai_1.expect)((0, utils_1.isLocalHost)('')).to.be.false;
});
it('should be true with ipv4 localhost', function () {
(0, chai_1.expect)((0, utils_1.isLocalHost)('http://localhost')).to.be.true;
});
it('should be true with ipv4 localhost with port', function () {
(0, chai_1.expect)((0, utils_1.isLocalHost)('http://localhost:8888')).to.be.true;
});
it('should be true with ipv4 127.0.0.1', function () {
(0, chai_1.expect)((0, utils_1.isLocalHost)('http://127.0.0.1')).to.be.true;
});
it('should be true with ipv6 ::1', function () {
(0, chai_1.expect)((0, utils_1.isLocalHost)('http://[::1]')).to.be.true;
});
it('should be true with ipv6 ::ffff:127.0.0.1', function () {
(0, chai_1.expect)((0, utils_1.isLocalHost)('http://[::ffff:127.0.0.1]')).to.be.true;
});
it('should be true with ipv6 ::ffff:127.0.0.1 with port', function () {
(0, chai_1.expect)((0, utils_1.isLocalHost)('http://[::ffff:127.0.0.1]:8888')).to.be.true;
});
it('should be false with ipv4 192.168.1.100', function () {
(0, chai_1.expect)((0, utils_1.isLocalHost)('http://192.168.1.100')).to.be.false;
});
it('should be false with ipv4 192.168.1.100 with port', function () {
(0, chai_1.expect)((0, utils_1.isLocalHost)('http://192.168.1.100:8888')).to.be.false;
});
it('should be false with ipv6 2001:db8:85a3:8d3:1319:8a2e:370:7348', function () {
(0, chai_1.expect)((0, utils_1.isLocalHost)('http://[2001:db8:85a3:8d3:1319:8a2e:370:7348]')).to.be.false;
});
});
});
//# sourceMappingURL=utils-specs.js.map