Skip to content
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
wants to merge 46 commits into
base: main
Choose a base branch
from
Open

Conversation

vocksel
Copy link

@vocksel vocksel commented Aug 17, 2024

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:

  • Tidy up merge artifacts
  • Added/updated relevant tests
  • Added/updated documentation

RoFlection Bot and others added 24 commits March 11, 2024 10:10
## 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 🤠
Copy link
Collaborator

@jeparlefrancais jeparlefrancais left a 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 🎉

src/jest-mock-genv/package.json Outdated Show resolved Hide resolved
vocksel and others added 5 commits October 6, 2024 10:40
## 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
vocksel and others added 17 commits October 12, 2024 11:47
## 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.
@MayGo
Copy link

MayGo commented Dec 6, 2024

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants