mirror of
https://github.com/pyscript/pyscript.git
synced 2026-05-16 07:02:15 -04:00
add tests for runtime config inside py-config and remove usage of indexURL (#734)
* add integration test for py-config * fix bug * fix test * remove indexURL altogether * make jest happy * fix create_proxy import * check that py-config loads an older version * add unit test * suggested changes * don't use /tmp because of bandit
This commit is contained in:
23
pyscriptjs/tests/unit/pyconfig.test.ts
Normal file
23
pyscriptjs/tests/unit/pyconfig.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { AppConfig, RuntimeConfig } from '../../src/runtime';
|
||||
import { PyConfig } from '../../src/components/pyconfig';
|
||||
|
||||
customElements.define('py-config', PyConfig);
|
||||
|
||||
describe('PyConfig', () => {
|
||||
let instance: PyConfig;
|
||||
beforeEach(() => {
|
||||
instance = new PyConfig();
|
||||
let runtime_config: RuntimeConfig = {src: "/demo/covfefe.js", name: "covfefe", lang: "covfefe"};
|
||||
let app_config: AppConfig = {autoclose_loader: true, runtimes: [runtime_config]};
|
||||
instance.values = app_config;
|
||||
});
|
||||
|
||||
it('should get the Config to just instantiate', async () => {
|
||||
expect(instance).toBeInstanceOf(PyConfig);
|
||||
});
|
||||
|
||||
it('should load runtime from config and set as script src', () => {
|
||||
instance.loadRuntimes();
|
||||
expect(document.scripts[0].src).toBe("http://localhost/demo/covfefe.js");
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,22 @@ describe('PyodideRuntime', () => {
|
||||
let runtime: PyodideRuntime;
|
||||
beforeAll(async () => {
|
||||
runtime = new PyodideRuntime();
|
||||
/**
|
||||
* Since import { loadPyodide } from 'pyodide';
|
||||
* is not used inside `src/pyodide.ts`, the function
|
||||
* `runtime.initialize();` below which calls
|
||||
* `loadInterpreter` and thus `loadPyodide` results
|
||||
* in an expected issue of:
|
||||
* ReferenceError: loadPyodide is not defined
|
||||
*
|
||||
* To make jest happy, while also not importing
|
||||
* explicitly inside `src/pyodide.ts`, the
|
||||
* following lines - so as to dynamically import
|
||||
* and make it available in the global namespace
|
||||
* - are used.
|
||||
*/
|
||||
const pyodideSpec = await import('pyodide');
|
||||
global.loadPyodide = pyodideSpec.loadPyodide;
|
||||
await runtime.initialize();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user