How to use testPassed method in wpt

Best JavaScript code snippet using wpt

FeatureDetection.js

Source:FeatureDetection.js Github

copy

Full Screen

1(function() {2 var detectors = {}, // Feature Detectors3 debugMode = false, // Toggles debug messages4 ie = { full : "fullie", ppb : "ppb", win8 : "win8" }; // IE Flavors5 // Log messages6 var log = function(message) {7 if(console && console.log) {8 console.log(message);9 }10 }11 // Log debug messages12 var debug = function(message) {13 if(debugMode) {14 log(message);15 }16 }17 // Helper object to parse the query string for values18 var queryStringHelper = {19 parse: function (variable) {20 var query = window.location.search.substring(1);21 var vars = query.split("&");22 for (var i = 0; i < vars.length; i++) {23 var pair = vars[i].split("=");24 if (pair[0] == variable) {25 return pair[1].replace(/%20/g, " ");26 }27 }28 return false;29 }30 }31 // Helper object to get information about browser (through UA string and checking other properties)32 var browserInfo = (function () {33 var isPPB = false; // if true, browser is an Internet Explorer platform preview34 var isPPB6 = false; // if true, browser is IE9 PPB6 or newer35 var isIE = false; // if true, browser is any version of Internet Explorer (including platform previews)36 var isChrome = false; // if true, browser is any version of Chrome37 var isOpera = false; // if true, browser is any version of Opera38 var isSafari = false; // if true, browser is any version of Safari39 var isFirefox = false; // if true, browser is any version of Firefox40 var browserVersion = 0; // Browser version number41 /* Initialize flags ------------------------------------------------*/42 var version;43 // Parse UA string for browser name and version44 if (version = document.documentMode) {45 isIE = true;46 browserVerison = document.documentMode;47 } else if (version = /Firefox\/(\d+\.\d+)/.exec(navigator.userAgent)) {48 isFirefox = true;49 browserVerison = parseFloat(version[1]);50 } else if (version = /Chrome\/(\d+\.\d+)/.exec(navigator.userAgent)) {51 isChrome = true;52 browserVerison = parseFloat(version[1]);53 } else if (version = /Opera.*Version\/(\d+\.\d+)/.exec(navigator.userAgent)) {54 isOpera = true;55 browserVerison = parseFloat(version[1]);56 } else if (version = /Version\/(\d+\.\d+).*Safari/.exec(navigator.userAgent)) {57 isSafari = true;58 browserVerison = parseFloat(version[1]);59 }60 // Check if this is an IE platform preview build, and if so, which one.61 if (isIE && typeof document.documentMode != 'undefined') {62 if (typeof window.external === 'object' && window.external == null) {63 isPPB = true;64 }65 }66 // Returns true if browser is any version of Internet Explorer, false otherwise67 var isInternetExplorer = function () {68 return isIE;69 }70 // Returns true if browser is any version of Internet Explorer Platform Preview, false otherwise71 var isPlatformPreview = function () {72 return isPPB;73 }74 // Returns true if browser is Internet Explorer 9 Platform Preview 6, or greater75 var isPlatformPreview6Plus = function () {76 return isPPB6;77 }78 // Returns true if browser is any version of Chrome, false otherwise79 var isChrome = function () {80 return isChrome;81 }82 // Returns true if browser is any version of Firefox, false otherwise83 var isFirefox = function () {84 return isFirefox;85 }86 // Returns true if browser is any version of Opera, false otherwise87 var isOpera = function () {88 return isOpera;89 }90 // Returns true if browser is any version of Safari, false otherwise91 var isSafari = function () {92 return isSafari;93 }94 // Returns browser version, as float95 var version = function () {96 return browserVerison;97 }98 return {99 isInternetExplorer : isInternetExplorer,100 isPlatformPreview : isPlatformPreview,101 isPlatformPreview6Plus : isPlatformPreview6Plus,102 isChrome : isChrome,103 isFirefox : isFirefox,104 isOpera : isOpera,105 isSafari : isSafari,106 version : version107 }108 }());109 // Add new feature detector to list110 var addDetector = function(name, description, failureMessage, upgradeChoices, testFunc) {111 detectors[name] = {112 name : name,113 description : description,114 failureMessage : failureMessage,115 upgradeChoices : upgradeChoices,116 test : testFunc117 };118 }119 // Called when feature detection test fails120 var fail = function(detector) {121 var choices = "&choices=" + encodeURI(detector.upgradeChoices);122 message = encodeURI(detector.failureMessage);123 debug("FAIL! (feature detector '" + detector.name + "'):");124 window.location.replace("http://ie.microsoft.com/testdrive/Info/MissingBrowserFeature/Default.html?message=" +125 message + "&url=" + window.location + choices);126 }127 // Called when feature detection passes128 var pass = function(detector) {129 debug("PASS! (feature detector '" + detector.name + "'):");130 }131 // Run configured detectors132 var run = function() {133 var scriptTags,134 scriptTag,135 detect,136 selectedDetectors,137 detector;138 // Find script tag139 scriptTags = document.getElementsByTagName("script");140 for(var i = 0; i < scriptTags.length; i++) {141 if(scriptTags[i].getAttribute("data-detect") !== null) {142 scriptTag = scriptTags[i];143 break;144 }145 }146 if(typeof scriptTag === 'undefined') {147 log("Feature Detection Error: detect attribute not found on script tag");148 }149 if(queryStringHelper.parse("o") === "1") {150 debug("Ignoring feature detection logic and proceeding with page load.");151 return;152 }153 if(typeof scriptTag !== 'undefined') {154 detect = scriptTag.getAttribute("data-detect");155 selectedDetectors = detect.split(" ");156 for(var i = 0; i < selectedDetectors.length; i++) {157 if(selectedDetectors[i].toUpperCase() === '[LIST]') {158 list();159 } else if(selectedDetectors[i].toUpperCase() === '[DEBUG]'){160 debugMode = true;161 } else {162 detector = detectors[selectedDetectors[i]];163 if(typeof detector !== 'undefined') {164 debug("Running '" + detector.name + "' feature detector [" + detector.description + "]");165 if(detector.test(detector)) {166 pass(detector);167 } else {168 fail(detector);169 }170 } else {171 debug("Feature detector '" + selectedDetectors[i] + "' does not exist.");172 }173 }174 }175 }176 }177 // List all available detectors178 var list = function() {179 debug("\nAVAILABLE FEATURE DETECTORS:");180 debug("============================\n");181 for(i in detectors) {182 if(detectors.hasOwnProperty(i)) {183 var detector = detectors[i];184 var message = " ";185 message += detector.name;186 var padBy = 30 - detector.name.length;187 if(padBy > 0) {188 for(var s = 0; s < padBy; s++) {189 message += " ";190 }191 }192 message += "[" + detector.description + "]\n";193 log(message);194 }195 }196 }197 // -----------------------------------------------------------------------198 // FEATURE DETECTOR: HTML 5 video tag199 // -----------------------------------------------------------------------200 addDetector(201 // Name of detector202 "video",203 // Description (used for debugging only)204 "Fails if the HTML5 video element is not available",205 // Failure message (displayed to users)206 "Your browser doesn't support the HTML5 video tag",207 // Upgrade choices (PPB and or latest Full IE)208 ie.full + ie.ppb,209 // Function that tests functionality210 function(detector) {211 var testPassed = false,212 video = document.createElement("video");213 if(typeof video.play === 'function') {214 testPassed = true;215 }216 return testPassed;217 });218 // -----------------------------------------------------------------------219 // FEATURE DETECTOR: Audio220 // -----------------------------------------------------------------------221 addDetector(222 // Name of detector223 "audio",224 // Description (used for debugging only)225 "Fails if the browser does not support HTML5 Audio element",226 // Failure message (displayed to user)227 "Your browser doesn't support the HTML5 Audio tag.",228 // Upgrade choices (PPB and/or latest full IE build)229 ie.full + ie.ppb,230 // Function that performs feature detection.231 function(detector) {232 var testPassed = false,233 audio = document.createElement('audio');234 if(typeof audio.play === 'function') {235 testPassed = true;236 }237 return testPassed;238 });239 // -----------------------------------------------------------------------240 // FEATURE DETECTOR: Canvas241 // -----------------------------------------------------------------------242 addDetector(243 // Name of detector244 "canvas",245 // Description (used for debugging only)246 "Fails if the browser does not support the HTML5 Canvas element",247 // Failure message (displayed to user)248 "Your browser doesn't support the HTML5 Canvas tag.",249 // Upgrade choices (PPB and/or latest full IE build)250 ie.full + ie.ppb,251 // Function that performs feature detection.252 function(detector) {253 var testPassed = false,254 canvas = document.createElement('canvas');255 if(typeof canvas.getContext === 'function') {256 testPassed = true;257 }258 return testPassed;259 });260 // -----------------------------------------------------------------------261 // FEATURE DETECTOR: Gesture262 // -----------------------------------------------------------------------263 addDetector(264 // Name of detector265 "gesture",266 // Description (used for debugging only)267 "Fails if the browser does not support MSGesture",268 // Failure message (displayed to user)269 "Your browser doesn't support gestures.",270 // Upgrade choices (PPB and/or latest full IE build)271 ie.full,272 // Function that performs feature detection.273 function(detector) {274 var testPassed = false,275 gesture = !!window.navigator.msPointerEnabled;276 testPassed = gesture;277 return testPassed;278 });279 // -----------------------------------------------------------------------280 // FEATURE DETECTOR: Media Queries281 // -----------------------------------------------------------------------282 addDetector(283 // Name of detector284 "styleMedia",285 // Description (used for debugging only)286 "Fails if the browser does not support CSS3 Media Queries",287 // Failure message (displayed to user)288 "Your browser doesn't support CSS3 Media Queries.",289 // Upgrade choices (PPB and/or latest full IE build)290 ie.full,291 // Function that performs feature detection.292 function(detector) {293 var testPassed = false,294 media = !!window.styleMedia || !!window.matchMedia;295 testPassed = media;296 return testPassed;297 });298 // -----------------------------------------------------------------------299 // FEATURE DETECTOR: XHTML support300 // -----------------------------------------------------------------------301 addDetector(302 // Name of detector303 "xhtml",304 // Description (used for debugging only)305 "Fails if the browser does not support XHTML",306 // Failure message (displayed to users)307 "Your browser doesn't support XHTML documents",308 // Upgrade choices (PPB and or latest Full IE)309 ie.full + ie.ppb,310 // Function that tests functionality311 function(detector) {312 var testPassed = false,313 xhtml = document.createElementNS('http://www.w3.org/1999/xhtml', 'div');314 if(xhtml.tagName) {315 testPassed = true;316 }317 return testPassed;318 });319 // -----------------------------------------------------------------------320 // FEATURE DETECTOR: h264 video codec support321 // -----------------------------------------------------------------------322 addDetector(323 // Name of detector324 "h264",325 // Description (used for debugging only)326 "Fails if the browser can't play h264 videos",327 // Failure message (displayed to user)328 "Your browser doesn't support the h264 video codec, which is needed to run this demo",329 // Upgrade choices (PPB and/or latest full IE build)330 ie.full + ie.ppb,331 // Function that performs feature detection.332 function(detector) {333 var testPassed = false,334 video = document.createElement("video");335 if(video.canPlayType &&336 video.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"')) {337 testPassed = true;338 }339 return testPassed;340 });341 // -----------------------------------------------------------------------342 // FEATURE DETECTOR: SVG support343 // -----------------------------------------------------------------------344 addDetector(345 // Name of detector346 "svg",347 // Description (used for debugging only)348 "Fails if the browser doesn't understand SVG",349 // Failure message (displayed to user)350 "Your browser doesn't support HTML5 SVG",351 // Upgrade choices (PPB and/or latest full IE build)352 ie.full + ie.ppb,353 // Function that performs feature detection.354 function(detector) {355 var testPassed = false,356 svgSupported = document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Structure", "1.1");357 if(svgSupported) {358 testPassed = true;359 }360 return testPassed;361 });362 // -----------------------------------------------------------------------363 // FEATURE DETECTOR: HTML5 semantic elements364 // -----------------------------------------------------------------------365 addDetector(366 // Name of detector367 "semanticElements",368 // Description (used for debugging only)369 "Fails if the browser doesn't understand HTML5 semantic elements",370 // Failure message (displayed to user)371 "Your browser doesn't support the HTML5 Semantic Elements.",372 // Upgrade choices (PPB and/or latest full IE build)373 ie.full + ie.ppb,374 // Function that performs feature detection.375 function(detector) {376 var testPassed = false,377 section = document.createElement('section');378 if(section.toString() === "[object HTMLElement]") {379 testPassed = true;380 }381 return testPassed;382 });383 // -----------------------------------------------------------------------384 // FEATURE DETECTOR: IE Site Pinning385 // -----------------------------------------------------------------------386 addDetector(387 // Name of detector388 "pinning",389 // Description (used for debugging only)390 "Fails if the browser doesn't support site pinning",391 // Failure message (displayed to user)392 "Your browser doesn't support the window.external.msIsSiteMode API.",393 // Upgrade choices (PPB and/or latest full IE build)394 ie.full,395 // Function that performs feature detection.396 function(detector) {397 var testPassed = false;398 if(window.external && "msIsSiteMode" in window.external) {399 testPassed = true;400 }401 return testPassed;402 });403 // -----------------------------------------------------------------------404 // FEATURE DETECTOR: Navigation Timing spec405 // -----------------------------------------------------------------------406 addDetector(407 // Name of detector408 "navigationTiming",409 // Description (used for debugging only)410 "Fails if the browser doesn't expose window.performance, msPerformance, or webkitPerformance",411 // Failure message (displayed to user)412 "Your browser doesn't support the W3C Navigation Timing interface.",413 // Upgrade choices (PPB and/or latest full IE build)414 ie.full + ie.ppb,415 // Function that performs feature detection.416 function(detector) {417 var testPassed = false;418 if(window.msPerformance || window.webkitPerformance || window.performance) {419 testPassed = true;420 }421 return testPassed;422 });423 // -----------------------------------------------------------------------424 // FEATURE DETECTOR: Checks for IE9 (must be full build, not PPB)425 // -----------------------------------------------------------------------426 addDetector(427 // Name of detector428 "ie9PlusFull",429 // Description (used for debugging only)430 "Fails if the browser is not a full build (not PPB) of IE, version 9 or higher",431 // Failure message (displayed to user)432 "This demo requires a full install of Internet Explorer 9 to run.",433 // Upgrade choices (PPB and/or latest full IE build)434 ie.full,435 // Function that performs feature detection.436 function(detector) {437 var testPassed = false;438 if(browserInfo.isInternetExplorer() &&439 !browserInfo.isPlatformPreview() &&440 browserInfo.version() >= 9) {441 testPassed = true;442 }443 return testPassed;444 });445 // -----------------------------------------------------------------------446 // FEATURE DETECTOR: Checks for IE9 plus dev tools (full build or ppb works)447 // -----------------------------------------------------------------------448 addDetector(449 // Name of detector450 "ie9PlusDevTools",451 // Description (used for debugging only)452 "Fails if the browser is not a build of IE (Full or PPB) and version 9 or higher",453 // Failure message (displayed to user)454 "This demo requires a version of Internet Explorer 9 or higher to run.",455 // Upgrade choices (PPB and/or latest full IE build)456 ie.full + ie.ppb,457 // Function that performs feature detection.458 function (detector) {459 var testPassed = false;460 if (browserInfo.isInternetExplorer() &&461 browserInfo.version() >= 9) {462 testPassed = true;463 }464 return testPassed;465 });466 // -----------------------------------------------------------------------467 // FEATURE DETECTOR: Checks if object HtmlElement is defined468 // -----------------------------------------------------------------------469 addDetector(470 // Name of detector471 "htmlElement",472 // Description (used for debugging only)473 "Fails if the browser does not define HtmlElement as global object",474 // Failure message (displayed to user)475 "Your browser doesn't support the HTMLElement object from script.",476 // Upgrade choices (PPB and/or latest full IE build)477 ie.full + ie.ppb,478 // Function that performs feature detection.479 function(detector) {480 var testPassed = false;481 if(typeof HTMLElement !== 'undefined') {482 testPassed = true;483 }484 return testPassed;485 });486 // -----------------------------------------------------------------------487 // FEATURE DETECTOR: Does browser DOM support getElementsByClassName()488 // -----------------------------------------------------------------------489 addDetector(490 // Name of detector491 "domGetElementsByClassName",492 // Description (used for debugging only)493 "Fails if the browser does not support DOM getElementsByClassName() API",494 // Failure message (displayed to user)495 "Your browser doesn't support the DOM getElementsByClassName() API.",496 // Upgrade choices (PPB and/or latest full IE build)497 ie.full + ie.ppb,498 // Function that performs feature detection.499 function(detector) {500 var testPassed = false;501 if(typeof document.getElementsByClassName !== 'undefined') {502 testPassed = true;503 }504 return testPassed;505 });506 // -----------------------------------------------------------------------507 // FEATURE DETECTOR: Geolocation508 // -----------------------------------------------------------------------509 addDetector(510 // Name of detector511 "geolocation",512 // Description (used for debugging only)513 "Fails if the browser does not support Geolocation API",514 // Failure message (displayed to user)515 "Your browser doesn't support the W3C Geolocation API.",516 // Upgrade choices (PPB and/or latest full IE build)517 ie.full + ie.ppb,518 // Function that performs feature detection.519 function(detector) {520 var testPassed = false;521 if(navigator && typeof navigation.geolocation !== 'undefined') {522 testPassed = true;523 }524 return testPassed;525 });526 // -----------------------------------------------------------------------527 // FEATURE DETECTOR: ES5 Object.defineProperties / defineProperty528 // -----------------------------------------------------------------------529 addDetector(530 // Name of detector531 "es5properties",532 // Description (used for debugging only)533 "Fails if the browser does not support ES5 Object.defineProperties or Object.defineProperty",534 // Failure message (displayed to user)535 "Your browser doesn't support the ES5 properties API.",536 // Upgrade choices (PPB and/or latest full IE build)537 ie.full + ie.ppb,538 // Function that performs feature detection.539 function(detector) {540 var testPassed = false;541 if(Object.defineProperties && Object.defineProperty) {542 testPassed = true;543 }544 return testPassed;545 });546 // -----------------------------------------------------------------------547 // FEATURE DETECTOR: ES5 Object.keys548 // -----------------------------------------------------------------------549 addDetector(550 // Name of detector551 "es5objectKeys",552 // Description (used for debugging only)553 "Fails if the browser does not support ES5 Object.keys",554 // Failure message (displayed to user)555 "Your browser doesn't support the Object.Keys method.",556 // Upgrade choices (PPB and/or latest full IE build)557 ie.full + ie.ppb,558 // Function that performs feature detection.559 function(detector) {560 var testPassed = false;561 if(Object.keys) {562 testPassed = true;563 }564 return testPassed;565 });566 // -----------------------------------------------------------------------567 // FEATURE DETECTOR: ES5 array methods568 // -----------------------------------------------------------------------569 addDetector(570 // Name of detector571 "es5arrays",572 // Description (used for debugging only)573 "Fails if the browser does not support ES5 array methods",574 // Failure message (displayed to user)575 "Your browser doesn't support the ES5 array methods.",576 // Upgrade choices (PPB and/or latest full IE build)577 ie.full + ie.ppb,578 // Function that performs feature detection.579 function(detector) {580 var testPassed = false;581 if([].filter && [].indexOf && [].lastIndexOf && [].every &&582 [].some && [].forEach && [].map && [].reduce && [].reduceRight) {583 testPassed = true;584 }585 return testPassed;586 });587 // -----------------------------------------------------------------------588 // FEATURE DETECTOR: DOM Traversal589 // -----------------------------------------------------------------------590 addDetector(591 // Name of detector592 "domTraversal",593 // Description (used for debugging only)594 "Fails if the browser does not support DOM Traversal (document.createNodeIterator)",595 // Failure message (displayed to user)596 "Your browser doesn't support DOM Traversal.",597 // Upgrade choices (PPB and/or latest full IE build)598 ie.full + ie.ppb,599 // Function that performs feature detection.600 function(detector) {601 var testPassed = false;602 if(document.createNodeIterator) {603 testPassed = true;604 }605 return testPassed;606 });607 // -----------------------------------------------------------------------608 // FEATURE DETECTOR: DOM Range609 // -----------------------------------------------------------------------610 addDetector(611 // Name of detector612 "domRange",613 // Description (used for debugging only)614 "Fails if the browser does not support DOM Range",615 // Failure message (displayed to user)616 "Your browser doesn't support DOM Range and/or HTML5 Selection.",617 // Upgrade choices (PPB and/or latest full IE build)618 ie.full + ie.ppb,619 // Function that performs feature detection.620 function(detector) {621 var testPassed = false;622 if(document.createRange && window.getSelection) {623 testPassed = true;624 }625 return testPassed;626 });627 // -----------------------------------------------------------------------628 // FEATURE DETECTOR: DOM Parser and XMLSerializer629 // -----------------------------------------------------------------------630 addDetector(631 // Name of detector632 "domParser",633 // Description (used for debugging only)634 "Fails if the browser does not support DOMParser or XMLSerializer",635 // Failure message (displayed to user)636 "Your browser doesn't support DOMParser and/or XMLSerializer.",637 // Upgrade choices (PPB and/or latest full IE build)638 ie.full + ie.ppb,639 // Function that performs feature detection.640 function(detector) {641 var testPassed = false;642 if(self.DOMParser && self.XMLSerializer) {643 testPassed = true;644 }645 return testPassed;646 });647 // -----------------------------------------------------------------------648 // FEATURE DETECTOR: CSS3 Floats649 // -----------------------------------------------------------------------650 addDetector(651 // Name of detector652 "positionedFloat",653 // Description (used for debugging only)654 "Fails if the browser does not support CSS3 Floats",655 // Failure message (displayed to user)656 "Your browser doesn't support CSS3 Floats.",657 // Upgrade choices (PPB and/or latest full IE build)658 ie.ppb,659 // Function that performs feature detection.660 function(detector) {661 var testPassed = false,662 positionedFloat = document.createElement("div");663 positionedFloat.style.cssFloat = "-ms-positioned";664 positionedFloat.style.msWrapSide = "both";665 if (positionedFloat.style.cssFloat == "-ms-positioned" || positionedFloat.style.msWrapSide == "both") {666 testPassed = true;667 }668 return testPassed;669 });670 // -----------------------------------------------------------------------671 // FEATURE DETECTOR: Win8 or touch supported browser672 // -----------------------------------------------------------------------673 addDetector(674 // Name of detector675 "IE10OrTouch",676 // Description (used for debugging only)677 "Fails if the browser is not IE10 or a browser that supports touch events",678 // Failure message (displayed to user)679 "Your browser doesn't support Touch events.",680 // Upgrade choices (PPB and/or latest full IE build)681 ie.win8,682 // Function that performs feature detection.683 function(detector) {684 return window.navigator.msPointerEnabled || ("ontouchstart" in document.createElement('div')) || ("TouchEvent" in window);685 });686 // -----------------------------------------------------------------------687 // FEATURE DETECTOR: JavaScript Intl688 // -----------------------------------------------------------------------689 addDetector(690 // Name of detector691 "JSIntl",692 // Description (used for debugging only)693 "Fails if the browser does not support Intl methods",694 // Failure message (displayed to user)695 "Your browser doesn't support the JavaScript Intl feature.",696 // Upgrade choices (PPB and/or latest full IE build)697 ie.full + ie.ppb,698 // Function that performs feature detection.699 function(detector) {700 var testPassed = false;701 if(typeof(Intl) == "object" && typeof(Intl.Collator) == "function"702 && typeof(Intl.NumberFormat) == "function" && typeof(Intl.DateTimeFormat) == "function") {703 testPassed = true;704 }705 return testPassed;706 });707 run();...

Full Screen

Full Screen

quicktest.js

Source:quicktest.js Github

copy

Full Screen

1/**2 * @typedef {[{input: [*], expectedOutput: *}]} DataProvider3 * @typedef {{desc:String,testFunction:Function<>,expectedResult:*}} TestSingleExpectResult4 * @typedef {{desc:String,testFunction:Function<>,expectedError:Error}} TestSingleExpectThrow5 * @typedef {{desc:String,6 * testFunction:Function<[*]>,7 * dataProvider: DataProvider8 * }} TestWithProvider9 *10 * @typedef {TestSingleExpectResult|TestSingleExpectThrow} TestSingle11 * @typedef {TestSingle|TestWithProvider} Test12 *13 */14const runTests = function(outDiv, tests) {15 /** @type {Generator} */16 let testIteration = QuickTestIterator(tests);17 let done = false;18 let i = 0;19 do {20 i++;21 let testResultObject = testIteration.next();22 if (testResultObject.done) {23 break;24 }25 /** @type {TestResult} */26 let result = testResultObject.value;27 let resultDiv = document.createElement('div');28 resultDiv.id = 'result-' + i;29 resultDiv.classList.add('result');30 resultDiv.classList.add(result.testPassed ? 'pass' : 'fail');31 let resultString = document.createTextNode(32 'Test ' + (result.testPassed ? 'Passed' : 'Failed')33 + ' - ' + result.testDescription34 + ' (' + result.testDurationInMilliseconds.toPrecision(3) + 'ms)');35 resultDiv.appendChild(resultString);36 if (!result.testPassed) {37 let detailsHeaderDiv = document.createElement('div');38 detailsHeaderDiv.id = 'details-header-' + i;39 detailsHeaderDiv.classList.add('details-header');40 detailsHeaderDiv.appendChild(41 document.createTextNode('Details: ' + result.testDiagnosis));42 resultDiv.appendChild(detailsHeaderDiv);43 let detailsDiv = document.createElement('div');44 detailsDiv.id = 'details-' + i;45 detailsDiv.classList.add('details');46 detailsDiv.innerHTML =47 '<pre>' +48 'Expected Result: type = ' + (typeof result.expectedResult) +49 '; value = ' + result.expectedResult +50 '\n' +51 'Observed Result: type = ' + (typeof result.observedResult) +52 '; value = ' + result.observedResult +53 '\n' +54 'Expected Error: type = ' + (typeof result.expectedError) +55 '; value = ' + result.expectedError +56 '\n' +57 'Observed Error: type = ' + (typeof result.thrownError) +58 '; value = ' + result.thrownError;59 if (typeof result.thrownError === 'object') {60 detailsDiv.innerHTML +=61 '<pre>\nStack Trace:\n' + result.thrownError.stack;62 }63 resultDiv.appendChild(detailsDiv);64 }65 outDiv.appendChild(resultDiv);66 console.log(testResultObject);67 } while (!done);68}69/**70 * @param {[Test]} tests71 * @constructor72 */73const QuickTestIterator = function* (tests) {74 /**75 * @param {Test} test76 * @param {[*]} input77 * @return {{testPassed: boolean,78 * testDiagnosis: *,79 * observedResult: *,80 * thrownError: *,81 * testDurationInMilliseconds: (number)}}82 */83 function runTest(test, input) {84 let observedResult;85 let thrownError;86 let testDurationInMilliseconds;87 let testPassed = false;88 let testDiagnosis;89 // Run the test90 let millisecondsBefore = window.performance.now();91 try {92 observedResult = test.testFunction(input);93 } catch (e) {94 thrownError = e;95 }96 let millisecondsAfter = window.performance.now();97 testDurationInMilliseconds = millisecondsAfter - millisecondsBefore;98 // what just happened?99 if ((typeof observedResult === 'undefined') && (typeof thrownError === 'undefined')) {100 // The function may have returned undefined, or not returned anything.101 if (test.hasOwnProperty('expectedResult') && typeof test.expectedResult === 'undefined') {102 testPassed = true;103 } else {104 testPassed = false;105 testDiagnosis = 'Test returned undefined.';106 }107 } else if ((typeof observedResult === 'undefined') && (typeof thrownError !== 'undefined')) {108 // An error was thrown109 if (typeof test.expectedError === 'undefined') {110 testPassed = false;111 testDiagnosis = 'Error of type ' + thrownError.name + ' thrown, but no error expected.';112 } else if (thrownError.name === test.expectedError.name) {113 if (typeof test.expectedError.message === 'undefined') {114 // The thrown error was of the correct type, and no further checks needed to be made.115 testPassed = true;116 } else {117 if (thrownError.message.startsWith(test.expectedError.message)) {118 testPassed = true;119 } else {120 testPassed = false;121 testDiagnosis = 'Correct error type was thrown, but error message was unexpected.';122 }123 }124 } else {125 testPassed = false;126 testDiagnosis =127 'Expected a ' + test.expectedError.name +128 ' to be thrown, but thrown error was of type ' + thrownError.name;129 }130 } else if ((typeof observedResult !== 'undefined') && (typeof thrownError === 'undefined')) {131 if (test.hasOwnProperty('expectedResult') && typeof test.expectedResult === 'undefined') {132 // The expected return type is the undefined type, but test method returned something else.133 // Special case of the next else branch below.134 testPassed = false;135 testDiagnosis =136 'Test returned type ' + (typeof observedResult) +137 ' but the undefined type was expected.';138 } else if (typeof observedResult !== typeof test.expectedResult) {139 testPassed = false;140 testDiagnosis = 'Test returned type ' + (typeof observedResult) +141 ' but expected result is of type ' + (typeof test.expectedResult);142 } else if (observedResult !== test.expectedResult) {143 testPassed = false;144 testDiagnosis = 'Test return value was different from expected value.';145 } else {146 testPassed = true;147 }148 } else {149 // observed result and thrown error are both defined, which is an error with the test rig.150 throw new Error('Observed result and thrown error are both defined.');151 }152 return {testPassed, testDiagnosis, observedResult, thrownError, testDurationInMilliseconds};153 }154 for (let test of tests) {155 let result;156 if (test.hasOwnProperty('dataProvider')) {157 test.desc = '[' + test.dataProvider.length + ' tests] ' + test.desc;158 let rollingDuration = 0;159 for (let i = 0; i < test.dataProvider.length; i++) {160 test.expectedResult = test.dataProvider[i].expectedOutput;161 result = runTest(test, test.dataProvider[i].input);162 rollingDuration += result.testDurationInMilliseconds;163 result.testDurationInMilliseconds = rollingDuration;164 if (!result.testPassed) {165 result.testDiagnosis =166 '(Test ' + (i + 1) + ' of ' + test.dataProvider.length + '): ' + result.testDiagnosis;167 break;168 }169 }170 } else {171 result = runTest(test, undefined);172 }173 /**174 * @typedef {{testPassed:!boolean,testDiagnosis:?string,175 * testDescription:!string,176 * expectedResult:?*,observedResult:?*,expectedError:?Error,thrownError:?Error,177 * testDurationInMilliseconds:!number}} TestResult178 *179 * @type {TestResult}180 */181 yield {182 testPassed: result.testPassed,183 testDiagnosis: result.testDiagnosis,184 testDescription: test.desc,185 expectedResult: test.expectedResult,186 observedResult: result.observedResult,187 expectedError: test.expectedError,188 thrownError: result.thrownError,189 testDurationInMilliseconds: result.testDurationInMilliseconds190 };191 }...

Full Screen

Full Screen

fileSys_spec.js

Source:fileSys_spec.js Github

copy

Full Screen

1var ein = ECO_INT_NAMESPACE;2describe('Allows access to the File System', function() {3 ein.jsmFileSysTsts = {4 ids: progIdData,5 testPassed: false,6 newFileId: ""7 }; console.log(ein.jsmFileSysTsts.ids);8 var fileSysTests = ein.jsmFileSysTsts;9 var testPassed = fileSysTests.testPassed;10 beforeEach(function() {11 fileSysTests.testPassed = false;12 });13 // it("Creates Folders", function(done) { GET DIRECTORY METHOD NOT CURRENTLY WORKING. WILL UPDATE TEST-INIT WHEN A GENERATED TEST FOLDER IS AN OPTION14 // ein.fileSys.getFolderEntry(15 // fileSysTests.ids.folder, // Should be the jasmine folder id, the root folder for testing16 // ein.fileSys.createFolder, // writeHandler17 // "Spec Test Folder", // fileText18 // function(){ // success callback19 // fileSysTests.testPassed = true;20 // done(expect(fileSysTests.testPassed).toBe(true));21 // }22 // )23 // });24 it("Opens and Reads Folders", function(done) {25 ein.fileSys.entryFromId(26 fileSysTests.ids.folder, // Should be the jasmine folder id, the root folder for testing27 ein.fileSys.getFolderData, // idHandler28 ein.fileSys.readFolder, // objHandler29 function(spH, folderObj){ // success callback30 // if ()31 console.log("folderObj", folderObj);32 fileSysTests.testPassed = true;33 done(expect(fileSysTests.testPassed).toBe(true));34 }35 )36 });37 it("Creates Files", function(done) {38 ein.fileSys.getFolderEntry(39 fileSysTests.ids.folder, // Should be the jasmine folder id, the root folder for testing40 ein.fileSys.createFile, // writeHandler41 "Test File", // name42 function(fSysId){ // success callback43 fileSysTests.newFileId = fSysId; console.log("newFileId", fileSysTests.newFileId);44 fileSysTests.testPassed = true;45 done(expect(fileSysTests.testPassed).toBe(true));46 }47 )48 });49 it("Writes Content to Files", function(done) {50 ein.fileSys.saveFile(51 fileSysTests.newFileId, // Id of file generate in previous test52 "Jasmine Test File Text", // fileText53 function(){ // success callback54 fileSysTests.testPassed = true;55 done(expect(fileSysTests.testPassed).toBe(true));56 }57 )58 });59 it("Opens and Reads Files", function(done) {60 ein.fileSys.entryFromId(61 fileSysTests.ids.file, // Should a csv file chosen for testing62 ein.fileSys.getFileObj, // idHandler63 ein.fileSys.readFile, // objHandler64 function(){ // success callback65 fileSysTests.testPassed = true;66 done(expect(fileSysTests.testPassed).toBe(true));67 }68 )69 });70});71describe('Parses CSVs', function() {72 it("Reads and Parses CSVs into Objects", function(done) {73 ein.fileSys.entryFromId(74 ein.jsmFileSysTsts.ids.file, // Should a csv file chosen for testing75 ein.fileSys.getFileObj, // idHandler76 ein.fileSys.readFile, // objHandler77 function(spH, csvStr){ // sends CSV string to CSV parse method78 var successful = ein.csvHlpr.csvToObject(spH, csvStr, true); // spH is a spaceHolder, true indicates to the method this is a test79 if(successful) { console.log("successful"); // and tells the method to return true, i.e. successful80 ein.jsmFileSysTsts.testPassed = true;81 done(expect(ein.jsmFileSysTsts.testPassed).toBe(true));82 }83 }84 )85 });86});...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 console.log(data);4});5var wpt = require('webpagetest');6var wpt = new WebPageTest('www.webpagetest.org');7 console.log(data);8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11wpt.getLocations(function(err, data) {12 console.log(data);13});14var wpt = require('webpagetest');15var wpt = new WebPageTest('www.webpagetest.org');16wpt.getBrowsers(function(err, data) {17 console.log(data);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getTesters(function(err, data) {22 console.log(data);23});24var wpt = require('webpagetest');25var wpt = new WebPageTest('www.webpagetest.org');26wpt.getTesters(function(err, data) {27 console.log(data);28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31wpt.getTesters(function(err, data) {32 console.log(data);33});34var wpt = require('webpagetest');35var wpt = new WebPageTest('www.webpagetest.org');36wpt.getTesters(function(err, data) {37 console.log(data);38});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptRunner = require('./wptRunner.js');2var wpt = new wptRunner();3wpt.testPassed();4var wptRunner = require('./wptRunner.js');5var wpt = new wptRunner();6wpt.testFailed();7var wptRunner = require('./wptRunner.js');8var wpt = new wptRunner();9wpt.testError();10var wptRunner = require('./wptRunner.js');11var wpt = new wptRunner();12wpt.testStatus('Test Completed');13var wptRunner = require('./wptRunner.js');14var wpt = new wptRunner();15wpt.testMessage('Test Completed');16var wptRunner = require('./wptRunner.js');17var wpt = new wptRunner();18wpt.testResult('Test Completed');19var wptRunner = require('./wptRunner.js');20var wpt = new wptRunner();21wpt.testResult('Test Completed');22var wptRunner = require('./wptRunner.js');23var wpt = new wptRunner();24wpt.testData('Test Completed');25var wptRunner = require('./wptRunner.js');26var wpt = new wptRunner();27wpt.testCustomMetric('Test Completed');

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.testPassed();2### `wpt.testFailed(message)`3### `wpt.testPassed(message)`4### `wpt.testFinished()`5### `wpt.testStatus(message, status)`6### `wpt.setTestStatus(status)`7### `wpt.setTestMessage(message)`8### `wpt.setTestPath(path)`9### `wpt.setTestType(type)`10### `wpt.setTestLabel(label)`11### `wpt.setTestID(id)`12### `wpt.setTestIndex(index)`13### `wpt.setTestRuns(runs)`14### `wpt.setTestRunsRemaining(runs)`15### `wpt.setTestLocation(location)`16### `wpt.setTestConnectivity(connectivity)`17### `wpt.setTestBWIn(bwIn)`

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.testPassed();2wpt.testFailed("Test failed because of some error");3wpt.testFinished("Test finished");4wpt.testStarted("Test started");5wpt.testWait("Test is waiting for something to happen");6wpt.testWaitUntilDone("Test is waiting for something to happen");

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.testPassed();2### `wpt.testFailed()`3wpt.testFailed();4### `wpt.testDone()`5wpt.testDone();6### `wpt.log()`7wpt.log("This is a log message");8### `wpt.debug()`9wpt.debug("This is a debug message");10### `wpt.status()`11wpt.status("This is a status message");12### `wpt.addResult()`13wpt.addResult("ResultName", "ResultValue");14### `wpt.addMetric()`15wpt.addMetric("MetricName", "MetricValue");16### `wpt.setCookie()`17wpt.setCookie("CookieName", "CookieValue");18### `wpt.clearCookies()`19wpt.clearCookies();20### `wpt.clearCache()`

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = new wpt('A.7c9b0f1d7f6c1d1b7c8b8bf6f7e6e0b3');3 if (err) return console.error(err);4 test.testPassed(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7 });8});9### runTest(url, options, callback)10 * `script` - A script to execute during the test. This can be a string with the script, or an object with `inline` and `type` properties (e.g. `{ inline: 'document.body.innerHTML = "Hello, World!";',

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