Skip to content

Commit

Permalink
use socket to communicate between cli and test
Browse files Browse the repository at this point in the history
  • Loading branch information
jperl committed Mar 27, 2020
1 parent 7d52e07 commit 26ff404
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/cli/edit.ts
@@ -1,8 +1,25 @@
import { spawn } from 'child_process';
import { buildArguments } from './runJest';
import { createServer, AddressInfo } from 'net';
import { loadConfig } from '../config';

const server = createServer((socket) => {
socket.on('data', (data) => {
console.log(data.toString());
});

socket.write('SERVER: Hello! This is server speaking.<br>');
socket.end('SERVER: Closing connection now.<br>');
}).on('error', (err) => {
console.error(err);
});

(async () => {
await new Promise((resolve) => server.listen(0, () => resolve()));

const address = server.address() as AddressInfo;
console.log('address', address, 'port', address.port);

const config = loadConfig();

const args = buildArguments({
Expand All @@ -14,8 +31,9 @@ import { loadConfig } from '../config';
testTimeout: config.testTimeout,
});

const child = spawn('npx', ['qawolf', 'test', ...args, 'keys'], {
const child = spawn('npx', ['qawolf', 'test', ...args, 'edit'], {
env: {
EDIT_PORT: `${address.port}`,
// // ...env,
// // override env with process.env
// // ex. for unit tests we want QAW_BROWSER to override cli one
Expand Down
42 changes: 42 additions & 0 deletions test/.qawolf/edit.test.js
@@ -0,0 +1,42 @@
const qawolf = require('qawolf');
const { TEST_URL } = require('./utils');

const net = require('net');

console.log(process.env.EDIT_PORT);

const client = net.createConnection(
{ port: Number(process.env.EDIT_PORT) },
() => {
console.log('CLIENT: I connected to the server.');
client.write('CLIENT: Hello this is client!');
},
);

client.on('data', (data) => {
console.log(data.toString());
client.end();
});

client.on('end', () => {
console.log('CLIENT: I disconnected from the server.');
});

let browser;
let page;

beforeAll(async () => {
browser = await qawolf.launch();
const context = await browser.newContext();
await qawolf.register(context);
page = await context.newPage();
});

afterAll(async () => {
await qawolf.stopVideos();
await browser.close();
});

test('edit', async () => {
await new Promise(() => {});
});

0 comments on commit 26ff404

Please sign in to comment.