How to use reportFailure method in wpt

Best JavaScript code snippet using wpt

assert.js

Source:assert.js Github

copy

Full Screen

...22 // Asserts |object|23 ok(object) {24 if (object)25 return;26 this.reportFailure('is not ok');27 }28 // Asserts !|object|29 notOk(object) {30 if (!object)31 return;32 this.reportFailure('is ok');33 }34 // Asserts |actual| == |expected|.35 equal(actual, expected) {36 if (actual == expected)37 return;38 this.reportFailure('expected ' + this.toString(expected) + ', but got ' + this.toString(actual));39 }40 // Asserts |actual| != |expected|.41 notEqual(actual, expected) {42 if (actual != expected)43 return;44 this.reportFailure('unexpectedly equals ' + this.toString(expected));45 }46 // Asserts |actual| === |expected|.47 strictEqual(actual, expected) {48 if (actual === expected)49 return;50 this.reportFailure('expected ' + this.toString(expected) + ', but got ' + this.toString(actual));51 }52 // Asserts |actual| !== |expected|.53 notStrictEqual(actual, expected) {54 if (actual !== expected)55 return;56 this.reportFailure('unexpectedly equals ' + this.toString(expected));57 }58 // Asserts that |actual| is deep equal to |expected|.59 deepEqual(actual, expected) {60 if (equals(actual, expected))61 return;62 // TODO(Russell): Improve this error message.63 this.reportFailure(this.toString(actual) + ' is not deep equal to ' + this.toString(expected));64 }65 // Asserts that |actual| is not deep equal to |expected|.66 notDeepEqual(actual, expected) {67 if (!equals(actual, expected))68 return;69 // TODO(Russell): Improve this error message.70 this.reportFailure('is deep equal to ' + this.toString(expected));71 }72 // Asserts |value| == true.73 isTrue(value) {74 if (value)75 return;76 this.reportFailure('evaluates to false');77 }78 // Assert whether |haystack| includes the |needle|.79 includes(haystack, needle) {80 if (haystack.includes(needle))81 return;82 this.reportFailure('expected ' + this.toString(haystack) + ' to include ' + this.toString(needle) + ', but it doesn\'t.');83 }84 // Assert that |haystack| does not include the |needle|.85 doesNotInclude(haystack, needle) {86 if (!haystack.includes(needle))87 return;88 this.reportFailure('expected ' + this.toString(haystack) + ' to not include ' + this.toString(needle) + ', but does.');89 }90 // Asserts valueToCheck > valueToBeAbove91 isAbove(valueToCheck, valueToBeAbove) {92 if (valueToCheck > valueToBeAbove)93 return;94 this.reportFailure('expected ' + this.toString(valueToCheck) + ' to be above ' + this.toString(valueToBeAbove));95 }96 // Asserts valueToCheck >= valueToBeAboveOrEqual97 // This is an addition for Las Venturas Playground.98 isAboveOrEqual(valueToCheck, valueToBeAboveOrEqual) {99 if (valueToCheck >= valueToBeAboveOrEqual)100 return;101 this.reportFailure('expected ' + this.toString(valueToCheck) + ' to be equal to or above ' + this.toString(valueToBeAboveOrEqual));102 }103 // Asserts valueToCheck < valueToBeBelow104 isBelow(valueToCheck, valueToBeBelow) {105 if (valueToCheck < valueToBeBelow)106 return;107 this.reportFailure('expected ' + this.toString(valueToCheck) + ' to be below ' + this.toString(valueToBeBelow));108 }109 // Asserts valueToCheck <= valueToBeBelowOrEqual110 // This is an addition for Las Venturas Playground.111 isBelowOrEqual(valueToCheck, valueToBeBelowOrEqual) {112 if (valueToCheck <= valueToBeBelowOrEqual)113 return;114 this.reportFailure('expected ' + this.toString(valueToCheck) + ' to be equal to or below ' + this.toString(valueToBeBelowOrEqual));115 }116 // Asserts |value| == false.117 isFalse(value) {118 if (!value)119 return;120 this.reportFailure('evaluates to true');121 }122 // Asserts |value| === null.123 isNull(value) {124 if (value === null)125 return;126 this.reportFailure('expected NULL, but got ' + this.toString(value));127 }128 // Asserts |value| !== null.129 isNotNull(value) {130 if (value !== null)131 return;132 this.reportFailure('evaluates to NULL');133 }134 // Asserts |value| === undefined.135 isUndefined(value) {136 if (value === undefined)137 return;138 this.reportFailure('expected undefined, but got ' + this.toString(value));139 }140 // Asserts |value| !== undefined.141 isDefined(value) {142 if (value !== undefined)143 return;144 this.reportFailure('evaluates to undefined');145 }146 // Asserts typeof |value| === "function".147 isFunction(value) {148 if (typeof value === "function")149 return;150 this.reportFailure('expected a function, but got ' + this.toString(value));151 }152 // Asserts typeof |value| !== "function".153 isNotFunction(value) {154 if (typeof value !== "function")155 return;156 this.reportFailure('evaluates to a function');157 }158 // Asserts typeof |value| === "object" && !Array.isArray(|value|).159 isObject(value) {160 if (typeof value === "object" && !Array.isArray(value))161 return;162 this.reportFailure('expected an object, but got ' + this.toString(value));163 }164 // Asserts typeof |value| !== "function".165 isNotObject(value) {166 if (typeof value !== "object" || Array.isArray(value))167 return;168 this.reportFailure('evaluates to an object');169 }170 // Asserts Array.isArray(value).171 isArray(value) {172 if (Array.isArray(value))173 return;174 this.reportFailure('expected an array, but got ' + this.toString(value));175 }176 // !Asserts Array.isArray(value).177 isNotArray(value) {178 if (!Array.isArray(value))179 return;180 this.reportFailure('evaluates to an array');181 }182 // Asserts typeof |value| === "string".183 isString(value) {184 if (typeof value === "string")185 return;186 this.reportFailure('expected a string, but got ' + this.toString(value));187 }188 // Asserts typeof |value| !== "string".189 isNotString(value) {190 if (typeof value !== "string")191 return;192 this.reportFailure('evaluates to a string');193 }194 // Asserts typeof |value| === "number".195 isNumber(value) {196 if (typeof value === "number")197 return;198 this.reportFailure('expected a number, but got ' + this.toString(value));199 }200 // Asserts typeof |value| !== "number".201 isNotNumber(value) {202 if (typeof value !== "number")203 return;204 this.reportFailure('evaluates to a number');205 }206 // Asserts typeof |value| === "boolean".207 isBoolean(value) {208 if (typeof value === "boolean")209 return;210 this.reportFailure('expected a boolean, but got ' + this.toString(value));211 }212 // Asserts typeof |value| !== "boolean".213 isNotBoolean(value) {214 if (typeof value !== "boolean")215 return;216 this.reportFailure('evaluates to a boolean');217 }218 // -----------------------------------------------------------------------------------------------219 // Asserts typeof value === name220 typeOf(value, name) {221 if (typeof value === name)222 return;223 this.reportFailure('expected type ' + this.toString(name) + ', but got ' + this.toString(value));224 }225 // Asserts typeof value !== name226 notTypeOf(value, name) {227 if (typeof value !== name)228 return;229 this.reportFailure('has type ' + this.toString(name));230 }231 // -----------------------------------------------------------------------------------------------232 // Asserts (object instanceof constructor)233 instanceOf(object, constructor) {234 if (object instanceof constructor)235 return;236 this.reportFailure('expected ' + this.toString(object) + ' to be instance of ' + constructor.name);237 }238 // Asserts !(object instanceof constructor)239 notInstanceOf(object, constructor) {240 if (!(object instanceof constructor))241 return;242 this.reportFailure('is instance of ' + constructor.name);243 }244 // -----------------------------------------------------------------------------------------------245 // Asserts that executing |fn| throws an exception of |type|.246 // TODO(Russell): Also allow asserting on the exception's message.247 throws(fn, type) {248 if (typeof fn !== 'function')249 this.reportFailure('|fn| must be a function');250 let threw = true;251 try {252 fn();253 threw = false;254 } catch (e) {255 if (typeof type === 'undefined')256 return;257 if ((typeof type === 'function' && e instanceof type) ||258 (typeof type === 'string' && e.name == type))259 return;260 let textualType = typeof type == 'string' ? type261 : this.toString(type);262 this.reportFailure('expected ' + textualType + ' exception, but got ' + e.name);263 }264 if (!threw)265 this.reportFailure('did not throw');266 }267 // Asserts that executing |fn| does not throw an exception.268 doesNotThrow(fn) {269 if (typeof fn !== 'function')270 this.reportFailure('|fn| must be a function');271 try {272 fn();273 } catch (e) {274 this.reportFailure('threw a ' + e.name + ' (' + e.message + ')');275 }276 }277 // -----------------------------------------------------------------------------------------------278 // Asserts Math.abs(actual - expected) <= delta279 closeTo(actual, expected, delta) {280 if (Math.abs(actual - expected) <= delta)281 return;282 this.reportFailure('expected ' + this.toString(actual) + ' to be close (~' + delta + ') to ' + this.toString(expected));283 }284 // Asserts Math.abs(actual - expected) > delta285 notCloseTo(actual, expected, delta) {286 if (Math.abs(actual - expected) > delta)287 return;288 this.reportFailure('expected ' + this.toString(actual) + ' to not be close (~' + delta + ') to ' + this.toString(expected));289 }290 // -----------------------------------------------------------------------------------------------291 // Creates a failure because the current place in the code execution should not be reached.292 notReached() {293 this.reportFailure('the code was unexpectedly reached');294 }295 // -----------------------------------------------------------------------------------------------296 // Creates a failure because of an unexpected promise resolution.297 unexpectedResolution() {298 this.reportFailure('promise was not expected to resolve');299 }300 // Creates a failure because of an unexpected promise rejection.301 unexpectedRejection() {302 this.reportFailure('promise was not expected to reject');303 }304 // -----------------------------------------------------------------------------------------------305 // Asserts that a certain Pawn function has been called, optionally with the given signature and306 // arguments. The last |times| calls will be considered for the assertion.307 pawnCall(fn, { signature = null, args = null, times = 1 } = {}) {308 const calls = MockPawnInvoke.getInstance().calls;309 let count = 0;310 for (const call of calls) {311 if (call.fn != fn)312 continue; // call to another Pawn method313 if (signature !== null && call.signature != signature)314 continue; // signature was provided, and differs315 if (args !== null && !equals(call.args, args))316 continue; // arguments were provided, but differ317 if (++count >= times)318 break;319 }320 if (count < times)321 this.reportFailure('expected ' + times + ' call(s) to ' + fn + ', got ' + count);322 }323 // Asserts that a certain Pawn function has *not* been called, optionally with the given signature324 // and arguments. The last |times| calls will be considered for the assertion.325 noPawnCall(fn, { signature = null, args = null, times = 1 } = {}) {326 let exceptionThrown = false;327 try {328 this.pawnCall(fn, { signature, args, times });329 } catch (e) {330 exceptionThrown = true;331 }332 if (!exceptionThrown)333 this.reportFailure('expected no call(s) to ' + fn);334 }335 // -----------------------------------------------------------------------------------------------336 // Coerces |value| to a string.337 toString(value) {338 if (value === null)339 return 'null';340 else if (value === undefined)341 return 'undefined';342 else if (Number.isNaN(value))343 return 'NaN';344 return value.toString();345 }346 // Reports |failure| by throwing an AssertionFailedError. This method should only be called by347 // methods within this class, tests should use the exposed assertions instead.348 reportFailure(message) {349 if (this.context_)350 message += ` [context: ${this.context_}]`;351 throw new AssertionFailedError({ suiteDescription: this.suite_.description,352 testDescription: this.description_,353 innerError: new Error() },354 message);355 }...

