mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-02-13 04:00:56 -05:00
fix: reuse python worker between tests (#52617)
This commit is contained in:
committed by
GitHub
parent
0cb5162e21
commit
06bbc07ec6
@@ -63,6 +63,11 @@ ctx.onmessage = async (e: PythonRunEvent) => {
|
||||
|
||||
const assert = chai.assert;
|
||||
const __helpers = helpers;
|
||||
|
||||
// Create fresh globals for each test
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
const __userGlobals = pyodide.globals.get('dict')() as PyProxy;
|
||||
|
||||
/* eslint-enable @typescript-eslint/no-unused-vars */
|
||||
// uncomment the following line to inspect
|
||||
// the frame-runner as it runs tests
|
||||
@@ -109,14 +114,24 @@ ctx.onmessage = async (e: PythonRunEvent) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Clear out the old import otherwise it will use the old input/print
|
||||
// functions
|
||||
pyodide.runPython(`
|
||||
import sys
|
||||
try:
|
||||
del sys.modules['jscustom']
|
||||
del jscustom
|
||||
except (KeyError, NameError):
|
||||
pass
|
||||
|
||||
`);
|
||||
|
||||
// Make input available to python (print is not used yet)
|
||||
pyodide.registerJsModule('jscustom', {
|
||||
input: testInput
|
||||
// print: () => {}
|
||||
});
|
||||
// Create fresh globals for each test
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
const __userGlobals = pyodide.globals.get('dict')() as PyProxy;
|
||||
|
||||
// Some tests rely on __name__ being set to __main__ and we new dicts do not
|
||||
// have this set by default.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
@@ -162,5 +177,7 @@ ctx.onmessage = async (e: PythonRunEvent) => {
|
||||
actual: (err as { actual?: string }).actual
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
__userGlobals.destroy();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user