{"id":"eyycheev/jest-snapshot","name":"jest-snapshot","scope":"eyycheev","platform":"roblox","description":"Mirrored from the Wally registry.","version":"3.14.0-rbx.2","latest":"3.14.0-rbx.2","versions":["3.14.0-rbx.0","3.14.0-rbx.1","3.14.0-rbx.2"],"license":"MIT","licenseRating":"safe","licenseCaveats":["The package archive does not include its license text; the license is declared in its manifest metadata."],"licenseVerified":false,"dependencies":{"eyycheev/chalk-lua":{"version":"^3.14.0-rbx.2","alias":"ChalkLua"},"eyycheev/jest-diff":{"version":"^3.14.0-rbx.2","alias":"JestDiff"},"eyycheev/jest-get-type":{"version":"^3.14.0-rbx.2","alias":"JestGetType"},"eyycheev/jest-matcher-utils":{"version":"^3.14.0-rbx.2","alias":"JestMatcherUtils"},"eyycheev/jest-types":{"version":"^3.14.0-rbx.2","alias":"JestTypes"},"jsdotlua/luau-polyfill":{"version":"^1.2.7","alias":"LuauPolyfill"},"eyycheev/pretty-format":{"version":"^3.14.0-rbx.2","alias":"PrettyFormat"},"jsdotlua/promise":{"version":"^3.5.2","alias":"Promise"},"eyycheev/roblox-shared":{"version":"^3.14.0-rbx.2","alias":"RobloxShared"}},"integrity":"15a31a385f84662bef036606c780e2f3b2343171d08aef40713072212637f459","likes":0,"downloads":0,"install":"forest install eyycheev/jest-snapshot","url":"https://forest.dev/p/roblox/eyycheev/jest-snapshot","files":"https://api.forest.dev/ai/package/roblox/eyycheev/jest-snapshot/files","readme":"# jest-snapshot\n\nUpstream: https://github.com/facebook/jest/tree/v27.4.7/packages/jest-snapshot\n\nThis package implements snapshot testing capabilities of Jest. You can find its documentation in the [Jest documentation](https://roblox.github.io/jest-roblox-internal).\n\n\n---\n\n### :pencil2: Notes\n* To update snapshots, first set `--load.asRobloxScript --fs.readwrite=\"$(pwd)\"` to grant `roblox-cli` elevated privileges to be able to write to filesystem and also grant it read/write access to the current directory and additionally set either:\n    * `--lua.globals=UPDATESNAPSHOT=\"all\"` to create new snapshots and update all existing snapshots\n    * `--lua.globals=UPDATESNAPSHOT=\"new\"` to only create new snapshots, existing failing snapshots will continue to fail\n* We intentionally exclude inline snapshot testing as it introduces a lot of code complexity for not much added utility.\n* Major deviations on snapshot read/write implementation details because we handle reading snapshots through various Roblox-specific mechanisms like `ModuleScript`, `FileSystemService`, and `CoreScriptSyncService`.\n* New snapshot tests pass by default in Jest because snapshots get automatically created for tests that do not already have a snapshot written to file, Jest Roblox cannot do this because elevated permissions are required to write snapshots to file, therefore new snapshot tests fail by default (Jest Roblox tries to match against an empty snapshot) until a snapshot update is run.\n* Detailed implementation notes and deviations on snapshot handling for future reference:\n    * Snapshots are written to file as a `.snap.lua` that can then be `require`'d as a valid `ModuleScript`. It exports a table with `{ [key] = \"snapshot\" }`.\n    * The TestEZ runner writes and updates three pieces of information into a `JEST_TEST_CONTEXT` global state for Jest snapshots to access:\n        * `instance`: the `Instance` reference to the `.spec.lua` that is currently running, this is needed to resolve the snapshot filesystem path.\n        * `blocks`: the test context (i.e. the `describe/it` hierarchy) of the currently running test, this is needed for the matchers to locate the correct snapshot to match against.\n        * `snapshotState`: the `SnapshotState` object, this is also needed for the matchers to locate the correct snapshot to match against.\n    * After a `.spec.lua` file is run, the TestEZ runner attempts to save a snapshot if a snapshot is dirty and the condition matches the snapshot update strategy.\n    * `toMatchSnapshot` first initializes the `SnapshotState` for a `.spec.lua` file and stores it in the `JEST_TEST_CONTEXT` global state if it doesn't already exist.\n        * If a `.snap.lua` file for that `.spec.lua` file exists, it initializes a `SnapshotState` of that snapshot.\n        * If it doesn't exist, it initializes an empty `SnapshotState` with its `_snapshotPath` set to `nil` (explained below).\n    * The `_snapshotPath` property of a `SnapshotState` is actually an `Instance` referring to the snapshot file instead of a path on the filesystem, this is needed because we load snapshots by `require`'ing them as a `ModuleScript` and also because we load things within the Roblox DOM instead of from filesystem.\n        * The exception is in `utils/saveSnapshotFile`, which actually takes a filesystem path for it's `snapshotPath` argument. The filesystem path of the snapshot is resolved in `SnapshotState:save` based off the path of the `.spec.lua` file that is currently running.\n        * This means that for a snapshot that doesn't yet exist, the `_snapshotPath` is set to `nil` since there is no `Instance` to refer to.\n    * Because `FileSystemService` and `CoreScriptSyncService` are heavily sandboxed and require elevated privileges, we opted to require absolutely no additional permissions to *match* against existing snapshots, but elevated permissions are needed to *update* snapshots.\n        * New snapshot tests fail by default (mentioned above).\n        * Obsolete snapshots (snapshots without a corresponding test) are not pruned unless done in an update snapshot run.\n            * Obsolete snapshot *files* are not pruned. If a `.spec.lua` no longer contains any snapshot tests, the `.snap.lua` will not be removed even through an update snapshot run. This is because of separation between the TestEZ runner and Jest Roblox, resulting in Jest Roblox initializing the `SnapshotState` and not the runner. This can be addressed when Jest Roblox gets its own runner.\n\n### :x: Excluded\n```\nsrc/snapshot_resolver.ts\n```\n\n### :package: [Dependencies](https://github.com/facebook/jest/blob/v27.4.7/packages/jest-snapshot/package.json)\n| Package               | Version | Status                    | Notes                                                                                |\n| --------------------- | ------- | ------------------------- | ------------------------------------------------------------------------------------ |\n| `@jest/types`         | 27.4.2  | :heavy_check_mark: Ported |                                                                                      |\n| `@chalk`              | 4.0.0   | :heavy_check_mark: Ported | Imported from the chalk-lua library                                                  |\n| `@expect`             | 27.4.6  | :heavy_check_mark: Ported |                                                                                      |\n| `@graceful-fs`        | 4.2.4   | :x: Will not port         | Don't need file system interaction since we use the Roblox datamodel for file access |\n| `@jest-diff`          | 27.4.6  | :heavy_check_mark: Ported |                                                                                      |\n| `@jest-get-type`      | 27.4.0  | :heavy_check_mark: Ported |                                                                                      |\n| `@jest-matcher-utils` | 27.4.6  | :heavy_check_mark: Ported |                                                                                      |\n| `@pretty-format`      | 27.4.6  | :heavy_check_mark: Ported |                                                                                      |\n","readmeTruncated":false}