I'm trying to code a test to my client-server modules. I need to run the server before the client is sending its requests, so I'm trying to use beforeEach, but the test fails before the server even started running.
My test:
'use strict';
const cp = require('child_process');
const ip = require('my-local-ip');
const utils = require('../util/utils');
describe('Server and client connectivity:', () => {
let originalTimeout;
let server;
beforeEach(function() {
server = cp.fork('Server/Server');
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
});
it('should transfer index.html file to client', (done) => {
const client = cp.fork('Client/request', ['-t', ip(), '-p', 3300]);
expect(utils.isFileExistsInDirectory('Client/', 'index.html')).toBe(true);
done();
});
afterEach(function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
});
When I'm running manually first the server, and then the client with these commands, it works perfectly.
In the test sometimes the client request is sent before the server is listening.
How could it happen?
What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire