How to use freePort method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

freeport.spec.ts

Source:freeport.spec.ts Github

copy

Full Screen

1import { setActivePinia, createPinia } from 'pinia'2import Direction from '@/types/enums/Direction'3import PortType from '@/types/enums/PortType'4import boundaries from '../../geometry/boundaries'5import ItemType from '@/types/enums/ItemType'6import {7 createConnection,8 createItem,9 createPort,10 stubAll11} from './__helpers__'12import { createDocumentStore } from '../..'13import ItemSubtype from '@/types/enums/ItemSubtype'14setActivePinia(createPinia())15describe('freeport actions', () => {16 beforeEach(() => jest.restoreAllMocks())17 describe('disconnectFreeport', () => {18 const store = createDocumentStore('document')()19 beforeEach(() => {20 store.$reset()21 stubAll(store, [22 'disconnect',23 'connect',24 'removeElement'25 ])26 })27 describe('when a connection is connected at both the target and the source', () => {28 beforeEach(() => {29 store.$patch({30 connections: {31 'connection1': createConnection('connection1', 'port1', 'port2'),32 'connection2': createConnection('connection2', 'port3', 'port4')33 },34 ports: {35 'port1': createPort('port1', 'item1', PortType.Output),36 'port2': createPort('port2', 'freeport', PortType.Input, { isFreeport: true }),37 'port3': createPort('port3', 'freeport', PortType.Output, { isFreeport: true }),38 'port4': createPort('port4', 'item2', PortType.Input)39 },40 items: {41 'item1': createItem('item1', ItemType.InputNode, { portIds: ['port1'] }),42 'item2': createItem('item2', ItemType.OutputNode, { portIds: ['port4'] }),43 'freeport': createItem('freeport', ItemType.Freeport, { portIds: ['port2', 'port3'] })44 }45 })46 store.disconnectFreeport('freeport')47 })48 it('should disconnect the freeport from its source', () => {49 expect(store.disconnect).toHaveBeenCalledWith({ source: 'port1', target: 'port2' })50 })51 it('should disconnect the freeport from its target', () => {52 expect(store.disconnect).toHaveBeenCalledWith({ source: 'port3', target: 'port4' })53 })54 it('should connect the freeport\'s original source to its original target', () => {55 expect(store.connect).toHaveBeenCalledWith({ source: 'port1', target: 'port4' })56 })57 it('should remove the item from the document', () => {58 expect(store.removeElement).toHaveBeenCalledWith('freeport')59 })60 })61 describe('when a connection is a freeport being dragged from a source port', () => {62 beforeEach(() => {63 store.$patch({64 connections: {65 'connection1': createConnection('connection1', 'port1', 'port2')66 },67 ports: {68 'port1': createPort('port1', 'item1', PortType.Output),69 'port2': createPort('port2', 'freeport', PortType.Input, { isFreeport: true }),70 'port3': createPort('port3', 'freeport', PortType.Output, { isFreeport: true })71 },72 items: {73 'item1': createItem('item1', ItemType.InputNode, { portIds: ['port1'] }),74 'freeport': createItem('freeport', ItemType.Freeport, { portIds: ['port2', 'port3'] })75 }76 })77 store.disconnectFreeport('freeport')78 })79 it('should only disconnect the freeport from its source', () => {80 expect(store.disconnect).toHaveBeenCalledWith({ source: 'port1', target: 'port2' })81 })82 it('should remove the item from the document', () => {83 expect(store.removeElement).toHaveBeenCalledWith('freeport')84 })85 })86 describe('when a connection is a freeport being dragged from a source port', () => {87 beforeEach(() => {88 store.$patch({89 connections: {90 'connection2': createConnection('connection2', 'port3', 'port4')91 },92 ports: {93 'port2': createPort('port2', 'freeport', PortType.Input, { isFreeport: true }),94 'port3': createPort('port3', 'freeport', PortType.Output, { isFreeport: true }),95 'port4': createPort('port4', 'item2', PortType.Input)96 },97 items: {98 'freeport': createItem('freeport', ItemType.Freeport, { portIds: ['port2', 'port3'] }),99 'item2': createItem('item2', ItemType.OutputNode, { portIds: ['port4'] })100 }101 })102 store.disconnectFreeport('freeport')103 })104 it('should only disconnect the freeport from its target', () => {105 expect(store.disconnect).toHaveBeenCalledWith({ source: 'port3', target: 'port4' })106 })107 it('should remove the item from the document', () => {108 expect(store.removeElement).toHaveBeenCalledWith('freeport')109 })110 })111 })112 describe('createFreeport', () => {113 const store = createDocumentStore('document')()114 const itemId = 'freeport'115 const sourceId = 'source-port'116 const targetId = 'target-port'117 const connectionChainId = 'connection-chain'118 const inputPortId = 'freeport-input-port'119 const outputPortId = 'freeport-output-port'120 const position: Point = { x: 0, y: 0 }121 beforeEach(() => {122 store.$reset()123 stubAll(store, [124 'addFreeportItem',125 'disconnect',126 'connect',127 'commitState',128 'setItemBoundingBox',129 'setSelectionState',130 'deselectAll',131 'createConnection'132 ])133 stubAll(store.simulation, [134 'addConnection',135 'removeConnection'136 ])137 })138 it('should not create a new freeport if an item having the same ID already exists', () => {139 store.$patch({140 items: {141 [itemId]: createItem(itemId, ItemType.Freeport)142 }143 })144 store.createFreeport({145 itemId,146 outputPortId,147 inputPortId148 })149 expect(store.connect).not.toHaveBeenCalled()150 expect(store.disconnect).not.toHaveBeenCalled()151 expect(store.addFreeportItem).not.toHaveBeenCalled()152 })153 describe('when this freeport is a joint between two connection segments', () => {154 const data = {155 itemId,156 sourceId,157 targetId,158 inputPortId,159 outputPortId,160 connectionChainId,161 position162 }163 beforeEach(() => {164 store.createFreeport(data)165 })166 it('should commit the current state to be undo-able', () => {167 expect(store.commitState).toHaveBeenCalled()168 })169 it('should deselect all items', () => {170 expect(store.deselectAll).toHaveBeenCalled()171 })172 it('should create the new freeport', () => {173 expect(store.addFreeportItem).toHaveBeenCalledWith({174 ...data,175 position: {176 x: 0,177 y: 0178 }179 })180 expect(store.setItemBoundingBox).toHaveBeenCalledWith(itemId)181 expect(store.activeFreeportId).toEqual(itemId)182 })183 })184 describe('when this freeport is a port being dragged from an output port', () => {185 const data = {186 itemId,187 sourceId,188 inputPortId,189 outputPortId: '',190 connectionChainId,191 position192 }193 beforeEach(() => {194 store.createFreeport(data)195 })196 it('should not commit the current state to be undo-able', () => {197 expect(store.commitState).not.toHaveBeenCalled()198 })199 it('should deselect all items', () => {200 expect(store.deselectAll).toHaveBeenCalled()201 })202 it('should create the new freeport', () => {203 expect(store.addFreeportItem).toHaveBeenCalledWith(data)204 expect(store.setItemBoundingBox).toHaveBeenCalledWith(itemId)205 expect(store.activeFreeportId).toEqual(itemId)206 })207 it('should not disconnect any connections', () => {208 expect(store.disconnect).not.toHaveBeenCalledWith(expect.any(Object))209 })210 it('should not reconnect the target port to anything', () => {211 expect(store.connect).not.toHaveBeenCalledWith({212 source: expect.any(String),213 target: targetId,214 connectionChainId215 })216 })217 })218 describe('when this freeport is a port being dragged from an input port', () => {219 const data = {220 itemId,221 targetId,222 inputPortId,223 outputPortId,224 connectionChainId,225 position226 }227 beforeEach(() => {228 store.createFreeport(data)229 })230 it('should not commit the current state to be undo-able', () => {231 expect(store.commitState).not.toHaveBeenCalled()232 })233 it('should deselect all items', () => {234 expect(store.deselectAll).toHaveBeenCalled()235 })236 it('should create the new freeport', () => {237 expect(store.addFreeportItem).toHaveBeenCalledWith(data)238 expect(store.setItemBoundingBox).toHaveBeenCalledWith(itemId)239 expect(store.activeFreeportId).toEqual(itemId)240 })241 it('should not disconnect any connections', () => {242 expect(store.disconnect).not.toHaveBeenCalledWith(expect.any(Object))243 })244 it('should not reconnect the source port to anything', () => {245 expect(store.connect).not.toHaveBeenCalledWith({246 source: sourceId,247 target: expect.any(String),248 connectionChainId249 })250 })251 })252 })253 describe('connectFreeport', () => {254 const store = createDocumentStore('document')()255 beforeEach(() => {256 stubAll(store, [257 'removeElement',258 'disconnect',259 'connect',260 'commitState'261 ])262 store.$reset()263 })264 describe('when there is a port in the neighborhood', () => {265 const sourceId = 'source-id'266 const targetId = 'target-id'267 const portId = 'port-id'268 const newPortId = 'new-port-id'269 const patch = (connectablePortIds: string[] = []) => store.$patch({270 ports: {271 [sourceId]: createPort(sourceId, '2', PortType.Input),272 [targetId]: createPort(sourceId, '2', PortType.Output),273 [newPortId]: createPort(newPortId, '2', PortType.Output),274 [portId]: createPort(portId, '1', PortType.Input)275 },276 connectablePortIds277 })278 beforeEach(() => {279 store.$reset()280 jest281 .spyOn(boundaries, 'isInNeighborhood')282 .mockReturnValue(true)283 })284 it('should not connect the port to itself or to one that is not in the predefined set of connectable ports', () => {285 patch()286 store.connectFreeport({ sourceId, portId })287 expect(store.connect).not.toHaveBeenCalled()288 })289 describe('when a connection is being made from an output port (acting as a source)', () => {290 beforeEach(() => {291 patch([newPortId])292 store.connectFreeport({ sourceId, portId })293 })294 it('should disconnect the temporary dragged port from the source', () => {295 expect(store.disconnect).toHaveBeenCalledWith({296 source: sourceId,297 target: portId298 })299 })300 it('should connect the the source to the discovered target', () => {301 expect(store.connect).toHaveBeenCalledWith({302 source: sourceId,303 target: newPortId304 })305 })306 })307 describe('when a connection is being made from an input port (acting as a target) to a receiving output port', () => {308 beforeEach(() => {309 patch([newPortId])310 store.connectFreeport({ targetId, portId })311 })312 it('should disconnect the temporary dragged port from the old target', () => {313 expect(store.disconnect).toHaveBeenCalledWith({314 source: portId,315 target: targetId316 })317 })318 it('should connect the the source to the new discovered source', () => {319 expect(store.connect).toHaveBeenCalledWith({320 source: newPortId,321 target: targetId322 })323 })324 })325 describe('when any connectable port is discovered', () => {326 it('should clear the list of connectable port IDs', () => {327 patch([newPortId])328 store.connectFreeport({ sourceId, portId })329 expect(store.connectablePortIds).toEqual([])330 })331 })332 describe('when an item owns the given port', () => {333 const itemId = 'item-id'334 const otherItemId = 'other-item-id'335 beforeEach(() => {336 patch([newPortId])337 store.$patch({338 items: {339 [itemId]: createItem(itemId, ItemType.Freeport, { portIds: [portId] }),340 [otherItemId]: createItem(otherItemId, ItemType.Freeport, { portIds: [sourceId, targetId] })341 }342 })343 store.connectFreeport({ sourceId, portId })344 })345 it('should remove the item', () => {346 expect(store.removeElement).toHaveBeenCalledWith(itemId)347 })348 it('should not remove any other items', () => {349 expect(store.removeElement).not.toHaveBeenCalledWith(otherItemId)350 })351 })352 })353 })354 describe('addFreeportItem', () => {355 const store = createDocumentStore('document')()356 const itemId = 'item-id'357 const inputPortId = 'input-port-id'358 const outputPortId = 'output-port-id'359 const value = 1360 beforeEach(() => {361 store.$reset()362 store.$patch({363 items: {364 [itemId]: createItem(itemId, ItemType.InputNode)365 }366 })367 jest368 .spyOn(store.simulation, 'addNode')369 .mockImplementation(jest.fn())370 })371 it('should add an input port if its ID is defined', () => {372 store.addFreeportItem({ itemId, inputPortId })373 expect(store.ports).toHaveProperty(inputPortId)374 expect(store.ports[inputPortId]).toEqual({375 id: inputPortId,376 type: PortType.Input,377 connectedPortIds: [],378 name: expect.any(String),379 elementId: itemId,380 orientation: Direction.Right,381 isFreeport: true,382 isMonitored: false,383 hue: 0,384 position: { x: 0, y: 0 },385 rotation: 0,386 value: 0387 })388 })389 it('should add an output port if its ID is defined', () => {390 store.addFreeportItem({ itemId, outputPortId })391 expect(store.ports).toHaveProperty(outputPortId)392 expect(store.ports[outputPortId]).toEqual({393 id: outputPortId,394 connectedPortIds: [],395 name: expect.any(String),396 type: PortType.Output,397 elementId: itemId,398 orientation: Direction.Left,399 isFreeport: true,400 isMonitored: false,401 hue: 0,402 position: { x: 0, y: 0 },403 rotation: 0,404 value: 0405 })406 })407 it('should add a new freeport item with the provided port IDs', () => {408 store.addFreeportItem({ itemId, inputPortId, outputPortId, value })409 expect(store.items).toHaveProperty(itemId)410 expect(store.items[itemId]).toEqual({411 id: itemId,412 name: '',413 type: ItemType.Freeport,414 subtype: ItemSubtype.None,415 portIds: [outputPortId, inputPortId],416 position: { x: 0, y: 0 },417 rotation: 0,418 boundingBox: {419 left: 0,420 top: 0,421 right: 1,422 bottom: 1423 },424 properties: expect.any(Object),425 isSelected: false,426 groupId: null,427 zIndex: 1,428 width: 1,429 height: 1430 })431 })432 it('should add the freeport to the circuit with its evaluation forced', () => {433 store.addFreeportItem({ itemId, inputPortId, outputPortId, value })434 expect(store.simulation.addNode).toHaveBeenCalledTimes(1)435 expect(store.simulation.addNode).toHaveBeenCalledWith(store.items[itemId], store.ports, true)436 })437 })...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1class PEPorts {2 #fp = require('find-free-port');3 #guiPort = null;4 #restPort = null;5 guiPort(callback) {6 this.#fp(8080, (err, freePort) => {7 if (freePort) {8 this.#guiPort = freePort;9 console.log("[GUI port] " + this.#guiPort);10 callback(freePort);11 } else {12 console.log("[GUI port] Error: " + err);13 throw "[GUI port] Error: " + err;14 }15 });16 }17 restPort(callback) {18 this.#fp(4000, (err, freePort) => {19 if (freePort) {20 this.#restPort = freePort;21 console.log("[REST port] " + this.#restPort);22 callback(freePort);23 } else {24 console.log("[REST port] Error: " + err);25 throw "[REST port] Error: " + err;26 }27 });28 }29 getGUIPort() {30 if (this.#guiPort) {31 return this.#guiPort;32 } else {33 throw "GUI port not setted";34 }35 }36 37 getRESTPort() {38 if (this.#restPort) {39 return this.#restPort;40 } else {41 throw "REST port not setted";42 }43 }44}45class HttpServer {46 #root = null;47 constructor(root) {48 this.#root = root;49 }50 startOn(host, port) {51 var express = require('express');52 this.app = express();53 this.app.use(express.static(this.#root));54 this.app.listen(port);55 return host + ":" + port;56 }57}58const { spawn } = require('child_process');59const { app, BrowserWindow } = require('electron');60const targetPath = "../service/target";61const jar = "spring-0.0.1-SNAPSHOT.jar";62let restService = null;63let pePorts = new PEPorts();64let httpServer = new HttpServer(__dirname + '/build');65app.whenReady().then(() => {66 const mainWindow = new BrowserWindow({67 width: 600,68 height: 600,69 webPreferences: {70 nodeIntegration: true71 }72 });73 pePorts.guiPort(function() {74 const url = httpServer.startOn(75 "http://localhost", 76 pePorts.getGUIPort()77 )78 mainWindow.loadURL(url);79 });80 pePorts.restPort(function (freePort) {81 restService = spawn('java', ['-jar', targetPath+"/"+jar, "--server.port="+freePort]);82 restService.on('data', function() {83 console.log('Spring service is ready!');84 });85 });86 mainWindow.on('closed', function() {87 restService.kill('SIGHUP');88 });...

Full Screen

Full Screen

freeport-async_vx.x.x.js

Source:freeport-async_vx.x.x.js Github

copy

Full Screen

1// flow-typed signature: befa8262ec9b88e3ea5f30bdedb218a12// flow-typed version: <<STUB>>/freeport-async_v^1.1.1/flow_v0.57.33/**4 * This is an autogenerated libdef stub for:5 *6 * 'freeport-async'7 *8 * Fill this stub out by replacing all the `any` types.9 *10 * Once filled out, we encourage you to share your work with the11 * community by sending a pull request to:12 * https://github.com/flowtype/flow-typed13 */14declare module 'freeport-async' {15 declare module.exports: any;16}17/**18 * We include stubs for each file inside this npm package in case you need to19 * require those files directly. Feel free to delete any files that aren't20 * needed.21 */22// Filename aliases23declare module 'freeport-async/index' {24 declare module.exports: $Exports<'freeport-async'>;25}26declare module 'freeport-async/index.js' {27 declare module.exports: $Exports<'freeport-async'>;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Pact } = require('@pact-foundation/pact')2const getMeAPort = async () => {3 const port = await Pact.getFreePort()4 console.log(port)5}6getMeAPort()7const { Pact } = require('@pact-foundation/pact')8const getMeAPort = async () => {9 const port = await Pact.getFreePort()10 console.log(port)11}12getMeAPort()

Full Screen

Using AI Code Generation

copy

Full Screen

1var pactNode = require('pact-foundation-pact-node');2var config = {3};4pactNode.freePort(config).then(function (port) {5 console.log('port is: ' + port);6});7[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1var pact = require('pact-foundation-pact');2var port = 1234;3pact.freePort(port).then(function(freePort) {4 console.log('freePort', freePort);5}, function(err) {6 console.log('err', err);7});8err { Error: listen EADDRINUSE

Full Screen

Using AI Code Generation

copy

Full Screen

1const pact = require('pact-foundation/pact-node');2console.log(pact);3pact.freePort().then(function (port) {4 console.log(port);5});6const port = require('./test2');7console.log(port);8{ freePort: [Function: freePort] }9{ freePort: [Function: freePort] }10const pact = require('pact-foundation/pact-node');11pact.freePort().then(function (port) {12 console.log(port);13});14const port = require('./test2');15console.log(port);

Full Screen

Using AI Code Generation

copy

Full Screen

1const Pact = require('@pact-foundation/pact').Pact;2const { somethingLike } = require('@pact-foundation/pact').Matchers;3const path = require('path');4const { expect } = require('chai');5const axios = require('axios');6describe('Pact', () => {7 let port;8 let mockServer;9 before(() => {10 .freePort()11 .then((freePort) => {12 port = freePort;13 url = url + ':' + port;14 mockServer = new Pact({15 log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),16 dir: path.resolve(process.cwd(), 'pacts'),17 });18 return mockServer.setup();19 });20 });21 after(() => {22 return mockServer.finalize();23 });24 describe('test', () => {25 const EXPECTED_BODY = {26 };27 before(() => {28 return mockServer.addInteraction({29 withRequest: {30 headers: {31 }32 },33 willRespondWith: {34 headers: {35 },36 }37 });38 });39 it('should validate the expectations of test consumer and test provider', () => {40 return axios.get(url + '/greeting')41 .then((response) => {42 expect(response.status).to.eql(200);43 expect(response.data).to.eql(EXPECTED_BODY);44 })45 .then(() => mockServer.verify());46 });47 });48});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Pact } = require('@pact-foundation/pact');2const { pactWith } = require('jest-pact');3const axios = require('axios');4const path = require('path');5const fs = require('fs');6const yaml = require('js-yaml');7const pactNode = require('pact-node');8const pactBrokerUrl = require('./pactBrokerUrl');9const pactBrokerUsername = require('./pactBrokerUsername');10const pactBrokerPassword = require('./pactBrokerPassword');11const pactBrokerToken = require('./pactBrokerToken');12const pactBrokerTags = require('./pactBrokerTags');13const pactBrokerConsumerVersion = require('./pactBrokerConsumerVersion');14const pactBrokerProviderVersion = require('./pactBrokerProviderVersion');15const pactBrokerProviderTags = require('./pactBrokerProviderTags');16const pactBrokerProviderVersionTags = require('./pactBrokerProviderVersionTags');17const pactBrokerProviderVersionNumber = require('./pactBrokerProviderVersionNumber');18const pactBrokerProviderVersionBranch = require('./pactBrokerProviderVersionBranch');19const pactBrokerProviderVersionBuildUrl = require('./pactBrokerProviderVersionBuildUrl');20const pactBrokerProviderVersionBuildNumber = require('./pactBrokerProviderVersionBuildNumber');21const pactBrokerProviderVersionGitCommit = require('./pactBrokerProviderVersionGitCommit');22const pactBrokerProviderVersionGitBranch = require('./pactBrokerProviderVersionGitBranch');

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 pact-foundation-pact 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