Skip to content

Commit

Permalink
fix: ensure cache-handler clones full errors (#9383)
Browse files Browse the repository at this point in the history
* fix: ensure cache-handler clones full errors

* update test logging

* fix prettier

* fix tsc

* Fix lint

* improve setup

* fix ensure-cert

* attempt to add to trust store

* fixup tests

* rework holodeck init

* fix setup

* more cleanup

* fix prettier

* fix lint
  • Loading branch information
runspired committed Apr 25, 2024
1 parent a5528b1 commit 053d70b
Show file tree
Hide file tree
Showing 40 changed files with 634 additions and 368 deletions.
9 changes: 8 additions & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ runs:
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master

- name: 'Setup SSL Cert'
- name: 'Setup SSL Cert Infra'
if: ${{ inputs.with-cert }}
shell: bash
run: |
Expand Down Expand Up @@ -105,6 +105,13 @@ runs:
env:
ADTL_ARGS: ${{ inputs.adtl-install-args }}

- name: 'Generate SSL Cert'
if: ${{ inputs.with-cert }}
shell: bash
# Generates the cert if needed, using our local copy of @warp-drive/holodeck
run: |
node ./packages/holodeck/server/ensure-cert.js
- name: Setup Broccoli Caching
if: ${{ inputs.restore-broccoli-cache == 'true' }}
shell: bash
Expand Down
17 changes: 12 additions & 5 deletions packages/diagnostic/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ const isBun = typeof Bun !== 'undefined';
export default async function launch(config) {
if (isBun) {
debug(`Bun detected, using Bun.serve()`);
if (config.setup) {
debug(`Running configured setup hook`);
await config.setup();
debug(`Configured setup hook completed`);
}

const { checkPort } = await import('./bun/port.js');
const hostname = config.hostname ?? 'localhost';
const protocol = config.protocol ?? 'http';
Expand Down Expand Up @@ -67,6 +63,17 @@ export default async function launch(config) {
protocol,
url: `${protocol}://${hostname}:${port}`,
};

if (config.setup) {
debug(`Running configured setup hook`);
await config.setup({
port,
hostname,
protocol,
});
debug(`Configured setup hook completed`);
}

await launchBrowsers(config, state);
} catch (e) {
error(`Error: ${e?.message ?? e}`);
Expand Down
9 changes: 9 additions & 0 deletions packages/diagnostic/src/-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type GlobalConfig<TC extends TestContext = TestContext> = {
_current: SuiteReport | null;
useTestem: boolean;
useDiagnostic: boolean;
testTimeoutMs: number;
concurrency: number;
globalHooks: GlobalHooksStorage<TC>;
totals: {
Expand Down Expand Up @@ -77,6 +78,14 @@ export interface Diagnostic {
expect(count: number): void;
step(name: string): void;
verifySteps(steps: string[], message?: string): void;
/**
* Asserts that the actual value has at least the properties of the expected value.
* If additional properties are present on the actual value, they are ignored.
*
* @param actual
* @param expected
* @param message
*/
satisfies<T extends object, J extends T>(actual: J, expected: T, message?: string): void;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/diagnostic/src/internals/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const Config: GlobalConfig = {
useTestem: typeof Testem !== 'undefined',
// @ts-expect-error
useDiagnostic: typeof Testem === 'undefined',
testTimeoutMs: 50,
concurrency: 1,
params: {
hideReport: {
Expand Down Expand Up @@ -148,6 +149,7 @@ export type ConfigOptions = {
params: Record<string, ParamConfig>;
useTestem: boolean;
useDiagnostic: boolean;
testTimeoutMs: number;
};
const configOptions = [
'concurrency',
Expand Down Expand Up @@ -189,6 +191,8 @@ export function configure(options: Partial<ConfigOptions>): void {
}
});

Config.testTimeoutMs = options.testTimeoutMs ?? 0;

// copy over any remaining params
Object.assign(Config.params, options.params);
}
Expand Down
41 changes: 28 additions & 13 deletions packages/diagnostic/src/internals/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import { Diagnostic } from './diagnostic';

export const PublicTestInfo = Symbol('TestInfo');

function cancellable(promise: Promise<void>, timeout: number): Promise<void> {
return new Promise((resolve, reject) => {
const id = setTimeout(() => {
reject(new Error('Test Timeout Exceeded: ' + timeout + 'ms'));
}, timeout);
promise.then(resolve, reject).finally(() => clearTimeout(id));
});
}

export async function runTest<TC extends TestContext>(
moduleReport: ModuleReport,
beforeChain: HooksCallback<TC>[],
Expand Down Expand Up @@ -56,7 +65,13 @@ export async function runTest<TC extends TestContext>(
}

try {
await test.cb.call(testContext, Assert);
const promise = test.cb.call(testContext, Assert);

if (promise instanceof Promise && Config.testTimeoutMs > 0) {
await cancellable(promise, Config.testTimeoutMs);
}

await promise;
} catch (err) {
Assert.pushResult({
message: `Unexpected Test Failure: ${(err as Error).message}`,
Expand All @@ -68,20 +83,20 @@ export async function runTest<TC extends TestContext>(
if (!Config.params.tryCatch.value) {
throw err;
}
}

for (const hook of afterChain) {
await hook.call(testContext, Assert);
}
Assert._finalize();
} finally {
for (const hook of afterChain) {
await hook.call(testContext, Assert);
}
Assert._finalize();

groupLogs() && console.groupEnd();
testReport.end = instrument() && performance.mark(`test:${test.module.moduleName} > ${test.name}:end`);
testReport.measure =
instrument() &&
performance.measure(`test:${test.module.moduleName} > ${test.name}`, testReport.start.name, testReport.end.name);
groupLogs() && console.groupEnd();
testReport.end = instrument() && performance.mark(`test:${test.module.moduleName} > ${test.name}:end`);
testReport.measure =
instrument() &&
performance.measure(`test:${test.module.moduleName} > ${test.name}`, testReport.start.name, testReport.end.name);

DelegatingReporter.onTestFinish(testReport);
DelegatingReporter.onTestFinish(testReport);
}
}

export async function runModule<TC extends TestContext>(
Expand Down
3 changes: 0 additions & 3 deletions packages/holodeck/bin/cmd/_start.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/holodeck/bin/cmd/_stop.js

This file was deleted.

39 changes: 0 additions & 39 deletions packages/holodeck/bin/cmd/pm2.js

This file was deleted.

50 changes: 0 additions & 50 deletions packages/holodeck/bin/cmd/run.js

This file was deleted.

40 changes: 0 additions & 40 deletions packages/holodeck/bin/cmd/spawn.js

This file was deleted.

64 changes: 0 additions & 64 deletions packages/holodeck/bin/holodeck.js

This file was deleted.

8 changes: 7 additions & 1 deletion packages/holodeck/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import type { ScaffoldGenerator } from './mock';

const TEST_IDS = new WeakMap<object, { id: string; request: number; mock: number }>();

let HOST = 'https://localhost:1135/';
export function setConfig({ host }: { host: string }) {
HOST = host.endsWith('/') ? host : `${host}/`;
}

export function setTestId(context: object, str: string | null) {
if (str && TEST_IDS.has(context)) {
throw new Error(`MockServerHandler is already configured with a testId.`);
Expand Down Expand Up @@ -68,7 +73,8 @@ export async function mock(owner: object, generate: ScaffoldGenerator, isRecordi
}
const testMockNum = test.mock++;
if (getIsRecording() || isRecording) {
const url = `https://localhost:1135/__record?__xTestId=${test.id}&__xTestRequestNumber=${testMockNum}`;
const port = window.location.port ? `:${window.location.port}` : '';
const url = `${HOST}__record?__xTestId=${test.id}&__xTestRequestNumber=${testMockNum}`;
await fetch(url, {
method: 'POST',
body: JSON.stringify(generate()),
Expand Down

0 comments on commit 053d70b

Please sign in to comment.