Skip to main content

testing

Helpers for testing programs that use the driver without a real Moodle, imported from @falkenslab/moodle-driver/testing: a fake site served inside a browser context, made-up grading panel HTML, and a browser manager that launches nothing.

Classes​

ClassDescription
ServiceFailureThrown by a fake service to answer with Moodle's exception errorcode.

Interfaces​

InterfaceDescription
FakeMoodleStateWhat the fake Moodle serves (serveFakeMoodle): the test sets it up and may change it while it runs (log someone in, change the sesskey); the fake records what it served in it.

Variables​

VariableDescription
PANELA grader panel reduced to its submission status table, as Moodle 5.2 renders it: online text with a summary and a full block, a short online text with only a summary, files, and comments. Made up; no real submission.
SITEThe fake Moodle's URL: the site URL to give the functions under test.

Functions​

FunctionDescription
fakeBrowserManagerA browser manager that never launches anything, with these methods instead.
launchTestBrowserThe first browser that launches headless: the system's Edge or Chrome, or Playwright's own Chromium (the test container, npm run test:docker); undefined skips the tests that need one.
moodlePageA Moodle page reduced to what the driver reads: the body class, M.cfg (wwwroot, sesskey, userId, and contextid when given), the logout link in the user menu and the page heading, as Moodle 5.2 renders them.
serveFakeMoodleServes a fake Moodle at SITE in context: logged out, every page is the login page, as with Moodle's forced login (served in place: Playwright doesn't route the request after a redirect it fulfilled, confirmed empirically); state.user logs someone in. lib/ajax/service.php answers like Moodle's, exceptions included.