Full Screen

Full Screen

websocket-worker.js

Source:websocket-worker.js Github

copy

Full Screen

1let port;2let received = false;3function reportFailure(details) {4 port.postMessage('FAIL: ' + details);5}6onmessage = event => {7 port = event.source;8 const ws = new WebSocket('wss://{{host}}:{{ports[wss][0]}}/echo');9 ws.onopen = () => {10 ws.send('Hello');11 };12 ws.onmessage = msg => {13 if (msg.data !== 'Hello') {14 reportFailure('Unexpected reply: ' + msg.data);15 return;16 }17 received = true;18 ws.close();19 };20 ws.onclose = (event) => {21 if (!received) {22 reportFailure('Closed before receiving reply: ' + event.code);23 return;24 }25 port.postMessage('PASS');26 };27 ws.onerror = () => {28 reportFailure('Got an error event');29 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 if(err) {4 console.log(err);5 } else {6 console.log('Test submitted. Polling for results.');7 wpt.waitRunTest(data.data.testId, function(err, data) {8 if(err) {9 console.log(err);10 } else {11 console.log('Got test results.');12 console.log(data);13 }14 });15 }16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3}, function(err, data) {4 if (err) {5 console.log(err);6 } else {7 var testId = data.data.testId;8 wpt.getTestStatus(testId, function(err, data) {9 if (err) {10 console.log(err);11 } else {12 if (data.statusCode !== 200) {13 wpt.reportFailure(testId, function(err, data) {14 if (err) {15 console.log(err);16 } else {17 console.log(data);18 }19 });20 }21 }22 });23 }24});25### WebPageTest(server, options)26### wpt.runTest(url, options, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var webpagetest = new wpt(options);5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});

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 wpt 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