How to use endTest method in wpt

Best JavaScript code snippet using wpt

test.js

Source:test.js Github

copy

Full Screen

...32 it('should work with casual web socket usage', endTest => {33 ws.send('test');34 ws.on('message', function(msg) {35 msg.should.equal('test-reply');36 endTest();37 });38 wsServer.on('message', function(msg) {39 wsServer.send('test-reply');40 });41 });42 it('should send JSON requests through basic API', endTest => {43 ws.sendRequest('test1', {code: 42}, function(err, res) {44 res.should.equal('foo');45 ws.sendRequest('test2', {code: 43}).then(function(res) {46 res.should.equal('foo2');47 endTest();48 });49 });50 wsServer.on('request:test1', function(data, responseCb) {51 data.code.should.equal(42);52 responseCb(null, 'foo');53 });54 wsServer.on('request:test2', function(data, responseCb) {55 data.code.should.equal(43);56 responseCb(null, 'foo2');57 });58 });59 it('should send JSON requests through promise request handlers',60 endTest => {61 ws.sendRequest('test1', {code: 42}, function(err, res) {62 res.should.equal('foo');63 ws.sendRequest('test2', {code: 43}).then(function(res) {64 res.should.equal('foo2');65 endTest();66 });67 });68 wsServer.onRequest('test1', function(data) {69 return 'foo';70 });71 wsServer.onRequest('test2', function(data) {72 return (new Promise(function(resolve, reject) {73 setTimeout(function() {74 resolve('foo2');75 }, 10);76 }));77 });78 });79 it('should send JSON requests through promise request handlers with nested promises',80 endTest => {81 ws.sendRequest('test1', {code: Promise.resolve(42)}, function(err, res) {82 assert.deepEqual(res, {83 foo: ['bar', 'foo']84 })85 endTest();86 });87 wsServer.onRequest('test1', function(data) {88 assert.deepEqual(data, {code: 42});89 90 return Promise.resolve({91 foo: [Promise.resolve('bar'), 'foo']92 });93 });94 });95 96 it('should send an error if request is not handled', endTest => {97 ws.sendRequest('test1', {code: 42}).catch(err => {98 if(err.message.match(/No handler for request: test1/)) {99 endTest();100 } else {101 throw err;102 }103 });104 });105 106 it('should send exceptions through promise handlers', endTest => {107 ws.sendRequest('test', {code: 42}, function(err, res) {108 err.should.equal("foo");109 endTest();110 });111 wsServer.onRequest('test', function(data) {112 throw "foo";113 });114 });115 116 it('should send real exceptions through promise handlers', endTest => {117 ws.sendRequest('test', {code: 42}, function(err, res) {118 err.name.should.equal('Remote::Error');119 err.message.should.equal("foo");120 endTest();121 });122 wsServer.onRequest('test', function(data) {123 throw new Error('foo');124 });125 });126 127 128 it('should send real exceptions through promise handlers with custom exception hook', endTest => {129 wsServer.setRemoteErrorHook(err => {130 err.name = 'FooBar';131 return Promise.resolve(err).delay(1);132 });133 134 wsServer.sendRequest('test', {code: 42}, function(err, res) {135 err.name.should.equal('FooBar');136 err.should.be.instanceof(WebSocket.RemoteError);137 err.message.should.equal("foo");138 endTest();139 });140 141 ws.onRequest('test', function(data) {142 throw new Error('foo');143 });144 });145 146 it('should not send Timeout after disconnected from server', endTest => {147 ws.setResponseTimeout(20);148 149 let timeout = setTimeout(() => {150 endTest();151 }, 30);152 153 ws.sendRequest('test', {code: 42}, function(err, res) {154 clearTimeout(timeout);155 if(err) endTest(err);156 });157 setTimeout(() => {158 wsServer.close();159 }, 10);160 wsServer.onRequest('test', function(data) {161 return new Promise((resolve, reject) => {});162 });163 164 });165 it('should not send Timeout after disconnected from client', endTest => {166 ws.setResponseTimeout(10);167 168 let timeout = setTimeout(() => {169 endTest();170 }, 15);171 172 ws.sendRequest('test', {code: 42}, function(err, res) {173 clearTimeout(timeout);174 if(err) endTest(err);175 });176 setTimeout(() => {177 ws.close();178 }, 5);179 wsServer.onRequest('test', function(data) {180 return new Promise((resolve, reject) => {});181 });182 });183 it('should send Error exceptions through promise handlers', endTest => {184 ws.sendRequest('test', {code: 42}).then(function(res) {185 //endTest();186 }).catch(WebSocket.RemoteError, function(err) {187 err.should.be.an.instanceOf(Error);188 err.message.should.equal('error with stacktrace');189 return Promise.resolve().then(function() {190 throw err;191 });192 }).catch(WebSocket.RemoteError, function(err) {193 err.stack.should.match(/remoteFunc/);194 endTest();195 });196 wsServer.onRequest('test', function(data) {197 function remoteFunc() {198 throw new Error('error with stacktrace');199 }200 return Promise.resolve().then(remoteFunc);201 });202 });203 it('should handle timeout errors', endTest => {204 var gotTimeout = false;205 ws.sendRequest('test1', {code: 42}, {responseTimeout: 10})206 .then(function(res) {207 res.should.equal('foo');208 }).catch(Promise.TimeoutError, function(err) {209 gotTimeout = true;210 err.message.should.equal('operation timed out');211 });212 wsServer.onRequest('test1', function(data) {213 return Promise.delay(20).then(function() {214 if(gotTimeout)215 endTest();216 return 'foo';217 });218 });219 });220 it('should send events', endTest => {221 ws.sendEvent('test', {222 code: 'foo'223 });224 wsServer.onEvent('test', function(data) {225 data.code.should.equal('foo');226 endTest();227 });228 });229 it('should not send events when removed', endTest => {230 ws.sendEvent('test', {231 code: 'foo'232 });233 wsServer.onEvent('test', function(data) {234 assert(false, 'Should not happen');235 });236 wsServer.offEvent('test');237 setTimeout(function() {238 endTest();239 }, 10);240 });241 it('should handle errors inside message handler', endTest => {242 ws.sendEvent('test');243 var tmp = console.error;244 console.error = function(msg) {245 };246 wsServer.on('message', function(msg) {247 throw new Error('test error');248 });249 wsServer.onEvent('test', function() {250 console.error = tmp;251 endTest();252 });253 });254 255 it('should not break if remote party suddenly dies', endTest => {256 ws.sendRequest('test1', {code: 42}).then(function(res) {257 res.should.equal('foo');258 });259 260 wsServer.onRequest('test1', function(data) {261 return Promise.delay(20).then(function() {262 cancelRequestCheck = true;263 ws.close();264 }).delay(20).then(endTest);265 });266 });267 describe('WebSocketServer', function() {268 it('should emit close events', endTest => {269 wss.close();270 wsServer.on('close', function() {271 endTest();272 });273 });274 });275 describe('WebSocket', function() {276 it('should emit close events from client', endTest => {277 ws.close(1000);278 wsServer.on('close', function() {279 endTest();280 });281 });282 it('should emit close events from client with terminate', endTest => {283 ws.terminate();284 wsServer.on('close', function() {285 endTest();286 });287 });288 it('should emit close events from server', endTest => {289 wsServer.close(1000);290 ws.on('close', function() {291 endTest();292 });293 });294 it('should emit close events from server with terminate', endTest => {295 wsServer.terminate();296 ws.on('close', function() {297 endTest();298 });299 });300 it('should emit an error if closing with bad error number', endTest => {301 ws.once('error', function(err) {302 err.message.should.match(/first argument must be a valid error code number/);303 endTest();304 });305 ws.close(0);306 });307 it('should emit an error if closing from server with bad error number', endTest => {308 wsServer.once('error', function(err) {309 err.message.should.match(/first argument must be a valid error code number/);310 endTest();311 });312 wsServer.close(0);313 });314 });315 316 describe('RequestHandler', function() {317 let emitter, requestHandler;318 before(() => {319 emitter = new EventEmitter();320 emitter.send = function(obj, cb) {321 emitter.emit('message', obj);322 if(cb) cb();323 };324 requestHandler = new RequestHandler(emitter);325 })326 function emitMessage(type, data) {327 328 }329 330 it('should emit event', endTest => {331 requestHandler.onEvent('test', () => {332 endTest();333 })334 requestHandler.sendEvent('test', 'foo');335 });336 337 338 it('should emit scoped event', endTest => {339 let scoped = requestHandler.scope('foobar');340 341 scoped.onEvent('test', () => {342 endTest();343 })344 requestHandler.sendEvent('foobar:test', 'foo');345 });346 347 it('should not emit scoped event', endTest => {348 let scoped = requestHandler.scope('foobar');349 350 scoped.onEvent('test', () => {351 endTest();352 })353 scoped.removeAllListeners();354 scoped.onEvent('test2', data => {355 data.should.equal('foo');356 endTest();357 })358 scoped.sendEvent('test2', 'foo');359 });360 361 it('should handle requests', endTest => {362 let scoped = requestHandler.scope('foobar');363 scoped.onRequest('test', () => {364 return 'bar';365 });366 scoped.sendRequest('test').then(data => {367 data.should.equal('bar');368 endTest();369 })370 });371 372 });373 ...

Full Screen

Full Screen

debug-receiver.js

Source:debug-receiver.js Github

copy

Full Screen

1// Copyright 2011 the V8 project authors. All rights reserved.2// Redistribution and use in source and binary forms, with or without3// modification, are permitted provided that the following conditions are4// met:5//6// * Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// * Redistributions in binary form must reproduce the above9// copyright notice, this list of conditions and the following10// disclaimer in the documentation and/or other materials provided11// with the distribution.12// * Neither the name of Google Inc. nor the names of its13// contributors may be used to endorse or promote products derived14// from this software without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27Debug = debug.Debug;28var test_name;29var listener_delegate;30var listener_called;31var exception;32var expected_receiver;33var begin_test_count = 0;34var end_test_count = 0;35var break_count = 0;36// Debug event listener which delegates. Exceptions have to be37// explicitly caught here and checked later because exception in the38// listener are not propagated to the surrounding JavaScript code.39function listener(event, exec_state, event_data, data) {40 try {41 if (event == Debug.DebugEvent.Break) {42 break_count++;43 listener_called = true;44 listener_delegate(exec_state);45 }46 } catch (e) {47 exception = e;48 }49}50// Add the debug event listener.51Debug.setListener(listener);52// Initialize for a new test.53function BeginTest(name) {54 test_name = name;55 listener_called = false;56 exception = null;57 begin_test_count++;58}59// Check result of a test.60function EndTest() {61 assertTrue(listener_called, "listener not called for " + test_name);62 assertNull(exception, test_name);63 end_test_count++;64}65// Check that the debugger correctly reflects that the receiver is not66// converted to object for strict mode functions.67function Strict() { "use strict"; debugger; }68function TestStrict(receiver) {69 expected_receiver = receiver;70 Strict.call(receiver);71}72listener_delegate = function(exec_state) {73 var receiver = exec_state.frame().receiver();74 assertEquals(expected_receiver, receiver.value())75}76BeginTest("strict: undefined"); TestStrict(undefined); EndTest();77BeginTest("strict: null"); TestStrict(null); EndTest();78BeginTest("strict: 1"); TestStrict(1); EndTest();79BeginTest("strict: 1.2"); TestStrict(1.2); EndTest();80BeginTest("strict: 'asdf'"); TestStrict('asdf'); EndTest();81BeginTest("strict: true"); TestStrict(true); EndTest();82// Check that the debugger correctly reflects the object conversion of83// the receiver for non-strict mode functions.84function NonStrict() { debugger; }85function TestNonStrict(receiver) {86 // null and undefined should be transformed to the global object and87 // primitives should be wrapped.88 expected_receiver = (receiver == null) ? this : Object(receiver);89 NonStrict.call(receiver);90}91listener_delegate = function(exec_state) {92 var receiver = exec_state.frame().receiver();93 assertEquals(expected_receiver, receiver.value());94}95BeginTest("non-strict: undefined"); TestNonStrict(undefined); EndTest();96BeginTest("non-strict: null"); TestNonStrict(null); EndTest();97BeginTest("non-strict: 1"); TestNonStrict(1); EndTest();98BeginTest("non-strict: 1.2"); TestNonStrict(1.2); EndTest();99BeginTest("non-strict: 'asdf'"); TestNonStrict('asdf'); EndTest();100BeginTest("non-strict: true"); TestNonStrict(true); EndTest();101assertEquals(begin_test_count, break_count,102 'one or more tests did not enter the debugger');103assertEquals(begin_test_count, end_test_count,...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...12 test('Has a task function (well it inherits from Undertaker)', testOptions => {13 const equal = testOptions.equal14 const endTest = testOptions.end15 equal(typeof unleashTaskManager.task, 'function')16 endTest()17 })18 test('Has the expected number of tasks', testOptions => {19 const equal = testOptions.equal20 const endTest = testOptions.end21 equal(taskNames.length, 17)22 endTest()23 })24 test('Has the expected number of dry run tasks', testOptions => {25 const equal = testOptions.equal26 const endTest = testOptions.end27 const dryRunTaskNames = taskNames.filter(n => includes.call(n, 'dry-run'))28 equal(dryRunTaskNames.length, 5)29 endTest()30 })31 test('Has changelog write tasks for each semver type', testOptions => {32 const equal = testOptions.equal33 const endTest = testOptions.end34 const changelogWritePrefix = 'changelog:write:'35 const changelogWriteTaskNames = taskNames.filter(n => includes.call(n, changelogWritePrefix))36 equal(changelogWriteTaskNames.length, SemVerIncrementTypes.length)37 SemVerIncrementTypes.forEach(t => equal(includes.call(changelogWriteTaskNames, `${changelogWritePrefix}${t}`), true))38 endTest()39 })40 test('Has a ghpages dry run task', testOptions => {41 const equal = testOptions.equal42 const endTest = testOptions.end43 equal(typeof unleashTaskManager._registry._tasks['ghpages:deploy:dry-run'], 'function')44 endTest()45 })46 test('Has an ls task', testOptions => {47 const equal = testOptions.equal48 const endTest = testOptions.end49 equal(typeof unleashTaskManager.task('ls'), 'function')50 endTest()51 })52 endSpec()...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.endTest('testId', function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.2f2e3e3e3e3e3e3e3e3e3e3e3e3e3e3');3wpt.endTest('141221_2Q_2X', function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org', 'A.2f2e3e3e3e3e3e3e3e3e3e3e3e3e3e');9 if (err) return console.error(err);10 console.log(data);11});12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org', 'A.2f2e3e3e3e3e3e3e3e3e3e3e3e3e3e');14wpt.getTestResults('141221_2Q_2X', function(err, data) {15 if (err) return console.error(err);16 console.log(data);17});18var wpt = require('webpagetest');19var wpt = new WebPageTest('www.webpagetest.org', 'A.2f2e3e3e3e3e3e3e3e3e3e3e3e3e3e');20wpt.getTestStatus('141221_2Q_2X', function(err, data) {21 if (err) return console.error(err);22 console.log(data);23});24var wpt = require('webpagetest

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