Skip to content

Commit 8c6bab3

Browse files
committed
clean exiting of debugger and api file tests
1 parent 6ea55dc commit 8c6bab3

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

testsuite/ts/classes/api_test.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const Samples: Record<Expression, string> = {
9898
'<mn>2</mn>' +
9999
'</msup>' +
100100
'</math>',
101-
[Expression.Maction]:
101+
[Expression.Maction]:
102102
'<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">' +
103103
'<maction actiontype="toggle" selection="2" data-collapsible="true" id="mjx-collapse-0">' +
104104
'<mtext>&#x25C2;f()&#x25B8;</mtext>' +
@@ -258,6 +258,13 @@ export class ApiFileTest extends ApiTest {
258258
) {
259259
const sample = this.getSample(input);
260260
await System.setupEngine(feature || ApiTest.SETUP);
261+
await this.asyncTest(func, sample, result);
262+
await this.syncTest(func, sample, result);
263+
System.setupEngine({mode: 'async'});
264+
}
265+
266+
private async asyncTest(func: string, sample: string, result: string) {
267+
System.setupEngine({mode: 'async'});
261268
SystemExternal.fs.promises.readFile = jest.fn((_file: string) => {
262269
return Promise.resolve(sample);
263270
});
@@ -268,6 +275,14 @@ export class ApiFileTest extends ApiTest {
268275
this.assert.equal(output.toString(), result);
269276
}
270277

278+
private async syncTest(func: string, sample: string, result: string) {
279+
System.setupEngine({mode: 'sync'});
280+
SystemExternal.fs.readFileSync = jest.fn((_file: string) => sample);
281+
SystemExternal.fs.writeFileSync = jest.fn();
282+
let output = (System.file as any)[func]('input', 'output');
283+
this.assert.equal(output, result);
284+
}
285+
271286
/**
272287
* @override
273288
*/
@@ -278,6 +293,14 @@ export class ApiFileTest extends ApiTest {
278293
return super.setUpTest();
279294
}
280295

296+
/**
297+
* @override
298+
*/
299+
public async tearDownTest(): Promise<string> {
300+
jest.resetAllMocks();
301+
return super.tearDownTest();
302+
}
303+
281304
}
282305

283306
export class WorkerTest extends ApiTest {
@@ -335,7 +358,7 @@ export class DebugTest extends ApiTest {
335358
public information = 'Debugger test.';
336359

337360
private oldDebug: boolean | string = null;
338-
361+
339362
constructor() {
340363
super();
341364
this.pickFields.push('strings');
@@ -356,12 +379,12 @@ export class DebugTest extends ApiTest {
356379
* @override
357380
*/
358381
public async tearDownTest(): Promise<string> {
382+
Debugger.getInstance().exit();
359383
if (this.oldDebug === null) {
360384
delete ApiTest.SETUP['debug'];
361385
} else {
362386
ApiTest.SETUP['debug'] = this.oldDebug;
363387
}
364-
jest.clearAllMocks();
365388
return super.tearDownTest();
366389
}
367390

@@ -430,8 +453,8 @@ export class DebugFileTest extends DebugTest {
430453
* @override
431454
*/
432455
public async tearDownTest(): Promise<string> {
433-
// TODO: change this to exit.
434-
(Debugger.getInstance() as any).stream_ = null;
456+
jest.resetAllMocks();
435457
return super.tearDownTest();
436458
}
459+
437460
}

ts/common/debugger.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,15 @@ export class Debugger {
8888
* debugger.
8989
*/
9090
public exit(callback: () => any = () => {}) {
91-
this.fileHandle.then(() => {
92-
if (this.isActive_ && this.stream_) {
93-
this.stream_.end('', '', callback);
94-
}
95-
});
91+
if (this.stream_) {
92+
this.fileHandle.then(() => {
93+
if (this.isActive_ && this.stream_) {
94+
this.stream_.end('', '', callback);
95+
this.stream_ = null;
96+
}
97+
});
98+
}
99+
this.isActive_ = false;
96100
}
97101

98102
/**

0 commit comments

Comments
 (0)