Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Mar 20, 2024
1 parent 42f1a68 commit 0d4fe59
Show file tree
Hide file tree
Showing 19 changed files with 380 additions and 27 deletions.
20 changes: 18 additions & 2 deletions packages/diagnostic/server/bun/socket-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import chalk from 'chalk';

import { debug, info } from '../utils/debug.js';
import { sinceStart } from '../utils/time.js';
import { watchAssets } from './watch.js';

export function buildHandler(config, state) {
const Connections = new Set();
if (config.serve && !config.noWatch) {
watchAssets(config.assets, () => {
Connections.forEach((ws) => {
ws.send(JSON.stringify({ name: 'reload' }));
});
});
}

return {
perMessageDeflate: true,
async message(ws, message) {
Expand Down Expand Up @@ -66,8 +76,14 @@ export function buildHandler(config, state) {
}
// console.log(JSON.parse(message));
}, // a message is received
open(ws) {}, // a socket is opened
close(ws, code, message) {}, // a socket is closed
open(ws) {
Connections.add(ws);
debug(`WebSocket opened`);
}, // a socket is opened
close(ws, code, message) {
Connections.delete(ws);
debug(`WebSocket closed`);
}, // a socket is closed
drain(ws) {}, // the socket is ready to receive more data
};
}
39 changes: 39 additions & 0 deletions packages/diagnostic/server/bun/watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { watch } from 'fs';

export function addCloseHandler(cb) {
let executed = false;

process.on('SIGINT', () => {
if (executed) return;
executed = true;
cb();
});

process.on('SIGTERM', () => {
if (executed) return;
executed = true;
cb();
});

process.on('SIGQUIT', () => {
if (executed) return;
executed = true;
cb();
});

process.on('exit', () => {
if (executed) return;
executed = true;
cb();
});
}

export function watchAssets(directory, onAssetChange) {
const watcher = watch(directory, { recursive: true }, (event, filename) => {
onAssetChange(event, filename);
});

addCloseHandler(() => {
watcher.close();
});
}
21 changes: 21 additions & 0 deletions packages/diagnostic/server/reporters/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ export default class CustomDotReporter {
this.totalLines = 0;
}

clearState() {
this.launchers = {};
this.tabs.clear();
this.idsToStartNumber.clear();
this.results = [];
this.failedTests = [];
this.globalFailures = [];
this.failedTestIds.clear();
this.total = 0;
this.pass = 0;
this.skip = 0;
this.todo = 0;
this.fail = 0;
this.shouldPrintHungTests = false;
this.lineFailures = [];
this.currentLineChars = 0;
this.totalLines = 0;
}

