How to use this.runMultiple method in ava

Best JavaScript code snippet using ava

runner.js

Source:runner.js Github

copy

Full Screen

...238 updateSnapshots: this.updateSnapshots,239 metadata: task.metadata,240 title: `${task.title}${titleSuffix || ''}`241 }));242 return this.runMultiple(hooks, this.serial).then(outcome => {243 if (outcome.allPassed) {244 return true;245 }246 // Only emit results for failed hooks.247 for (const result of outcome.storedResults) {248 if (!result.passed) {249 this.emit('stateChange', {250 type: 'hook-failed',251 title: result.title,252 err: serializeError('Hook failure', true, result.error),253 duration: result.duration,254 logs: result.logs255 });256 }...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1import { Manager as Steps } from './Steps';2import utils from './utils';3import * as commands from './commands';4import { EventEmitter } from 'events';5import safeEval from 'safe-eval';6import puppeteer from 'puppeteer';7exports.utils = utils;8exports.commands = commands;9exports.Scrappy = class Scrappy extends EventEmitter {10 /**11 * The Map of pages in this instance.12 */13 pages = new Map();14 /**15 * The browser instance from the `BrowserManager`. Used to launch16 * a new browser.17 */18 browser;19 /**20 * The options you want to use for the puppeteer instance.21 */22 options = { headless: false };23 isRunning = false;24 currentlyRunning = new Map();25 /**26 * Manages the puppeteer browser instance, can add pages, can delete pages,27 * and can run the pages either by specific ID or all at once.28 *29 * @constructor30 *31 * @params {Object} opts The options used for the puppeteer launch instance. See https://github.com/GoogleChrome/puppeteer32 * for further details33 *34 * @returns {void}35 *36 */37 constructor(opts) {38 super();39 this.options = opts || { headless: false };40 41 this.once('end', this.#onBrowserClose.bind(this));42 this.once('start', this.#onBrowserOpen.bind(this));43 this.on('page-start', this.#onPageStart.bind(this));44 this.on('page-error', this.#onPageError.bind(this));45 this.on('page-data', this.#onPageData.bind(this));46 this.on('page-end', this.#onPageEnd.bind(this));47 }48 #onBrowserClose = async () => {49 if (this.browser) {50 await this.browser.close();51 this.browser = null;52 this.isRunning = false;53 }54 };55 #onBrowserOpen = async () => {56 if (this.isRunning) return;57 58 this.isRunning = true;59 };60 #onPageStart = async ({ page, steps, id }) => {61 this.currentlyRunning.set(`${id}`, page);62 return await this.runSteps(id, page, steps);63 };64 #onPageEnd = async (id, errors) => {65 if (this.currentlyRunning.has(`${id}`)) {66 let page = this.currentlyRunning.get(`${id}`);67 await page.close();68 this.currentlyRunning.delete(`${id}`);69 }70 if (this.currentlyRunning.size === 0) {71 this.emit('end', errors);72 }73 return Promise.resolve();74 };75 #onPageError = (id, err) => {76 this.emit('error', { from: id, error: err });77 };78 #onPageData = ({ id, data }) => {79 this.emit('data', { from: id, results: data });80 }81 /**82 * Adds a page instance to the page manager. When using the Scrappy.run method83 * this will iterate through the `PageManager` property pages instance.84 *85 * @param {String} id The unique id for the page you are trying to add.86 *87 * @param {Array<object<string[]|string>>} steps An array of objects with the key88 * of the command you are attempting to run in the puppeteer instance and the89 * value of the steps which can either be a string or an array of strings.90 *91 * @param {Object<string>} props The properties you want to set for each step.92 * Generally, these are dynamic values such as a username and password input.93 *94 * @returns {void}95 *96 * @example97 *98 * import uuid from 'uuid/v4';99 * import Scrappy from '@movement-mortgage/scrappy';100 *101 * const pageId = uuid();102 * const steps = [{ goto: 'https://example.com' }, { type: [ '#browser', 'password' ] }];103 *104 * const props = { password: 'This is a dynamic value password' };105 *106 * const scrappy = new Scrappy({ headless: false });107 *108 * scrappy.addPage(pageId, steps, props);109 *110 * scrappy.run();111 *112 * // or113 *114 * scrappy.run(pageId) 115 *116 */117 addPage(id, steps, props={}) {118 if (!this.pages.has(`${id}`) && !this.isRunning) {119 this.pages.set(`${id}`, new Steps(steps, props));120 }121 }122 /**123 * Removes the page from the `PageManager` instance. When you use the `run` method next time,124 * the page that was removed will not be run.125 *126 * @param {string} id The id of the page you want to remove.127 *128 * @returns {void}129 *130 * @example131 *132 * import uuid from 'uuid/v4';133 * import Scrappy from '@movement-mortgage/scrappy';134 *135 * const pageId = uuid();136 * const steps = [{ goto: 'https://example.com' }, { type: [ '#browser', 'password' ] }];137 *138 * const props = { password: 'This is a dynamic value password' };139 *140 * const scrappy = new Scrappy({ headless: false });141 *142 * scrappy.addPage(pageId, steps, props);143 *144 * scrappy.run();145 *146 * // or147 *148 * scrappy.run(pageId);149 *150 * // Now let's remove the page151 * scrappy.removePage(pageId);152 *153 * console.log(scrappy.pages.has(pageId)) // outputs false154 *155 * // That page will no longer appear.156 * scrappy.run();157 *158 */159 removePage(id) {160 if (this.pages.has(id) && !this.isRunning) {161 this.pages.delete(id);162 };163 }164 async runSteps(id, page, steps) {165 let errors = [];166 if (steps instanceof Map) {167 for (let [ key, value ] of steps.entries()) {168 let args = value;169 let func = key.replace(/:[0-9]+$/, '');170 if (/evaluate/.test(key)) {171 let fn = safeEval(args[0]);172 args = [fn, ...args.slice(1)];173 }174 try {175 let results = await page[func](...args);176 if (/evaluate/.test(key)) {177 this.emit('page-data', { id, data: results })178 }179 } catch(e) {180 errors.push(e.message);181 }182 }183 } else if (!steps) {184 errors.push('You cannot have 0 steps for a page.');185 }186 let hasErrors;187 if (errors.length > 0) {188 hasErrors = errors;189 }190 this.emit('page-end', id, hasErrors);191 }192 #runMultiple = async () => {193 for (let [ key, value ] of this.pages.entries()) {194 let page = await this.browser.newPage();195 this.emit('page-start', { page, steps: value.steps, id: key });196 }197 return Promise.resolve(true);198 };199 #runSingle = async (id) => {200 if (this.pages.has(id)) {201 let page = await this.browser.newPage();202 let instance = this.pages.get(id);203 this.emit('page-start', { page, steps: instance.steps, id });204 }205 };206 /**207 * Launches the puppeteer instance from the `BrowserManager` if one does208 * not already exists. Iterates through all pages in the `PageManager` property209 * instance, or if the optional parameter of `pageId` is defined, then just run210 * that one page.211 *212 * @param {string?} pageId The id of the page that you want to run, if the page does not exist213 * then throw an error, if the page id is undefined then run all pages in the `PageManager` property.214 *215 * @returns {Promise<any>} returns the close method of the `BrowserManager` property.216 *217 * @example218 *219 * import uuid from 'uuid/v4';220 * import Scrappy from '@movement-mortgage/scrappy';221 *222 * const pageId = uuid();223 * const steps = [{ goto: 'https://example.com' }, { type: [ '#browser', 'password' ] }];224 *225 * const props = { password: 'This is a dynamic value password' };226 *227 * const scrappy = new Scrappy({ headless: false });228 *229 * // see `addPage` method for further details230 * scrappy.addPage(pageId, steps, props);231 *232 * scrappy.run();233 *234 * // or235 *236 * scrappy.run(pageId);237 *238 */239 async run(pageId) {240 this.browser = await puppeteer.launch(this.options);241 this.emit('start');242 if (!pageId) {243 await this.#runMultiple();244 } else {245 await this.#runSingle(pageId)246 }247 }...

Full Screen

Full Screen

container-api.js

Source:container-api.js Github

copy

Full Screen

1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 *19 */20const axios = require('axios');21/**22 * For testing convenience, this interface abstracts away the REST calls to a23 * container as blocking method calls of this interface.24 */25class ContainerApi {26 /**27 * non glie piace28 * @param {function} init function to initialize container29 * @param {function} run function to execute wsk function in container30 */31 constructor(init, run) {32 this.init = init;33 this.run = run;34 // this.runMultiple = runMultiple; TODO run multiple35 }36}37// Create an instance of the mock container interface for testing38const mockContainerApi = (ip, port) => new ContainerApi(39 (value) => syncPost(ip, port, '/init', value),40 (value) => syncPost(ip, port, '/run', value),41 // (values) => concurrentSyncPost(ip, port, "/run", values) TODO42);43const syncPost = (host, port, endPoint, content) =>44 axios({45 method: 'POST',46 url: `http://${host}:${port}${endPoint}`,47 data: content,48 validateStatus: () => true,49 });50module.exports = {51 mockContainerApi,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1test('multiple', t => {2 return t.runMultiple([3 t => {4 t.is('foo', 'foo');5 },6 t => {7 t.is('bar', 'bar');8 }9 ]);10});11test('foo', t => {12 t.is('foo', 'foo');13});14test('bar', t => {15 t.is('bar', 'bar');16});

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2const { runMultiple } = require('ava/lib/worker/subprocess');3const path = require('path');4 path.join(__dirname, 'test1.js'),5 path.join(__dirname, 'test2.js'),6 path.join(__dirname, 'test3.js')7];8test('test', async t => {9 const result = await runMultiple(files, {10 });11 console.log(result);12});13const test = require('ava');14test('test1', t => {15 t.pass();16});17const test = require('ava');18test('test2', t => {19 t.pass();20});21const test = require('ava');22test('test3', t => {23 t.pass();24});

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2const { runMultiple } = require('ava');3test('runMultiple', async t => {4 const result = await runMultiple([5 {file: 'test1.js'},6 {file: 'test2.js'}7 ]);8 t.true(result.passed);9});

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2const { runMultiple } = require('ava');3test('runMultiple', async t => {4 const result = await runMultiple([5 {file: 'test1.js'},6 {file: 'test2.js'}7 ], {concurrency: 2});8 t.is(result.passCount, 2);9 t.is(result.failCount, 0);10 t.is(result.skipCount, 0);11 t.is(result.rejectionCount, 0);12 t.is(result.exceptionCount, 0);13 t.is(result.todoCount, 0);14 t.is(result.duration, 2000);15 t.is(result.tests.length, 2);16 t.is(result.tests[0].title, 'title1');17 t.is(result.tests[1].title, 'title2');18});19const test = require('ava');20test('title1', t => {21 setTimeout(() => {22 t.pass();23 }, 1000);24});25const test = require('ava');26test('title2', t => {27 setTimeout(() => {28 t.pass();29 }, 1000);30});31### runMultiple(files, [options])

Full Screen

Using AI Code Generation

copy

Full Screen

1import test from 'ava';2import { runMultiple } from 'ava';3import path from 'path';4import { promisify } from 'util';5import { exec } from 'child_process';6const execAsync = promisify(exec);7const testPath = path.resolve(__dirname, 'test.js');8test('run multiple test', async t => {9 const { stdout, stderr } = await execAsync(10 `node_modules/.bin/ava ${testPath} --verbose`11 );12 console.log(stdout);13 console.log(stderr);14 t.pass();15});16import test from 'ava';17import { runMultiple } from 'ava';18import path from 'path';19import { promisify } from 'util';20import { exec } from 'child_process';21const execAsync = promisify(exec);22const testPath = path.resolve(__dirname, 'test.js');23test('run multiple test', async t => {24 const { stdout, stderr } = await execAsync(25 `node_modules/.bin/ava ${testPath} --verbose`26 );27 console.log(stdout);28 console.log(stderr);29 t.pass();30});31import test from 'ava';32import { runMultiple } from 'ava';33import path from 'path';34import { promisify } from 'util';35import { exec } from 'child_process';36const execAsync = promisify(exec);37const testPath = path.resolve(__dirname, 'test.js');38test('run multiple test', async t => {39 const { stdout, stderr } = await execAsync(40 `node_modules/.bin/ava ${testPath} --verbose`41 );42 console.log(stdout);43 console.log(stderr);44 t.pass();45});46import test from 'ava';47import { runMultiple } from 'ava';48import path from 'path';49import { promisify } from 'util';50import { exec } from 'child_process';51const execAsync = promisify(exec);52const testPath = path.resolve(__dirname, 'test.js');53test('run multiple test', async t => {54 const { stdout, stderr } = await execAsync(55 `node_modules/.bin/ava ${testPath} --verbose`56 );

Full Screen

Using AI Code Generation

copy

Full Screen

1test('my test', this.runMultiple, [2 async t => {3 },4 async t => {5 }6]);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ava 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