Skip to content

Commit ffeab81

Browse files
committed
test: Update test infrastructure for better debugging
- Add support for DOM setup in createMegamorphicProgram tests - Improve error handling in test runner with unified error display - Add comprehensive harness setup for integration testing
1 parent ceac212 commit ffeab81

File tree

3 files changed

+48
-208
lines changed

3 files changed

+48
-208
lines changed

bin/run-tests.mjs

Lines changed: 27 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const { puppeteer, executablePath } = await PCR({});
1010
const __root = fileURLToPath(new URL('..', import.meta.url));
1111

1212
const qps = getQPs();
13-
const headless = process.argv.includes('--headless');
1413
const check = process.argv.includes('--check');
1514
const failingOnly = process.argv.includes('--failing-only') || check;
1615

@@ -126,207 +125,40 @@ stderr('[ci] puppeteer launched');
126125
* FailedAssertion[]}} TestEnd
127126
*/
128127

129-
const headlessHandler = {
130-
/**
131-
* @param {RunStart} runStart
132-
*/
133-
runStart(runStart) {
134-
console.log(`[HARNESS] run start: ${runStart.testCounts.total}`);
135-
},
136-
137-
/**
138-
* @param {RunEnd} runEnd
139-
*/
140-
runEnd(runEnd) {
141-
console.log(
142-
`[HARNESS] run end: ${runEnd.status} (${runEnd.runtime}ms, ${runEnd.testCounts.total} tests)`
143-
);
144-
},
145-
146-
/**
147-
* @param {SuiteStart} suiteStart
148-
*/
149-
suiteStart(suiteStart) {
150-
console.log(`[HARNESS] suite start: ${suiteStart.fullName.join(' ')}`);
151-
},
152-
153-
/**
154-
* @param {SuiteEnd} suiteEnd
155-
*/
156-
suiteEnd(suiteEnd) {
157-
console.log(`[HARNESS] suite end: ${suiteEnd.fullName.join(' ')}`);
158-
},
159-
160-
/**
161-
* @param {TestStart} testStart
162-
*/
163-
testStart(testStart) {
164-
console.log(`[HARNESS] test start: ${testStart.fullName.join(' ')}`);
165-
},
166-
167-
/**
168-
* @param {TestEnd} testEnd
169-
*/
170-
testEnd(testEnd) {
171-
if (testEnd.status === 'failed') {
172-
console.error(
173-
`[HARNESS] test end: ${testEnd.fullName.join(' ')} - failed (${testEnd.runtime}ms)`
174-
);
175-
for (const error of testEnd.errors) {
176-
console.error(`- ${error.message || 'Unknown error'}`);
177-
if (error.stack) {
178-
console.error(error.stack);
179-
}
180-
}
181-
} else {
182-
console.log(
183-
`[HARNESS] test end: ${testEnd.fullName.join(' ')} - ${testEnd.status} (${testEnd.runtime}ms)`
184-
);
185-
}
186-
},
187-
188-
/**
189-
* @param {string} type
190-
* @param {...unknown} args
191-
*/
192-
other(type, ...args) {
193-
stderr(`[HARNESS] [${type.toUpperCase()}]`, ...args);
194-
},
195-
};
196-
197-
class TapHandler {
198-
#current = 1;
199-
200-
/**
201-
* @param {unknown} string
202-
* @returns {string}
203-
*/
204-
#format(string) {
205-
if (typeof string === 'string') {
206-
return string.trim().replace(/\n/gu, '\n# ');
207-
}
208-
209-
const json = JSON.stringify(string) ?? 'undefined';
210-
211-
if (json.length > 100 || json.includes('\n')) {
212-
return this.#format(JSON.stringify(string, null, 2));
213-
} else {
214-
return json;
215-
}
216-
}
217-
218-
/**
219-
* @param {RunStart} runStart
220-
*/
221-
runStart(runStart) {
222-
console.log(`TAP version 13`);
223-
console.log(`# ${runStart.testCounts.total} tests`);
224-
}
225-
226-
/**
227-
* @param {RunEnd} runEnd
228-
*/
229-
runEnd(runEnd) {
230-
console.log(`1..${runEnd.testCounts.total}`);
231-
if (runEnd.status === 'failed') {
232-
console.error(`# tests failed: ${runEnd.testCounts.failed}`);
233-
process.exit(1);
234-
} else {
235-
console.log(`# tests passed: ${runEnd.testCounts.passed}`);
236-
process.exit(0);
237-
}
238-
}
239-
240-
/**
241-
* @param {SuiteStart} suiteStart
242-
*/
243-
suiteStart(suiteStart) {
244-
console.log(`# Suite: ${suiteStart.fullName.join(' ')}`);
245-
}
246-
247-
/**
248-
* @param {SuiteEnd} suiteEnd
249-
*/
250-
suiteEnd(suiteEnd) {
251-
console.log(`# End of suite: ${suiteEnd.fullName.join(' ')}`);
252-
}
253-
254-
/**
255-
* @param {TestStart} _testStart
256-
*/
257-
testStart(_testStart) {
258-
// console.log(`# Test: ${testStart.fullName.join(' ')}`);
259-
}
260-
261-
/**
262-
* @param {TestEnd} testEnd
263-
*/
264-
testEnd(testEnd) {
265-
const fullName = this.#format(testEnd.fullName.join(' '));
266-
const msg = `${this.#current++} (${testEnd.runtime}ms) ${fullName}`;
267-
if (testEnd.status === 'failed') {
268-
console.log(`not ok ${msg}`);
269-
for (const error of testEnd.errors) {
270-
this.failedAssertion(error);
128+
/**
129+
* @param {string} type
130+
* @param {...unknown} args
131+
*/
132+
function other(type, ...args) {
133+
if (!failingOnly) {
134+
if (args.length === 1) {
135+
const [arg] = args;
136+
if (typeof arg === 'string' && !arg.includes('\n')) {
137+
console.error(`# [${type.toUpperCase()}] ${arg}`);
138+
return;
139+
} else if ((typeof arg !== 'object' && typeof arg !== 'string') || arg === null) {
140+
console.error(`# [${type.toUpperCase()}] ${JSON.stringify(arg)}`);
141+
return;
271142
}
272-
} else if (!failingOnly) {
273-
console.log(`ok ${msg}`);
274143
}
275-
}
276144

277-
/**
278-
* @param {FailedAssertion} failedAssertion
279-
*/
280-
failedAssertion(failedAssertion) {
281-
console.error(`not ok - ${failedAssertion.message || 'Unknown error'}`);
282-
if (failedAssertion.stack) {
283-
console.error(`# ${this.#format(failedAssertion.stack)}`);
284-
} else {
285-
console.error(`# ${this.#format(failedAssertion.message || 'Unknown error')}`);
286-
}
287-
console.log(` ---`);
288-
console.log(` Expected: ${failedAssertion.expected}`);
289-
console.log(` Actual: ${failedAssertion.actual}`);
290-
console.log(` ...`);
291-
}
145+
console.error(`# [${type.toUpperCase()}]`);
292146

293-
/**
294-
* @param {string} type
295-
* @param {...unknown} args
296-
*/
297-
other(type, ...args) {
298-
if (!failingOnly) {
299-
if (args.length === 1) {
300-
const [arg] = args;
301-
if (typeof arg === 'string' && !arg.includes('\n')) {
302-
console.error(`# [${type.toUpperCase()}] ${arg}`);
303-
return;
304-
} else if ((typeof arg !== 'object' && typeof arg !== 'string') || arg === null) {
305-
console.error(`# [${type.toUpperCase()}] ${JSON.stringify(arg)}`);
306-
return;
307-
}
308-
}
309-
310-
console.error(`# [${type.toUpperCase()}]`);
311-
312-
for (const arg of args) {
313-
if (typeof arg === 'string') {
314-
const lines = arg.split('\n');
315-
for (const line of lines) {
316-
if (line) {
317-
console.error(`# > ${line}`);
318-
}
147+
for (const arg of args) {
148+
if (typeof arg === 'string') {
149+
const lines = arg.split('\n');
150+
for (const line of lines) {
151+
if (line) {
152+
console.error(`# > ${line}`);
319153
}
320-
} else {
321-
console.error(`# > `, arg);
322154
}
155+
} else {
156+
console.error(`# > `, arg);
323157
}
324158
}
325159
}
326160
}
327161

328-
const handler = headless ? headlessHandler : new TapHandler();
329-
330162
try {
331163
stderr('[ci] navigating to new page');
332164
const page = await browser.newPage();
@@ -365,7 +197,7 @@ try {
365197
return;
366198
}
367199

368-
handler.other(msg.type(), first, ...rest);
200+
other(msg.type(), first, ...rest);
369201
});
370202

371203
const { promise } = Promise.withResolvers();
@@ -388,16 +220,10 @@ process.exit(0);
388220

389221
/**
390222
* @param {string} msg
223+
* @param {...unknown[]} args
391224
*/
392-
function stdout(msg) {
393-
console.log(msg);
394-
}
395-
396-
/**
397-
* @param {string} msg
398-
*/
399-
function stderr(msg) {
225+
function stderr(msg, ...args) {
400226
if (!failingOnly) {
401-
console.error(msg);
227+
console.error(msg, ...args);
402228
}
403229
}

packages/@glimmer-workspace/integration-tests/lib/setup-harness.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ export async function bootQunit(
2828
QUnit.start();
2929
}
3030

31+
type QUnitExt = typeof QUnit & {
32+
reporters: {
33+
tap: {
34+
init: (qunit: typeof QUnit, options: { log: (message: string) => void }) => void;
35+
};
36+
};
37+
};
38+
39+
declare global {
40+
const exposedCiLog: undefined | ((message: string) => void);
41+
const ciHarnessEvent: undefined | ((event: string, details: QUnit.DoneDetails) => void);
42+
}
43+
3144
export async function setupQunit() {
3245
const qunitLib: QUnit = await import('qunit');
3346
await import('qunit/qunit/qunit.css');
@@ -79,10 +92,9 @@ export async function setupQunit() {
7992

8093
// const runner = autoRegister();
8194

82-
if (globalThis['exposedCiLog']) {
83-
console.log({ exposedCiLog });
84-
qunitLib.reporters.tap.init(qunitLib, {
85-
log: globalThis['exposedCiLog'],
95+
if (typeof exposedCiLog !== 'undefined') {
96+
(qunitLib as QUnitExt).reporters.tap.init(qunitLib, {
97+
log: exposedCiLog,
8698
});
8799
}
88100

@@ -129,8 +141,8 @@ export async function setupQunit() {
129141
qunitLib.done((finish) => {
130142
console.log('[HARNESS] done');
131143

132-
if (globalThis['ciHarnessEvent']) {
133-
globalThis['ciHarnessEvent']('end', finish);
144+
if (typeof ciHarnessEvent !== 'undefined') {
145+
ciHarnessEvent('end', finish);
134146
}
135147
});
136148

packages/@glimmer/compiler/test/compiler-test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function compileTemplate(
2929

3030
return {
3131
...wire,
32-
block: JSON.parse(wire.block),
32+
block: JSON.parse(wire.block) as SerializedTemplateBlock,
3333
};
3434
}
3535

@@ -45,6 +45,7 @@ function testSyntax({
4545
testFn: (desc: string, block: QUnit.TestFunctionCallback) => void;
4646
}) {
4747
testFn(desc, (assert) => {
48+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
4849
let actual = compileTemplate(template, (source) => eval(source));
4950

5051
let symbols = new ProgramSymbols();
@@ -80,6 +81,7 @@ QUnit.test(
8081
<a @onClick={{action "hi"}}>Link</a>
8182
`;
8283
assert.throws(
84+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
8385
() => compileTemplate(template, (source) => eval(source)),
8486
/@onClick is not a valid attribute name. @arguments are only allowed on components, but the tag for this element \(`a`\) is a regular, non-component HTML element/u
8587
);

0 commit comments

Comments
 (0)