write(str) {
this.out.write(str);
}
Expand Down Expand Up @@ -193,6 +212,8 @@ export default class CustomDotReporter {
)} ms\n${HEADER_STR}\n\n`
);

this.clearState();

return this.failedTests.length ? 1 : 0;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/diagnostic/server/utils/get-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function getFlags() {
const filtered = {};

// global flags
const noWatch = flags.has('--no-watch') || flags.has('-w');
const debug = flags.has('--debug') || flags.has('-d');
const serve = flags.has('--serve') || flags.has('-s');
const noLaunch = flags.has('--no-launch') || flags.has('-n');
Expand Down Expand Up @@ -46,6 +47,9 @@ export function getFlags() {
if (useExisting) {
filtered['useExisting'] = true;
}
if (noWatch) {
filtered['noWatch'] = true;
}

return {
parsed: {
Expand All @@ -54,6 +58,7 @@ export function getFlags() {
noLaunch,
filter,
retry,
noWatch,
headless,
useExisting,
},
Expand Down
4 changes: 3 additions & 1 deletion packages/diagnostic/src/emitters/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ class DiagnosticEmitter implements Emitter {
throw new Error(`[Diagnostic] Remote Reporter Connection Failed`);
};
socket.onmessage = (message: MessageEvent<string>) => {
const msg = JSON.parse(message.data) as { name: 'close' };
const msg = JSON.parse(message.data) as { name: 'close' | 'reload' };
if (msg.name === 'close') {
window.close();
} else if (msg.name === 'reload') {
window.location.reload();
} else {
throw new Error(`[Diagnostic] Unexpected message from server`);
}
Expand Down
1 change: 0 additions & 1 deletion packages/ember/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { getRequestState } from './-private/request-state';
export { getPromiseState } from './-private/promise-state';
export { type PromiseState } from './-private/promise-state';
5 changes: 3 additions & 2 deletions packages/holodeck/bin/cmd/pm2.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-console */
/* global Bun, globalThis */
const { process } = globalThis;
import pm2 from 'pm2';
import fs from 'fs';
import pm2 from 'pm2';

const { process } = globalThis;

export default async function pm2Delegate(cmd, _args) {
const pkg = JSON.parse(fs.readFileSync('./package.json'), 'utf8');
Expand Down
1 change: 1 addition & 0 deletions packages/holodeck/bin/holodeck.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exec printf '%s\n' "$test1" "$test2" 1>&2
/* global Bun, globalThis */

import chalk from 'chalk';

import { spawn } from './cmd/spawn.js';

const isBun = typeof Bun !== 'undefined';
Expand Down
6 changes: 3 additions & 3 deletions packages/holodeck/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"extends": "../../package.json"
},
"dependencies": {
"@hono/node-server": "^1.3.3",
"chalk": "^4.1.2",
"hono": "^3.11.3",
"@hono/node-server": "^1.8.2",
"chalk": "^5.3.0",
"hono": "^4.1.2",
"pm2": "^5.3.1",
"pnpm-sync-dependencies-meta-injected": "0.0.10"
},
Expand Down
7 changes: 6 additions & 1 deletion packages/holodeck/server/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { serve } from '@hono/node-server';
import chalk from 'chalk';
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { HTTPException } from 'hono/http-exception';
import { logger } from 'hono/logger';
import crypto from 'node:crypto';
import fs from 'node:fs';
import http2 from 'node:http2';
import { dirname } from 'node:path';
import zlib from 'node:zlib';
import { fileURLToPath } from 'url';
import { HTTPException } from 'hono/http-exception';

const __dirname = dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -225,4 +226,8 @@ export function createServer(options) {
port: options.port ?? DEFAULT_PORT,
hostname: 'localhost',
});

console.log(
`\tMock server running at ${chalk.magenta('https://localhost:') + chalk.yellow(options.port ?? DEFAULT_PORT)}`
);
}
25 changes: 16 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/ember-data__request/tests/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ setupGlobalHooks((hooks) => {
configure();

start({
tryCatch: false,
debug: false,
tryCatch: true,
debug: true,
concurrency: 10,
groupLogs: false,
instrument: true,
hideReport: true,
hideReport: false,
useDiagnostic: true,
});
1 change: 1 addition & 0 deletions tests/warp-drive__ember/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
node.config(),
node.defaults(),
typescript.defaults(),
diagnostic.config(),
diagnostic.defaults({
files: ['tests/**/*.{js,ts}'],
allowedImports: ['@glimmer/tracking', '@glimmer/component', '@ember/object', '@ember/owner'],
Expand Down
22 changes: 21 additions & 1 deletion tests/warp-drive__ember/diagnostic.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/* global Bun */
import launch from '@warp-drive/diagnostic/server/default-setup.js';

await launch({});
/** @type {import('bun-types')} */

await launch({
async setup() {
Bun.spawnSync(['holodeck', 'start'], {
env: process.env,
cwd: process.cwd(),
stdout: 'inherit',
stderr: 'inherit',
});
},
async cleanup() {
Bun.spawnSync(['holodeck', 'end'], {
env: process.env,
cwd: process.cwd(),
stdout: 'inherit',
stderr: 'inherit',
});
},
});
10 changes: 10 additions & 0 deletions tests/warp-drive__ember/holodeck.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { dirname } from 'node:path';
import { fileURLToPath } from 'url';

import { createServer } from '@warp-drive/holodeck';

const __dirname = dirname(fileURLToPath(import.meta.url));

export default createServer({
projectRoot: __dirname,
});
7 changes: 7 additions & 0 deletions tests/warp-drive__ember/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"@warp-drive/ember": {
"injected": true
},
"@warp-drive/holodeck": {
"injected": true
},
"@warp-drive/diagnostic": {
"injected": true
},
"@warp-drive/schema-record": {
"injected": true
},
Expand Down Expand Up @@ -99,6 +105,7 @@
"@warp-drive/schema-record": "workspace:0.0.0-alpha.25",
"@warp-drive/ember": "workspace:0.0.0-alpha.1",
"@warp-drive/diagnostic": "workspace:0.0.0-alpha.25",
"@warp-drive/holodeck": "workspace:0.0.0-alpha.25",
"ember-auto-import": "^2.7.0",
"ember-cli": "~5.4.1",
"ember-cli-babel": "^8.2.0",
Expand Down
Loading

0 comments on commit 0d4fe59

Please sign in to comment.