Best JavaScript code snippet using wpt
date-set-to-nan.js
Source:date-set-to-nan.js  
...80                  : ((2 == steps) ? date["set" + functionNameRoot](setValue, 0)81                  : ((3 == steps) ? date["set" + functionNameRoot](setValue, 0, 0)82                  :                  date["set" + functionNameRoot](setValue, 0, 0, 0)));83    if (!isNaN(setResult)) {84        testFailed("date(NaN).set" + functionNameRoot + "(" + setValue + params[steps - 1]85                                   + ") was " + setResult + " instead of NaN");86        return false;87    }88    var getResult = date["get" + functionNameRoot]();89    if (!isNaN(getResult)) {90        testFailed("date.get" + functionNameRoot + "() was " + getResult + " instead of NaN");91        return false;92    }93    testPassed ("no recovering from NaN date using date.set" + functionNameRoot94        + "(arg0" + params[steps - 1] + ")");95    return true;96}97function testDateFunctionWithValueRecoverTime(functionNameRoot)98{99    var date = new Date();100    var setValue = date["get" + functionNameRoot]();101    date.setMilliseconds(Number.NaN);102    var setResult = date["set" + functionNameRoot](setValue);103    if (setValue != setResult) {104        testFailed("date(NaN).set" + functionNameRoot + "(" + setValue + ") was " + setResult + " instead of " + setValue);105        return false;106    }107    var getResult = date["get" + functionNameRoot]();108    if (getResult != setValue) {109        testFailed("date.get" + functionNameRoot + "() was " + getResult + " instead of " + setValue);110        return false;111    }112    testPassed ("recover from NaN date using date.set" + functionNameRoot + "()");113    return true;114}115function testDateFunctionWithValueRecoverFullYear(functionNameRoot)116{117    var result = true;118    var date = new Date();119    var setValue = date["get" + functionNameRoot]();120    date.setMilliseconds(Number.NaN);121    var setResult = date["set" + functionNameRoot](setValue);122    var getResult = date["get" + functionNameRoot]();123    if (getResult != setValue) {124        testFailed("date.get" + functionNameRoot + "() was " + getResult + " instead of " + setValue);125        result = false;126    }127    getResult = date.getMilliseconds();128    if (getResult != 0) {129        testFailed("date.getMilliseconds() was " + getResult + " instead of 0");130        result = false;131    }132    getResult = date.getSeconds();133    if (getResult != 0) {134        testFailed("date.getSeconds() was " + getResult + " instead of 0");135        result = false;136    }137    getResult = date.getMinutes();138    if (getResult != 0) {139        testFailed("date.getMinutes() was " + getResult + " instead of 0");140        result = false;141    }142    getResult = date.getHours();143    if (getResult != 0) {144        testFailed("date.getHours() was " + getResult + " instead of 0");145        result = false;146    }147    getResult = date.getDate();148    if (getResult != 1) {149        testFailed("date.getDate() was " + getResult + " instead of 1");150        result = false;151    }152    getResult = date.getMonth();153    if (getResult != 0) {154        testFailed("date.getMonth() was " + getResult + " instead of 0");155        result = false;156    }157    if (result)158        testPassed ("recover from NaN date using date.setFullYear()");159    else160        testFailed ("recover from NaN date using date.setFullYear()");161    return result;162}163function testDateFunctionWithValueRecoverUTCFullYear(functionNameRoot)164{165    var result = true;166    var date = new Date();167    var setValue = date["get" + functionNameRoot]();168    date.setMilliseconds(Number.NaN);169    var setResult = date["set" + functionNameRoot](setValue);170    var getResult = date["get" + functionNameRoot]();171    if (getResult != setValue) {172        testFailed("date.get" + functionNameRoot + "() was " + getResult + " instead of " + setValue);173        result = false;174    }175    getResult = date.getUTCMilliseconds();176    if (getResult != 0) {177        testFailed("date.getUTCMilliseconds() was " + getResult + " instead of 0");178        result = false;179    }180    getResult = date.getUTCSeconds();181    if (getResult != 0) {182        testFailed("date.getUTCSeconds() was " + getResult + " instead of 0");183        result = false;184    }185    getResult = date.getUTCMinutes();186    if (getResult != 0) {187        testFailed("date.getUTCMinutes() was " + getResult + " instead of 0");188        result = false;189    }190    getResult = date.getUTCHours();191    if (getResult != 0) {192        testFailed("date.getUTCHours() was " + getResult + " instead of 0");193        result = false;194    }195    getResult = date.getUTCDate();196    if (getResult != 1) {197        testFailed("date.getUTCDate() was " + getResult + " instead of 1");198        result = false;199    }200    getResult = date.getUTCMonth();201    if (getResult != 0) {202        testFailed("date.getUTCMonth() was " + getResult + " instead of 0");203        result = false;204    }205    if (result)206        testPassed ("recover from NaN date using date.setUTCFullYear()");207    else208        testFailed ("recover from NaN date using date.setUTCFullYear()");209    return result;210}211function testDateFunctionWithValueRecoverYear(functionNameRoot)212{213    var result = true;214    var is13Compatible = true;215    var date = new Date();216    var setValue = date["get" + functionNameRoot]();217    var fullYears = date.getFullYear() - 1900;218    if (setValue != fullYears) {219        testFailed("date.get" + functionNameRoot + "() was " + setValue + " instead of " + fullYears);220        is13Compatible = false;221    } else222        testPassed("date.getYear() is compatible to JavaScript 1.3 and later");223    date.setMilliseconds(Number.NaN);224    var setResult = date["set" + functionNameRoot](setValue + 1900);225    var getResult = date["get" + functionNameRoot]();226    if (getResult != setValue) {227        testFailed("date.get" + functionNameRoot + "() was " + getResult + " instead of " + setValue);228        result = false;229    }230    getResult = date.getMilliseconds();231    if (getResult != 0) {232        testFailed("date.getMilliseconds() was " + getResult + " instead of 0");233        result = false;234    }235    getResult = date.getSeconds();236    if (getResult != 0) {237        testFailed("date.getSeconds() was " + getResult + " instead of 0");238        result = false;239    }240    getResult = date.getMinutes();241    if (getResult != 0) {242        testFailed("date.getMinutes() was " + getResult + " instead of 0");243        result = false;244    }245    getResult = date.getHours();246    if (getResult != 0) {247        testFailed("date.getHours() was " + getResult + " instead of 0");248        result = false;249    }250    getResult = date.getDate();251    if (getResult != 1) {252        testFailed("date.getDate() was " + getResult + " instead of 1");253        result = false;254    }255    getResult = date.getMonth();256    if (getResult != 0) {257        testFailed("date.getMonth() was " + getResult + " instead of 0");258        result = false;259    }260    if (result)261        testPassed ("recover from NaN date using date.setUTCFullYear()");262    else263        testFailed ("recover from NaN date using date.setUTCFullYear()");264    return result && is13Compatible;265}266function makeIEHappy(functionNameRoot, value)267{268    var date = new Date();269    var setResult = date["set" + functionNameRoot](value);270    if (!isNaN(setResult)) {271        testFailed("date.set" + functionNameRoot272                              + "() was "273                              + setResult + " instead of NaN");274         return false;275    }276    var getResult = date["get" + functionNameRoot]();277    if (!isNaN(getResult)) {278        testFailed("date.get" + functionNameRoot + "() was "279                              + getResult + " instead of NaN");280        return false;281    }282    return true283}284function testDateFunctionWithValueExpectingNaN1(functionNameRoot)285{286    var result = true;287    for (var idx0 in testValues)288        if (idx0 != 0) {289            var date = new Date();290            var setResult = date["set" + functionNameRoot](testValues[idx0]);291            if (!isNaN(setResult)) {292                testFailed("date.set" + functionNameRoot + "("293                                      + testValues[idx0] + ") was "294                                      + setResult + " instead of NaN");295                result = false;296            }297            var getResult = date["get" + functionNameRoot]();298            if (!isNaN(getResult)) {299                testFailed("date.get" + functionNameRoot + "() was "300                                      + getResult + " instead of NaN");301                result = false;302            }303        } else if (!makeIEHappy(functionNameRoot))304            result = false;305    if (result) {306        testPassed("date.set" + functionNameRoot + "(arg0)");307        testPassed("date.set" + functionNameRoot + "()");308    }309    return result;310}311function testDateFunctionWithValueExpectingNaN2(functionNameRoot)312{313    var result = true;314    for (var idx0 in testValues)315        for (var idx1 in testValues)316            if (idx0 != 0 || idx1 != 0) {317                var date = new Date();318                var setResult = date["set" + functionNameRoot](testValues[idx0],319                                                               testValues[idx1]);320                if (!isNaN(setResult)) {321                    testFailed("date.set" + functionNameRoot + "("322                                          + testValues[idx0] + ", "323                                          + testValues[idx1] + ") was "324                                          + setResult + " instead of NaN");325                    result = false;326                }327                var getResult = date["get" + functionNameRoot]();328                if (!isNaN(getResult)) {329                    testFailed("date.get" + functionNameRoot + "() was "330                                          + getResult + " instead of NaN");331                    result = false;332                }333            }334    if (result)335        testPassed("date.set" + functionNameRoot + "(arg0, arg1)");336    return result;337}338function testDateFunctionWithValueExpectingNaN3(functionNameRoot)339{340    var result = true;341    for (var idx0 in testValues)342        for (var idx1 in testValues)343            for (var idx2 in testValues)344                if (idx0 != 0 || idx1 != 0 || idx2 != 0) {345                    var date = new Date();346                    var setResult = date["set" + functionNameRoot](testValues[idx0],347                                                                   testValues[idx1],348                                                                   testValues[idx2]);349                    if (!isNaN(setResult)) {350                        testFailed("date.set" + functionNameRoot + "("351                                              + testValues[idx0] + ", "352                                              + testValues[idx1] + ", "353                                              + testValues[idx2] + ") was "354                                              + setResult + " instead of NaN");355                        result = false;356                    }357                    var getResult = date["get" + functionNameRoot]();358                    if (!isNaN(getResult)) {359                        testFailed("date.get" + functionNameRoot + "() was "360                                              + getResult + " instead of NaN");361                        result = false;362                    }363                }364    if (result)365        testPassed("date.set" + functionNameRoot + "(arg0, arg1, arg2)");366    return result;367}368function testDateFunctionWithValueExpectingNaN4(functionNameRoot)369{370    var result = true;371    for (var idx0 in testValues)372        for (var idx1 in testValues)373            for (var idx2 in testValues)374                for (var idx3 in testValues)375                    if (idx0 != 0 || idx1 != 0 || idx2 != 0 || idx3 != 0) {376                        var date = new Date();377                        var setResult = date["set" + functionNameRoot](testValues[idx0],378                                                                       testValues[idx1],379                                                                       testValues[idx2],380                                                                       testValues[idx3]);381                        if (!isNaN(setResult)) {382                            testFailed("date.set" + functionNameRoot + "("383                                                  + testValues[idx0] + ", "384                                                  + testValues[idx1] + ", "385                                                  + testValues[idx2] + ", "386                                                  + testValues[idx3] + ") was "387                                                  + setResult + " instead of NaN");388                            result = false;389                        }390                        var getResult = date["get" + functionNameRoot]();391                        if (!isNaN(getResult)) {392                            testFailed("date.get" + functionNameRoot + "() was "393                                                  + getResult + " instead of NaN");394                            result = false;395                        }396                    }397    if (result)398        testPassed("date.set" + functionNameRoot + "(arg0, arg1, arg2, arg3)");399    return result;400}401function testDateFunction(functionNameRoot, functionParamNum)402{403    var success = true;404    switch (functionParamNum) {405    case 4:406        success &= testDateFunctionWithValueExpectingNaN4(functionNameRoot);...run.js
Source:run.js  
1StickyLoadBalancer = require('../index.js');2async = require('async');3request = require('request');4crypto = require('crypto');5RequestMirror = require('./RequestMirror.js');6function randomString(howMany, chars) {7    chars = chars8        || "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";9    var rnd = crypto.randomBytes(howMany)10        , value = new Array(howMany)11        , len = chars.length;12    for (var i = 0; i < howMany; i++) {13        value[i] = chars[rnd[i] % len]14    }15    return value.join('');16}17StickyLoadBalancer.setLogging(true);18var testPort = 61234;19var balancer = new StickyLoadBalancer('127.0.0.1', testPort);20balancer.setIdentifier('foooooobar');21balancer.setStickyStrategy([22    'url',23    'body.foo',24    'body.foobar',25    'headers.user-agent',26    'cookie.foo'27]);28var mirrorPort = 34645;29RequestMirror('127.0.0.1', mirrorPort);30StickyLoadBalancer.tellBalancer({ip: '127.0.0.1', port: testPort, identifier: balancer.identifier}, {31    ip: '127.0.0.1',32    port: mirrorPort,33    balance: 634});35balancer.start();36//start tests37var testFailed = [];38var runTest=function(cb){39    /**40     * save chained balancers here41     * @type {{}}42     */43    var balancers={};44    var useBalancer=null;45    async.series([46        function createChainedBalancers(next){47            var currentPort = 15000;48            var lip = '127.0.0.1';49            var amount = 100;50            //create balancer-chain51            var c = 0;52            while (c < amount) {53                var prevBalancer = balancers[(c - 1)];54                //create balancer55                balancers[c] = new StickyLoadBalancer(lip, currentPort);56                balancers[c].setStickyStrategy([57                    'url',58                    'body.foo',59                    'cookie.foo'60                ]);61                balancers[c].start();62                //add to previous balancer63                if (prevBalancer) {64                    StickyLoadBalancer.tellBalancer({65                        ip: prevBalancer.getIp(),66                        port: prevBalancer.getPort(),67                        identifier: prevBalancer.identifier68                    }, {69                        ip: lip,70                        port: balancers[c].getPort(),71                        balance: 672                    });73                }74                currentPort++;75                c++;76            }77            useBalancer = balancers[0];78            var lastBalancer=balancers[Object.keys(balancers)[Object.keys(balancers).length - 1]];79            //add mirror to last balancer80            StickyLoadBalancer.tellBalancer(81                {82                    ip: lastBalancer.getIp(),83                    port: lastBalancer.getPort(),84                    identifier: lastBalancer.identifier85                }, {86                    ip: lip,87                    port: mirrorPort,88                    balance: 689                });90            next();91        },92        function w8(next) {93            console.log('Starting tests');94            //w8 a bit so all is started up95            setTimeout(function () {96                next();97            }, 1);98        },99        function getRequest(next) {100            console.time("getRequest");101            request({102                url: 'http://localhost:' + testPort + '/foobar?bliebla=imba',103                headers: {104                    'User-Agent': 'foobar agent',105                    'cookie': 'foo=bar; centralnotice_buckets_by_campaign=%7B%22wlm%202015%22%3A%7B%22val%22%3A0%2C%22start%22%3A1440284460%2C%22end%22%3A1447275540%7D%7D; GeoIP=:::::v6; dewikimwuser-sessionId=b7361cbc5cb3b9b2; WMF-Last-Access=06-Oct-2015'106                }107            }, function (err, response, body) {108                if (err) {109                    testFailed.push('getRequest(): error in request');110                }111                var json = {};112                try {113                    json = JSON.parse(body);114                } catch (e) {115                    testFailed.push('getRequest(): cant parse body to json');116                }117                try {118                    if (json.method != 'GET') {119                        testFailed.push('getRequest(): method is not GET');120                    }121                    if (json.url != '/foobar?bliebla=imba') {122                        testFailed.push('getRequest(): url is wrong');123                    }124                    if (json.headers['user-agent'] != 'foobar agent') {125                        testFailed.push('getRequest(): user-agent is not foobar agent');126                    }127                    if (json.cookies.foo != 'bar') {128                        testFailed.push('getRequest(): cookie[foo] is not bar');129                    }130                    if (json.body != '') {131                        testFailed.push('getRequest(): body is not empty');132                    }133                } catch (e) {134                    testFailed.push('getRequest(): unknown error');135                }136                console.timeEnd("getRequest");137                next();138            });139        },140        function POSTrequest(next) {141            console.time("POSTrequest");142            request({143                method: 'POST',144                url: 'http://localhost:' + testPort + '/foobar?bliebla=imba',145                headers: {146                    'User-Agent': 'foobar agent',147                    'cookie': 'foo=bar; centralnotice_buckets_by_campaign=%7B%22wlm%202015%22%3A%7B%22val%22%3A0%2C%22start%22%3A1440284460%2C%22end%22%3A1447275540%7D%7D; GeoIP=:::::v6; dewikimwuser-sessionId=b7361cbc5cb3b9b2; WMF-Last-Access=06-Oct-2015'148                },149                form: {150                    foobar: "furchtbar",151                    fooArray: ['foo', 'bar']152                }153            }, function (err, response, body) {154                if (err) {155                    testFailed.push('POSTrequest(): error in request');156                }157                var json = {};158                try {159                    json = JSON.parse(body);160                } catch (e) {161                    testFailed.push('POSTrequest(): cant parse body to json');162                }163                try {164                    if (json.method != 'POST') {165                        testFailed.push('POSTrequest(): method is not POST');166                    }167                    if (json.url != '/foobar?bliebla=imba') {168                        testFailed.push('POSTrequest(): url is wrong');169                    }170                    if (json.headers['user-agent'] != 'foobar agent') {171                        testFailed.push('POSTrequest(): user-agent is not foobar agent');172                    }173                    if (json.cookies.foo != 'bar') {174                        testFailed.push('POSTrequest(): cookie[foo] is not bar');175                    }176                    if (json.body.foobar != 'furchtbar') {177                        testFailed.push('POSTrequest(): body.foobar!=furchtbar');178                    }179                } catch (e) {180                    testFailed.push('POSTrequest(): unknown error');181                }182                console.timeEnd("POSTrequest");183                next();184            });185        },186        function jsonRequest(next) {187            console.time("jsonRequest");188            request({189                method: 'POST',190                url: 'http://localhost:' + testPort + '/foobar?bliebla=imba',191                headers: {192                    'User-Agent': 'foobar agent',193                    'cookie': 'foo=bar; centralnotice_buckets_by_campaign=%7B%22wlm%202015%22%3A%7B%22val%22%3A0%2C%22start%22%3A1440284460%2C%22end%22%3A1447275540%7D%7D; GeoIP=:::::v6; dewikimwuser-sessionId=b7361cbc5cb3b9b2; WMF-Last-Access=06-Oct-2015'194                },195                body: {196                    foo: 'bar',197                    ar: ['foo', 'bar']198                },199                json: true200            }, function (err, response, json) {201                if (err) {202                    testFailed.push('jsonRequest(): error in request');203                }204                try {205                    if (json.method != 'POST') {206                        testFailed.push('jsonRequest(): method is not POST');207                    }208                    if (json.url != '/foobar?bliebla=imba') {209                        testFailed.push('jsonRequest(): url is wrong');210                    }211                    if (json.headers['user-agent'] != 'foobar agent') {212                        testFailed.push('jsonRequest(): user-agent is not foobar agent');213                    }214                    if (json.cookies.foo != 'bar') {215                        testFailed.push('jsonRequest(): cookie[foo] is not bar');216                    }217                    if (json.body.ar.length != 2) {218                        testFailed.push('jsonRequest(): body.ar.length!=2');219                    }220                } catch (e) {221                    testFailed.push('jsonRequest(): unknown error');222                }223                console.timeEnd("jsonRequest");224                next();225            });226        },227        function bigRequest(next) {228            console.time("bigRequest");229            request({230                method: 'POST',231                url: 'http://localhost:' + testPort + '/foobar?bliebla=imba',232                headers: {233                    'User-Agent': 'foobar agent',234                    'cookie': 'foo=bar; centralnotice_buckets_by_campaign=%7B%22wlm%202015%22%3A%7B%22val%22%3A0%2C%22start%22%3A1440284460%2C%22end%22%3A1447275540%7D%7D; GeoIP=:::::v6; dewikimwuser-sessionId=b7361cbc5cb3b9b2; WMF-Last-Access=06-Oct-2015'235                },236                form: {237                    foo: randomString(2000),238                    bar: randomString(2000),239                    is: randomString(2000),240                    basinga: randomString(2000),241                    boom: randomString(200000)242                }243            }, function (err, response, body) {244                if (err) {245                    testFailed.push('bigRequest(): error in request');246                }247                var json = {};248                try {249                    json = JSON.parse(body);250                } catch (e) {251                    testFailed.push('bigRequest(): cant parse body to json');252                    console.error(body);253                }254                try {255                    if (json.method != 'POST') {256                        testFailed.push('bigRequest(): method is not POST');257                    }258                    if (json.url != '/foobar?bliebla=imba') {259                        testFailed.push('bigRequest(): url is wrong');260                    }261                    if (json.headers['user-agent'] != 'foobar agent') {262                        testFailed.push('bigRequest(): user-agent is not foobar agent');263                    }264                    if (json.cookies.foo != 'bar') {265                        testFailed.push('bigRequest(): cookie[foo] is not bar');266                    }267                    if (json.body.foo.length < 2000) {268                        testFailed.push('bigRequest():body.foo.length<2000');269                    }270                } catch (e) {271                    testFailed.push('bigRequest(): unknown error');272                    console.dir(e);273                }274                console.timeEnd("bigRequest");275                next();276            });277        },278        function chainedBalancersPost(next) {279            //next();return false; //comment in to skip this test280            //make requests281            var makeRequest=function(cb){282                var rand=Math.ceil(Math.random()*1000);283                console.time("chainedBalancersPost("+rand+")");284                request({285                    method: 'POST',286                    url: 'http://' + useBalancer.getIp() + ':' + useBalancer.getPort() + '/foobar?bliebla=imba',287                    headers: {288                        'User-Agent': 'foobar agent',289                        'cookie': 'foo=bar; centralnotice_buckets_by_campaign=%7B%22wlm%202015%22%3A%7B%22val%22%3A0%2C%22start%22%3A1440284460%2C%22end%22%3A1447275540%7D%7D; GeoIP=:::::v6; dewikimwuser-sessionId=b7361cbc5cb3b9b2; WMF-Last-Access=06-Oct-2015'290                    },291                    body: {292                        foo: 'bar',293                        ar: ['foo', 'bar'+rand]294                    },295                    json: true296                }, function (err, response, json) {297                    if (err) {298                        testFailed.push('chainedBalancers(): error in request');299                    }300                    try {301                        if (json.method != 'POST') {302                            testFailed.push('chainedBalancers(): method is not POST');303                        }304                        if (json.url != '/foobar?bliebla=imba') {305                            testFailed.push('chainedBalancers(): url is wrong');306                        }307                        if (json.headers['user-agent'] != 'foobar agent') {308                            testFailed.push('chainedBalancers(): user-agent is not foobar agent');309                        }310                        if (json.cookies.foo != 'bar') {311                            testFailed.push('chainedBalancers(): cookie[foo] is not bar');312                        }313                        if (json.body.ar.length != 2) {314                            testFailed.push('chainedBalancers(): body.ar.length!=2');315                        }316                        if (json.body.foo != 'bar') {317                            testFailed.push('chainedBalancers(): body[foo] is not bar');318                        }319                    } catch (e) {320                        testFailed.push('chainedBalancers(): unknown error');321                    }322                    console.timeEnd("chainedBalancersPost("+rand+")");323                    cb();324                });325            };326            var c=0;327            var doAmount=10;328            var done=0;329            while(c<doAmount){330                setTimeout(function(){331                    makeRequest(function(){332                        done++;333                        if(done==doAmount){334                            next();335                        }336                    });337                }, 200*c);338                c++;339            }340        },341        function breakingNode(next){342            //this just stop the server von RequestMirror343            request({344                method: 'POST',345                url: 'http://localhost:' + testPort + '/foobar?bliebla=imba',346                headers: {347                    'User-Agent': 'foobar agent',348                    'cookie': 'foo=bar; centralnotice_buckets_by_campaign=%7B%22wlm%202015%22%3A%7B%22val%22%3A0%2C%22start%22%3A1440284460%2C%22end%22%3A1447275540%7D%7D; GeoIP=:::::v6; dewikimwuser-sessionId=b7361cbc5cb3b9b2; WMF-Last-Access=06-Oct-2015'349                },350                body: {351                    stop: true,352                    foo: 'bbbar',353                    ar: ['foo', 'bar']354                },355                json: true356            }, function (err, response, json) {357                next();358            });359        },360        function brokenNode(next){361            console.time("brokenNode");362            request({363                method: 'POST',364                url: 'http://localhost:' + testPort + '/foobar?bliebla=imba',365                headers: {366                    'User-Agent': 'foobar agent',367                    'cookie': 'foo=bar; centralnotice_buckets_by_campaign=%7B%22wlm%202015%22%3A%7B%22val%22%3A0%2C%22start%22%3A1440284460%2C%22end%22%3A1447275540%7D%7D; GeoIP=:::::v6; dewikimwuser-sessionId=b7361cbc5cb3b9b2; WMF-Last-Access=06-Oct-2015'368                },369                body: {370                    stop: true,371                    foo: 'bbbar',372                    ar: ['foo', 'bar']373                },374                json: true375            }, function (err, response, json) {376                if (err) {377                    testFailed.push('jsonRequest(): error in request');378                }379                try{380                    if(json!='StickyLoadBalancer: Error with node'){381                        testFailed.push('brokenNode(): wrong error handling with broken node');382                    }383                }catch(e){}384                console.timeEnd("brokenNode");385                next();386            });387        },388        function finish() {389            console.log('failed tests:');390            console.dir(testFailed);391            cb();392            // setTimeout(process.exit(1));393        }394    ]);395};396    runTest(function(){397       process.exit();...Using AI Code Generation
1testFailed("This is a test failure");2testPassed("This is a test success");3testStep("This is a test step");4testStepTimeout("This is a test step timeout");5testWaitUntilDone();6testDone();7waitForTestCompletion();8setTimeout(function () {9    testPassed("This is a test success");10    testDone();11}, 1000);12setInterval(function () {13    testPassed("This is a test success");14    testDone();15}, 1000);16var timer = setTimeout(function () {17    testPassed("This is a test success");18    testDone();19}, 1000);20clearTimeout(timer);21var timer = setInterval(function () {22    testPassed("This is a test success");23    testDone();24}, 1000);25clearInterval(timer);26console.log("This is a console log");27console.error("This is a console error");28console.info("This is a console info");29console.warn("This is a console warn");30console.debug("This is a console debug");31console.assert(true, "This is a console assert");Using AI Code Generation
1var wpt = require('webpagetest');2var webpagetest = new wpt('API_KEY');3  if (err) return console.log(err);4  console.log(data);5});6`test(url, options, callback)`Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('A.5b5a5d5a5d5a5d5a5d5a5d5a5d5a5d5a5');3var options = {4};5test.runTest(url, options, function(err, data) {6  if (err) return console.error(err);7  console.log('Test Status:', data.statusText);8  test.getTestResults(data.data.testId, function(err, data) {9    if (err) return console.error(err);10    console.log('Test Status:', data.statusText);11    console.log('View test at:', data.data.summary);12  });13});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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
