-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom jest environment - Allow ES Class unit tests #3428
Conversation
Great work Oliver! Also, to handle the build/ folder requirement, could the package.json script be updated to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is fantastic, so happy to see :)
I don't think it's possible to bundle the code directly, as one has to specify a module name in the config, I'll have a look see if there are alternative ways of extending the It's not finished at the moment, I'd like all of the hardcoded strings to be configurable from the jest config. The
Probably |
document.body.appendChild(container); | ||
Adapt.course = { | ||
get: jest.fn().mockReturnValue( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eleanor-heath I'm pretty sure there is a much better way of mocking this Adapt.course.get function, but I didn't manage to read that far into the jest api. The Adapt.course object doesn't exist here, because Adapt data hasn't loaded, because core/js/app
wasn't imported. You can see the commented out section above which does that. (You can see my poor attempt at an async "wait for condition", to wait for _isStarted, thinking about it, Adapt.on('change:_isStarted', () => resolve(Promise.resolve()))
would have worked).
We should probably have a meeting to discuss what this code actually does? |
Yes please, I read your previous comment here #3383 (comment) so understand a lot of what has been done based on the comment you have added but a call to discuss unit testing in general and our plans would be ideal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really good work all involved on this, it is fairly straight forward to get up to speed with and works as expected, going to be very useful going forward.
…3383) * Issue#64/Introduce Jest component testing to the framework starting with Core Header template * issue#64/reverted change to adapt-contri-core * Issue#64 - removed view and model mock * Issue#64 - modified mocks to only include what was needed for the test, added spy on isMinScreenSize to test different screen sizes, added jest to eslintrc and added extra clearjest cache command * Issue#64 - removed device.screenSize setting within test as device.screenSize is no longer in use within the header template * Issue#64 - header file path update after initialising the core submodule * Removed coverage reports * Git ignore all files within the coverage directory * Added package-lock * removed displayTitle test * isScreenSizeMin Mock const * removed react helpers extported templates as is it not used in the jsx template * Extended with a custom jest environment to allow ES Class unit tests (#3428) * Fix: files moved to test folder, test preperation/execution seperated. * Files removed from root after being added to test folder. * Refactor * Pull jest-environment-adapt from npm instead of github * Added npm test help * Updating testing environment to 16 and removed typo --------- Co-authored-by: Eleanor Heath <[email protected]> Co-authored-by: Oliver Foster <[email protected]> Co-authored-by: joe-allen-89 <[email protected]>
# [5.32.0](v5.31.31...v5.32.0) (2023-09-26) ### New * Introduce Jest component testing to the framework (fixes #3417) (#3383) ([c83f68b](c83f68b)), closes [#3417](#3417) [#3383](#3383) [Issue#64](https://github.com/Issue/issues/64) [issue#64](https://github.com/issue/issues/64) [Issue#64](https://github.com/Issue/issues/64) [Issue#64](https://github.com/Issue/issues/64) [Issue#64](https://github.com/Issue/issues/64) [Issue#64](https://github.com/Issue/issues/64) [#3428](#3428)
Fix
New
scorm_test_harness.html
and all associated files, up untiladapt.min.js
, whereby tests canimport Adapt from 'core/js/adapt'
etc, and test the code directly.backbone
,html-react-parser
to steal from the Adapt loaded versionsbowser
to override appropriatelyplugins
dynamically, to allowimport 'core/js/app';
to load the compiled plugins, which will allow loading a full version of adapt into the testing environment for more complex json configured testsTesting
grunt dev
before runningnpm run jesttest
as files are loaded from thebuild/
folder to setup the test environmentuse strict
environment (have yet to figure out how to stop this), so mediaelement-and-player.js has somedelete
statements which failrequire
from the global scope, it should usewindow.require
insteadAdapt.course
as it's not loaded yet, so a return early must be inserted to fix