forked from Roblox/jest-roblox
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Merge latest upstream changes #16
Open
vocksel
wants to merge
46
commits into
jsdotlua:main
Choose a base branch
from
vocksel:upgrade
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Problem [APT-328](https://roblox.atlassian.net/browse/APT-328) ## Solution Align and complete implementation of `spyOn` function ## Testing Aligned a number of tests, including further tests for already-ported logic.
The type in the export is incorrect See here https://github.com/Roblox/jest-roblox-internal/blob/master/src/jest-runtime/src/init.lua#L2450 Updating and bumping to be moduleScript instead of string ---------
Updating changelog and bumping release version for 3.7.0. Needed for the vscode extension.
Mocking task.wait directly in jest as per suggestion of @LordOfSpelunky
## Problem Projects using the registry cannot consume new versions of Jest ## Solution Configre Jest to use the registry ## Testing Describe how the solution was tested (ideally unit tests). If done manually, describe the process and outcome. ## Checklist (remove if not applicable) - [ ] For new modules, has a README.md file with notes about the translation - [ ] All deviations are notated in code with `-- ROBLOX deviation: comment` - [ ] Translated files include a comment with a link to the upstream file
## Problem The `spyOn` function does not currently work with Lua globals because those tables are not mockable in the usual way. ## Solution Adds `jest.globalEnv` which can be used with `spyOn` to mock Lua globals in a test environment. Allows access to the unmocked globals as members too. ## Testing Added new unit test cases to cover API surface. ## Checklist (remove if not applicable) - [x] For new modules, has a README.md file with notes about the translation - [x] All deviations are notated in code with `-- ROBLOX deviation: comment` - [x] Translated files include a comment with a link to the upstream file
## Problem Jest assumes that all properties listed in the Roblox API are safe to index. This is not true when encountering properties that are only accessible to privileged code while Jest is running in a less privileged context, or when otherwise dealing with properties that have the potential to error on index. ## Solution Hide details of the Roblox API inside of RobloxInstance, and instead only expose 'safe' APIs that protect around all instance reads and writes, and expose only the properties which are accessible with the script's current capabilities. ## Testing Unit tests and snapshots.
Moved all jest docs links to point to the 27.x archived version of the jest docs and updated static assets correctly the docusaurus way.
…st environment (#405) ## Problem When Jest 2 users are in the midst of updating to Jest 3, they might attempt to pull in Jest 3 globals. https://roblox.slack.com/archives/C04N86WJA4R/p1721837297468429?thread_ts=1721815127.913289&cid=C04N86WJA4R ## Solution Update the JestGlobals error to include a tip about mixing Jest 2 and Jest 3. ## Testing Unit tests.
## Problem When an error with a stack trace is saved to a snapshot, superficial or unrelated changes in the codebase can cause the snapshot test to fail, because line numbers or file names in the stack trace can change. In particular, this occurs for some of Jest's own snapshot tests. ## Solution Introduce a new `redactStackTrace` function to `RobloxShared` which replaces stack traces with fixed-size dummy contents, similar to how `pruneDeps` cleans up stack trace lines from stack traces today. The final result is intended to be formatted exactly like a valid stack trace, except it is guaranteed to be completely decoupled from the actual stack trace it replaces, allowing for the stack trace to be snapshotted safely. Use `redactStackTrace` in the flaky snapshot tests in `errorParsing.spec` which were causing problems before. ## Testing Unit tests and snapshots.
## Problem When adding `pretty-format` plugins, it's possible to accidentally miss adding the plugin to the `prettyFormat.plugins` table. However, other code might still depend on the plugin being accessible from that table, which will silently fail. ## Solution Add an `__index` metatable which throws an error, so that when a plugin can't be found in the table, the issue is escalated right away. ## Testing Unit test. ## Checklist - [x] All deviations are notated in code with `-- ROBLOX deviation: comment`
## Problem RobloxInstance "serialises Folder" test should not fail when source code in RobloxInstance changes. ## Solution Copy a different folder of code into the tests directory as an unchanging target. Then, point the test at that. ## Testing Snapshot tests test themselves 🤠
jeparlefrancais
approved these changes
Oct 5, 2024
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.
Minor thing! Other than this it looks good to me 👍
Thanks a lot this is very valuable work 🎉
Co-authored-by: jeparlefrancais <[email protected]>
## Problem Right now, `spyOn` injects a table object when spying on objects. This table has a different type and overall behaves quite differently from the function it's meant to replace, and there's only so much we can do to disguise it in Luau. ## Solution Move away from injecting 'mock objects'. Instead, inject 'alike types' wherever possible - in this case, inject a function when spying on a function. ## Testing Unit & snapshot tests. ## Checklist (remove if not applicable) - [x] For new modules, has a README.md file with notes about the translation - [x] All deviations are notated in code with `-- ROBLOX deviation: comment` - [x] Translated files include a comment with a link to the upstream file
## Problem In future editions of Luau, require-by-string will be enabled, allowing users to pass in string paths to `require()` which are resolved internally to a ModuleScript instance. ## Solution Disable this feature in Jest, because we do not yet have functionality to match this. Throws a useful error instead. ## Testing Unit tests. ## Checklist - [x] All deviations are notated in code with `-- ROBLOX deviation: comment`
Latest recent node version breaks the node setup and yarn won't install things. Switching to version 22 solves this.
## Problem Callable tables are not compatible with the `spyOn` method. ## Solution Allow callable tables to be injected by `spyOn`, cloning their data and metatable while replacing the `__call` with a forwarding function to the mock object. ## Testing Unit tests and snapshots ## Checklist (remove if not applicable) - [x] For new modules, has a README.md file with notes about the translation - [x] All deviations are notated in code with `-- ROBLOX deviation: comment`
## Problem Sometimes, `RobloxInstance.listProps` is prone to returning incorrect property listings because of quantum UI bugs. ## Solution Perform a "cold read" of all properties to allow any quantum UI calculations to run, then do a "warm read" to collect all the properties once they've settled into their proper values. This behaviour is optional. Existing features do not utilise this "warm read" behaviour for backwards compat. ## Testing Unit tests and snapshots
## Problem Jest currently lacks the facilities to adequately mock and spy on the behaviour of `Instance` objects, because Jest's existing methods of spying on objects are invasive. Additionally, it's unclear how our existing mocking tech could expand to cover the nuances of instances well. ## Solution Introduce new internal classes for creating and working with mock instances: - `InstanceProxy` implementing basic proxying and mocking support - `DataModelMocker` to house complex mocking logic for instance <-> instance operations The implementation of `DataModelMocker` will remain pretty barebones for now, just acting as a simple cache for proxies, because not much functionality is needed here for the MVP of `GetService` mocks. In the future, if we implement a translation layer to properly sandbox instances, this will likely need to expand to support more complex data model operations, e.g. returning already-mocked instances when indexing into children or `.Parent`, so that `game.Workspace.Parent == game`, for example. ## Testing Unit tests.
Would really love if this get merged. Want to run it in Open Cloud Engine: https://devforum.roblox.com/t/beta-open-cloud-engine-api-for-executing-luau/3172185/67 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR merges the latest changes from commit 0d5efe3 in Roblox/jest-roblox
A new package JestMockGenv is included with these changes, and I'm hitting some build issues because of it. Seems like this package may need to be published to the jsdotlua npm scope first.
Checklist before submitting: