How to use _getManifest method in Cypress

Best JavaScript code snippet using cypress

addon_manager.js

Source:addon_manager.js Github

copy

Full Screen

...123 * @param {DOMApplication} app124 * @returns {Boolean}125 */126 _privilegeCheck: function(addon, app) {127 var addonManifest = this._getManifest(addon);128 var appManifest = this._getManifest(app);129 return addonManifest.type === appManifest.type ||130 addonManifest.type === 'certified' ||131 addonManifest.type === 'privileged';132 },133 /**134 * Get the manifest.135 *136 * @access private137 * @memberOf AddonManager.prototype138 * @param {DOMApplication} app139 * @returns {Object}140 */141 _getManifest: function(app) {142 return app.manifest || app.updateManifest;143 },144 /**145 * Check whether reboot is required when disabling the addon.146 *147 * @access private148 * @memberOf AddonManager.prototype149 * @param {DOMApplication} app150 * @param {Array} contentScripts151 * @returns {Boolean}152 */153 _needsReboot: function({app, contentScripts}) {154 var manifest = this._getManifest(app);155 var role = manifest.role;156 // If the addon affects a system app157 if (role === 'system' || role === 'homescreen') {158 // and the app is customized with a script, then we need reboot159 return contentScripts.some(c => c.js.length > 0);160 } else {161 return false;162 }163 },164 /**165 * Check whether restart is required when disabling the addon.166 *167 * @access private168 * @memberOf AddonManager.prototype169 * @param {DOMApplication} app170 * @param {Array} contentScripts171 * @returns {Boolean}172 */173 _needsRestart: function({app, contentScripts}) {174 return contentScripts.some(c => c.js.length > 0);175 },176 /**177 * Check whether this app is an addon.178 *179 * @access private180 * @memberOf AddonManager.prototype181 * @param {DOMApplication} app182 * @returns {Boolean}183 */184 _isAddon: function(app) {185 var manifest = this._getManifest(app);186 return manifest && manifest.role === 'addon';187 },188 /**189 * This internal utility function returns an array of objects describing190 * the apps that are affected by the given addon.191 *192 * @access private193 * @memberOf AddonManager.prototype194 * @param {DOMApplication} addon195 * @returns {Boolean}196 */197 _getAffectedApps: function(addon) {198 if (!this._isAddon(addon)) {199 return Promise.reject('not an addon');200 }201 var manifest = this._getManifest(addon);202 var customizations = manifest && manifest.customizations;203 // content_scripts field is internally copied from manifest.json to204 // manifest.webapp205 var contentScripts = manifest && manifest.content_scripts;206 // If the addon specifies customizations, then it is obsolete and does not207 // work208 if (customizations) {209 return Promise.resolve([]);210 }211 // If there are no content scripts or content scripts list is empty, the212 // addon does not affect any apps.213 if (!contentScripts || contentScripts.length === 0) {214 return Promise.resolve([]);215 }216 return AppsCache.apps()217 .then(apps => apps.filter(app => {218 var manifest = this._getManifest(app);219 // Ignore apps that are themselves add-ons or if the addon doesn't220 // have high enough privileges to affect this app then we can just221 // return now.222 return manifest.role !== 'addon' &&223 this._privilegeCheck(addon, app);224 }))225 // Match apps based on add-on's content sctipts.226 .then(apps => {227 var matches = [];228 apps.forEach(app => {229 var matched;230 if ((matched = this._matchContentScripts(contentScripts, app))) {231 matches.push({ app: app, contentScripts: matched });232 }233 });234 return matches;235 })236 .catch(() => []);237 },238 /**239 * Returns a list of content scripts (from an addon manifest), if available,240 * that affect the app by a given addon. We implement getAddonTargets()241 * using this information , derive the 'reboot' and 'restart' return242 * values of disableAddon() from it and also use this function to apply243 * addon filters.244 *245 * @access private246 * @memberOf AddonManager.prototype247 * @param {DOMApplication} addon248 * @param {DOMApplication} app249 * @returns {Array?} appliedContentScripts if available250 */251 _matchContentScripts: function(contentScripts, app) {252 var manifest = this._getManifest(app);253 // Get the URL of the app origin plus its launch path to254 // compare against each of the filters.255 // XXX: Note that we and do not check the paths used by256 // activity handlers or any other paths in the manifest.257 var launchPath = manifest.launch_path || '';258 var launchURL = new URL(launchPath, app.origin);259 // For each content script, compile the pattern string MatchPattern260 var patterns = contentScripts.map(contentScript => {261 return {262 matches: new MatchPattern(contentScript.matches),263 excludeMatches: new MatchPattern(contentScript.exclude_matches)264 };265 });266 var appliedContentScripts = [];267 // Now loop through the patterns to see what content scripts are applied268 // to this app269 for(var i = 0; i < patterns.length; i++) {270 var pattern = patterns[i];271 if (!pattern.excludeMatches.matches(launchURL) &&272 pattern.matches.matches(launchURL)) {273 appliedContentScripts.push(contentScripts[i]);274 break;275 }276 }277 // If any content scripts were applied to this app, return the list of278 // appliedContentScripts279 if (appliedContentScripts.length > 0) {280 return appliedContentScripts;281 }282 },283 /**284 * Convert exported add-on into an Array Buffer.285 *286 * @access private287 * @memberOf AddonManager.prototype288 * @param {Blob} blob289 * @returns {Promise}290 */291 _blobToArrayBuffer: function(blob) {292 return new Promise(function(resolve, reject) {293 var fileReader = new FileReader();294 fileReader.onload = function() {295 resolve(fileReader.result);296 };297 fileReader.onerror = function(reason) {298 reject(reason);299 };300 fileReader.readAsArrayBuffer(blob);301 });302 },303 /**304 * Upack an add-on script.305 *306 * @access private307 * @memberOf AddonManager.prototype308 * @param {ArrayBuffer} arrayBuffer309 * @returns {Promise}310 */311 _unpackScript: function(arrayBuffer) {312 return this._JSZip.then(JSZip => {313 var zip = new JSZip();314 zip.load(arrayBuffer);315 var applicationZipFile = zip.file('application.zip');316 if (!applicationZipFile) { return; }317 var applicationZip = new JSZip();318 applicationZip.load(applicationZipFile.asArrayBuffer());319 var scriptFile = applicationZip.file('main.js');320 if (!scriptFile) { return; }321 return(scriptFile.asText());322 });323 },324 /**325 * Generate a new add-on.326 *327 * @access private328 * @memberOf AddonManager.prototype329 * @param {JSON} manifest add-on manifest330 * @param {String} script add-on script331 * @returns {Promise}332 */333 _generate: function(manifest, script) {334 return this._JSZip.then(JSZip => {335 var id = 'addon' + Math.round(Math.random() * 100000000);336 var applicationZip = new JSZip();337 // Ensure that we are creating an addon with a new id.338 manifest.role = 'addon';339 manifest.type = 'certified';340 manifest.origin = 'app://' + id + '.gaiamobile.org';341 manifest.activities = manifest.activities || {};342 applicationZip.file('manifest.webapp', JSON.stringify(manifest));343 applicationZip.file('main.js', script);344 var packageZip = new JSZip();345 packageZip.file('metadata.json', JSON.stringify({346 installOrigin: 'http://gaiamobile.org',347 manifestURL: 'app://' + id + '.gaiamobile.org/update.webapp',348 version: 1349 }));350 packageZip.file('update.webapp', JSON.stringify({351 name: manifest.name,352 package_path: '/application.zip'353 }));354 packageZip.file('application.zip',355 applicationZip.generate({ type: 'arraybuffer' }));356 return new Blob([packageZip.generate({ type: 'arraybuffer' })],357 { type: 'application/zip' });358 });359 },360 /**361 * Lazily require jszip. It is currently used only for renaming Add-ons.362 *363 * @access private364 * @memberOf AddonManager.prototype365 * @returns {Promise}366 */367 get _JSZip() {368 return new Promise(resolve => { require(['vendor/jszip'], resolve); });369 },370 /**371 * Install add-on, but importing it using a memory-backed blob.372 *373 * @access private374 * @memberOf AddonManager.prototype375 * @param {Blob} blob add-on blob376 * @returns {Promise}377 */378 _install: function(blob) {379 return navigator.mozApps.mgmt.import(blob).then(addon => {380 // Enable the addon by default.381 var app = { instance: addon };382 this.enableAddon(app);383 return app;384 });385 },386 /**387 * Check whether an addon is enabled.388 *389 * @access public390 * @memberOf AddonManager.prototype391 * @param {App} addon392 * @returns {Boolean}393 */394 isEnabled: function(addon) {395 return this._isAddon(addon.instance) && addon.instance.enabled === true;396 },397 /**398 * Check whether an addon can be deleted.399 *400 * @access public401 * @memberOf AddonManager.prototype402 * @param {App} addon403 * @returns {Boolean}404 */405 canDelete: function(addon) {406 return this._isAddon(addon.instance) && addon.instance.removable === true;407 },408 /**409 * Enable an addon410 *411 * @access public412 * @memberOf AddonManager.prototype413 * @param {App} addon414 */415 enableAddon: function(addon) {416 if (this._isAddon(addon.instance) && !addon.instance.enabled) {417 mozApps.mgmt.setEnabled(addon.instance, true);418 }419 },420 /**421 * Disable an addon. Returns a string indicating whether reboot or restart422 * required for disabling the addon completely.423 *424 * @access public425 * @memberOf AddonManager.prototype426 * @param {App} addon427 */428 disableAddon: function(addon) {429 if (this._isAddon(addon.instance) && addon.instance.enabled) {430 mozApps.mgmt.setEnabled(addon.instance, false);431 }432 },433 /**434 * Delete an addon.435 *436 * @access public437 * @memberOf AddonManager.prototype438 * @param {App} addon439 * @returns {Promise}440 */441 deleteAddon: function(addon) {442 if (!this._isAddon(addon.instance)) {443 return Promise.reject('not an addon');444 }445 if (!addon.instance.removable) {446 return Promise.reject('addon is not deletable');447 }448 return new Promise(function(resolve, reject) {449 var request = mozApps.mgmt.uninstall(addon.instance);450 request.onsuccess = function() {451 resolve();452 };453 request.onerror = function() {454 reject();455 };456 });457 },458 /**459 * Rename an addon.460 *461 * @access public462 * @memberOf AddonManager.prototype463 * @param {App} addon464 * @param {String} name addon name465 * @returns {Promise}466 */467 renameAddon: function(addon, name) {468 if (!name) {469 return Promise.reject('no name given');470 }471 if (!this._isAddon(addon.instance)) {472 return Promise.reject('not an addon');473 }474 var manifest = this._getManifest(addon.instance);475 if (name === manifest.name) {476 return Promise.reject('name is unchanged');477 }478 var newManifest, addonBlob;479 // To rename an addon we are creating a new DOMApplication that will have480 // an updated name. Other manifest attributes are preserved.481 // Export an add-on as a blob.482 return addon.instance.export().then(blob => {483 addonBlob = blob;484 // Copy over manifest object.485 newManifest = Object.assign({}, manifest);486 newManifest.name = name;487 // Delete original add-on.488 return this.deleteAddon(addon);489 }).then(() => {490 // Convert exported add-on into an Array Buffer.491 return this._blobToArrayBuffer(addonBlob);492 }).then(this._unpackScript.bind(this)).then(script => {493 // Generate a new add-on using the original manifest and a new name.494 return this._generate(newManifest, script);495 }).then(this._install.bind(this));496 },497 /**498 * Share an addon.499 *500 * @access public501 * @memberOf AddonManager.prototype502 * @param {App} addon503 * @returns {Promise}504 */505 shareAddon: function(addon) {506 if (!this._isAddon(addon.instance)) {507 return Promise.reject('not an addon');508 }509 return new Promise(function(resolve, reject) {510 var activity = new window.MozActivity({511 name: 'share',512 data: {513 type: 'app',514 app: addon.instance.manifestURL515 }516 });517 activity.onsuccess = function() {518 resolve();519 };520 activity.onerror = function() {521 reject((activity.error && activity.error.name) || 'activity error');522 };523 });524 },525 /**526 * Return an array of the apps that are targeted by any of this527 * addon's content scripts. Note, however, that addons can also target528 * arbitrary web pages and hosted apps. This test only applies to529 * installed packaged apps and so may be of limited utility.530 *531 * @access public532 * @memberOf AddonManager.prototype533 * @param {App} addon534 * @returns {Promise}535 */536 getAddonTargets: function(addon) {537 return this._getAffectedApps(addon.instance).then((affectedApps) => {538 return affectedApps.map((x) => x.app);539 });540 },541 /**542 * Return a string indicating whether reboot or restart is required for543 * disabling the addon.544 *545 * @access public546 * @memberOf AddonManager.prototype547 * @param {App} addon548 * @returns {Promise.<String>}549 */550 getAddonDisableType: function(addon) {551 return this._getAffectedApps(addon.instance).then((affectedApps) => {552 var needsReboot = affectedApps.some(this._needsReboot.bind(this));553 if (needsReboot) {554 return 'reboot';555 }556 var needsRestart = affectedApps.some(this._needsRestart.bind(this));557 if (needsRestart) {558 return 'restart';559 }560 return '';561 });562 },563 /**564 * Return the App object that matches the given manifest url.565 *566 * @access public567 * @memberOf AddonManager.prototype568 * @param {String} manifestURL569 * @returns {Promise.<App>}570 */571 findAddonByManifestURL: function(manifestURL) {572 return AppsCache.apps().then(() => {573 return this._addons.array.find((addon) => {574 return addon.instance.manifestURL === manifestURL;575 });576 });577 },578 /**579 * Returns a promise for a boolean flag indicating whether an addon affects580 * an application or not..581 *582 * @access public583 * @memberOf AddonManager.prototype584 * @param {DOMApplication} addon addon to check585 * @param {String} manifestURL app manifest URL to check586 * @returns {Promise.<Boolean>}587 */588 addonAffectsApp: function(addon, manifestURL) {589 if (!manifestURL) {590 return Promise.reject('No manifestURL given for an app');591 }592 if (!this._isAddon(addon.instance)) {593 return Promise.reject('not an addon');594 }595 var manifest = this._getManifest(addon.instance);596 var customizations = manifest && manifest.customizations;597 // content_scripts field is internally copied from manifest.json to598 // manifest.webapp599 var contentScripts = manifest && manifest.content_scripts;600 // If the addon specifies customizations, then it is obsolete and does not601 // work602 if (customizations) {603 return Promise.resolve(false);604 }605 // If there are no content scripts or content scripts list is empty, the606 // addon does not affect any apps.607 if (!contentScripts || contentScripts.length === 0) {608 return Promise.resolve(false);609 }...

Full Screen

Full Screen

service_settings.js

Source:service_settings.js Github

copy

Full Screen

...38 if (!mapConfig.includeElasticMapsService) {39 return { services: [] };40 }41 try {42 const response = await this._getManifest(mapConfig.manifestServiceUrl, this._queryParams);43 return response.data;44 } catch (e) {45 if (!e) {46 e = new Error('Unkown error');47 }48 if (!(e instanceof Error)) {49 e = new Error(e.data || `status ${e.statusText || e.status}`);50 }51 throw new Error(`Could not retrieve manifest from the tile service: ${e.message}`);52 }53 });54 this._loadFileLayers = _.once(async () => {55 const catalogue = await this._loadCatalogue();56 const fileService = catalogue.services.find(service => service.type === 'file');57 if (!fileService) {58 return [];59 }60 const manifest = await this._getManifest(fileService.manifest, this._queryParams);61 const layers = manifest.data.layers.filter(layer => layer.format === 'geojson' || layer.format === 'topojson');62 layers.forEach((layer) => {63 layer.url = this._extendUrlWithParams(layer.url);64 layer.attribution = $sanitize(markdownIt.render(layer.attribution));65 });66 return layers;67 });68 this._loadTMSServices = _.once(async () => {69 const catalogue = await this._loadCatalogue();70 const tmsService = catalogue.services.find((service) => service.type === 'tms');71 if (!tmsService) {72 return [];73 }74 const tmsManifest = await this._getManifest(tmsService.manifest, this._queryParams);75 const preppedTMSServices = tmsManifest.data.services.map((tmsService) => {76 const preppedService = _.cloneDeep(tmsService);77 preppedService.attribution = $sanitize(markdownIt.render(preppedService.attribution));78 preppedService.subdomains = preppedService.subdomains || [];79 preppedService.url = this._extendUrlWithParams(preppedService.url);80 return preppedService;81 });82 return preppedTMSServices;83 });84 }85 _extendUrlWithParams(url) {86 return unescapeTemplateVars(extendUrl(url, {87 query: this._queryParams88 }));89 }90 /**91 * this internal method is overridden by the tests to simulate custom manifest.92 */93 async _getManifest(manifestUrl) {94 return $http({95 url: extendUrl(manifestUrl, { query: this._queryParams }),96 method: 'GET'97 });98 }99 async getFileLayers() {100 return await this._loadFileLayers();101 }102 /**103 * Returns all the services published by EMS (if configures)104 * It also includes the service configured in tilemap (override)105 */106 async getTMSServices() {107 const allServices = [];...

Full Screen

Full Screen

get-manifest.js

Source:get-manifest.js Github

copy

Full Screen

...30 */31function getManifest(_x) {32 return _getManifest.apply(this, arguments);33}34function _getManifest() {35 _getManifest = (0, _asyncToGenerator2.default)(function* (config) {36 // This check needs to be done before validation, since the deprecated options37 // will be renamed.38 const deprecationWarnings = checkForDeprecatedOptions(config);39 const options = validate(config, getManifestSchema);40 const _ref = yield getFileManifestEntries(options),41 manifestEntries = _ref.manifestEntries,42 count = _ref.count,43 size = _ref.size,44 warnings = _ref.warnings; // Add in any deprecation warnings.45 warnings.push(...deprecationWarnings);46 return {47 manifestEntries,48 count,...

Full Screen

Full Screen

updater.js

Source:updater.js Github

copy

Full Screen

...20}21const check = async ({ onNewVersion, onNoNewVersion } = {}) => {22 try {23 const id = await machineId()24 const manifest = await _getManifest(id)25 if (!manifest || !manifest.version) {26 throw new Error('manifest is empty or does not have a version')27 }28 debug('latest version of Cypress is:', manifest.version)29 const localVersion = pkg.version30 const newVersionAvailable = semver.gt(manifest.version, localVersion)31 if (newVersionAvailable) {32 debug('new version of Cypress exists:', manifest.version)33 onNewVersion(manifest)34 } else {35 debug('new version of Cypress does not exist')36 onNoNewVersion()37 }38 } catch (err) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress._getManifest().then((manifest) => {2 console.log(manifest)3})4Cypress._getManifest = () => {5 return cy.task('getManifest')6}7module.exports = (on, config) => {8 on('task', {9 getManifest () {10 return require('../../../manifest.json')11 },12 })13}14it('loads', () => {15 cy.visit('/')16 cy.get('h1').should('contain', Cypress._getManifest().name)17})18module.exports = (on, config) => {19 on('task', {20 getManifest () {21 return require('../../../manifest.json')22 },23 })24}25it('loads', () => {26 cy.visit('/')27 cy.task('getManifest').then((manifest) => {28 cy.get('h1').should('contain', manifest.name)29 })30})31module.exports = (on, config) => {32 on('task', {33 getManifest () {34 return require('../../../manifest.json')35 },36 })37}38it('loads', () => {39 cy.visit('/')40 cy.task('getManifest').then((manifest) => {41 cy.get('h1').should('contain', manifest.name)42 })43})

Full Screen

Using AI Code Generation

copy

Full Screen

1cy._getManifest().then((manifest) => {2});3Cypress.Commands.add('_getManifest', () => {4 const manifest = Cypress.env('manifest');5 if (!manifest) {6 return cy.readFile('manifest.json').then((json) => {7 Cypress.env('manifest', json);8 return json;9 });10 }11 return manifest;12});13Note: I’m using TypeScript and this is how I’m importing the command in my commands.ts file:14import './test';

Full Screen

Using AI Code Generation

copy

Full Screen

1const getManifest = () => {2 return cy.window().then((win) => {3 return win.__cypress_iframe.getManifest();4 });5};6describe("Cypress Test", () => {7 it("Cypress Test", () => {8 getManifest().then((manifest) => {9 console.log(manifest);10 });11 });12});

Full Screen

Using AI Code Generation

copy

Full Screen

1const manifest = Cypress._.getManifest()2Cypress.Commands.add('getVersion', () => {3 const manifest = Cypress._.getManifest()4 cy.log(`version: ${version}, buildNumber: ${buildNumber}`)5})6describe('Test', () => {7 it('get version', () => {8 cy.getVersion()9 })10})11describe('Test', () => {12 it('get version', () => {13 const manifest = Cypress._.getManifest()14 cy.log(`version: ${version}, buildNumber: ${buildNumber}`)15 })16})17describe('Test', () => {18 it('get version', () => {19 const manifest = Cypress._.getManifest()20 cy.log(`version: ${version}, buildNumber: ${buildNumber}`)21 })22})23describe('Test', () => {24 it('get version', () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const getManifest = () => {2 return cy.task('getManifest').its('version')3}4describe('My First Test', () => {5 it('Does not do much!', () => {6 getManifest().should('equal', '1.0.0')7 })8})9const getManifest = () => {10 return cy.task('getManifest')11}12module.exports = (on, config) => {13 on('task', {14 getManifest() {15 return require('../../manifest.json')16 }17 })18}

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful