8000 Fix main.test.ts (#1320) · trofimander/pyscript@b61e843 · GitHub
[go: up one dir, main page]

Skip to content

Commit b61e843

Browse files
authored
Fix main.test.ts (pyscript#1320)
1 parent 146afb6 commit b61e843

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

pyscriptjs/src/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ globalExport('pyscript_get_config', pyscript_get_config);
436436

437437
// main entry point of execution
438438
const globalApp = new PyScriptApp();
439-
globalApp.readyPromise = globalApp.main();
439+
440+
// This top level execution causes trouble in jest
441+
if (typeof jest === 'undefined') {
442+
globalApp.readyPromise = globalApp.main();
443+
}
440444

441445
export { version };

pyscriptjs/tests/unit/main.test.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import { describe, it, expect } from '@jest/globals';
1+
import { describe, it, beforeEach, expect } from '@jest/globals';
2+
import { UserError, ErrorCode } from '../../src/exceptions';
3+
import { PyScriptApp } from '../../src/main';
24

3-
describe('Placeholder', () => {
4-
it('this is a placeholder, we need to fix and re-enable the commented out tests', () => {
5-
expect(true).toBe(true);
6-
});
7-
});
8-
9-
/*
105
describe('Test withUserErrorHandler', () => {
116
class MyApp extends PyScriptApp {
127
myRealMain: any;
@@ -17,7 +12,7 @@ describe('Test withUserErrorHandler', () => {
1712
}
1813

1914
async _realMain() {
20-
await this.myRealMain();
15+
this.myRealMain();
2116
}
2217
}
2318

@@ -68,8 +63,6 @@ describe('Test withUserErrorHandler', () => {
6863
}
6964

7065
const app = new MyApp(myRealMain);
71-
expect.assertions(1);
72-
await expect(async () => await app.main()).resolves.toThrow(new Error('Explosions!'));
66+
expect(app.main()).rejects.toThrow(new Error('Explosions!'));
7367
});
7468
});
75-
*/

pyscriptjs/tests/unit/setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ import { directoryManifest } from '../../directoryManifest.mjs';
44
jest.unstable_mockModule('../../src/python_package', async () => ({
55
python_package: await directoryManifest('./src/python/'),
66
}));
7+
8+
globalThis.jest = jest;

0 commit comments

Comments
 (0)
0