Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinscott committed Nov 18, 2023
1 parent 89b471c commit 57d49d6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 177 deletions.
3 changes: 2 additions & 1 deletion internals/http-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@internals/common": "workspace:*",
"fs-extra": "^11.1.1",
"tunnelmole": "2.2.0"
"tunnelmole": "2.2.8"
},
"wireit": {
"build": {
Expand Down Expand Up @@ -47,6 +47,7 @@
}
},
"scripts": {
"foo": "tmole 3000",
"build": "wireit",
"test:run": "wireit",
"test": "wireit"
Expand Down
4 changes: 2 additions & 2 deletions internals/http-server/src/HttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export class HttpServer {
this.port = getServerPort(httpServer);
if (this.useTunnel) {
this.tunnel = new Tunnel(this.port);
info('Starting server with tunnel');
info('Starting server with tunnel', this.name);
await this.tunnel.start();
info('Tunnel started', this.url);
info('Tunnel started', this.url, this.name);
}
const url = this.url;
if (!url) {
Expand Down
68 changes: 3 additions & 65 deletions internals/http-server/src/Tunnel.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { tunnelmole } from 'tunnelmole';
// import localtunnel from 'localtunnel';
// import ngrok from 'ngrok';
// import { info, warn } from '@internals/common/logger';
// import { service, tunnel } from "cloudflared";
// import { warn } from '@internals/common/logger';
// import path from 'path';
// import * as url from 'url';

// const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
process.env.TUNNELMOLE_TELEMETRY = '0';
process.env.TUNNELMOLE_QUIET_MODE = '1';

const regexp = new RegExp(/^http(.*) is forwarding to(.*)/);
const silenceTunnelmoleOutput = () => {
Expand All @@ -22,74 +14,20 @@ const silenceTunnelmoleOutput = () => {

export class Tunnel {
port: number;
// private localtunnel?: ReturnType<typeof localtunnel>;
url?: string;
// private _stop: any;


constructor(port: number) {
this.port = port;
}

// get url() {
// // if (!this.localtunnel) {
// // throw new Error('Tunnel was never started, ensure you call start');
// // }
// // return this.localtunnel?.url;
// }

async start() {
// ngrok
// this.url = await ngrok.connect({
// addr: this.port,
// });

// local tunnel
// console.log(this.port)
// this.localtunnel = await localtunnel({ port: this.port });
// return this.localtunnel.url;


// tunnelmole
silenceTunnelmoleOutput();
// // silenceTunnelmoleOutput();
this.url = await tunnelmole({
port: this.port,
});
return this.url;

// // cloudflared
// const { url, stop, child, ...rest } = tunnel({ "--url": `localhost:${this.port}`, '--config': path.resolve(__dirname, './config.yaml')});

// child?.stdout?.on('data', data => console.log(data.toString()));
// child?.stderr?.on('data', data => console.log(data.toString()));
// console.log(rest, url)
// this._stop = stop;
// const timers = [
// setTimeout(() => {
// warn('Still awaiting cloudflare tunnel to start')
// }, 3000),
// setTimeout(() => {
// throw new Error('Cloudflare tunnel failed to start in 10 seconds')
// }, 5000),
// ];
// this.url = await url;
// timers.forEach(clearTimeout);
// return url;
}

async close() { // skipcq: JS-0105
// if (!this._stop) {
// throw new Error('No stop command was set')
// }
// return this._stop();
// localtunnel
// return new Promise(resolve => {
// if (this.localtunnel) {
// this.localtunnel.on('close', () => {
// info('tunnel has been closed');
// });
// } else {
// warn('Tunnel was never started, so it cannot be closed');
// }
// });
}
}
6 changes: 6 additions & 0 deletions internals/test-runner/src/ClientsideTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,14 @@ export class ClientsideTestRunner {
});

// Note: these must be done sequentially; there's a race condition bug in tunnelmole
const timer = setTimeout(() => {
throw new Error('Could not start servers within 3 seconds');
}, 3000);

await this.fixturesServer.start();
await this.server.start();

clearTimeout(timer);
}

async stopServers(): Promise<void> {
Expand Down
Loading

0 comments on commit 57d49d6

Please sign in to comment.