>
11 | >mouse>
12 | >
13 | >rat>
14 | >
15 |
>
16 | }>
17 | />>"
18 | ]]
19 | exports["ReactElement plugin highlights syntax with color from theme option 1"] = [[
20 |
21 | "
22 | style>=\"color:red\">
23 | >>
24 | >Hello, Mouse!>
25 | >"
26 | ]]
27 | exports["ReactTestComponent plugin highlights syntax 1"] = [[
28 |
29 | "
30 | prop>={
31 | >
32 | >mouse>
33 | >
34 | >rat>
35 | >
36 |
>
37 | }>
38 | />>"
39 | ]]
40 | exports["ReactTestComponent plugin highlights syntax with color from theme option 1"] = [[
41 |
42 | "
43 | style>=\"color:red\">
44 | >>
45 | >Hello, Mouse!>
46 | >"
47 | ]]
48 | exports["ReactTestComponent removes undefined props 1"] = [[
49 |
50 | "
51 | xyz>={true}>
52 | />>"
53 | ]]
54 |
55 | return exports
56 |
--------------------------------------------------------------------------------
/src/pretty-format/README.md:
--------------------------------------------------------------------------------
1 | # pretty-format
2 |
3 | Upstream: https://github.com/facebook/jest/tree/v27.4.7/packages/pretty-format
4 |
5 | Stringify any Luau value
6 | * Supports Luau builtins and Roblox Instances.
7 | * Can be extended with user defined plugins.
8 |
9 | ---
10 |
11 | ### :pencil2: Notes
12 | * :warning: Our `prettyFormat` doesn't distinguish between `Tables`, `Arrays`, `Objects`, etc. and prints out all Lua table-like types as `Table`.
13 | * For example, an empty array is printed as `Table {}` and an array with values is printed as `Table {1, 2, 3,}`.
14 | * `printComplexValue` is reduced to just arrays and tables.
15 | * :x: Color formatting isn't supported so all related methods are omitted.
16 | * :hammer: Built-in plugins for `prettyFormat` are not implemented yet.
17 | * `prettyFormat` formats Roblox `DateTime` objects as a replacement for JS `Date`.
18 | * Formats using the Lua native string representations of primitives like `nil`, `nan` and `inf` over the JS `null`, `NaN` and `Infinity`. The tests are modified accordingly.
19 | * Formatting for any Javascript specific types in are omitted, `Symbol`, named `Function`, `Error`, `Date`, `BigInt`, etc.
20 | * `getConfig` is rewritten to avoid ternary operators.
21 | loop is rewritten with a `for` loop instead of an `iterator.next()`.
22 | * `Collections.lua` deviates from upstream substantially since Lua only has tables. We only have two functions: `printTableEntries` for formatting key, value pairs and `printListItems` for formatting arrays.
23 |
--------------------------------------------------------------------------------
/src/jest-diff/README.md:
--------------------------------------------------------------------------------
1 | # jest-diff
2 |
3 | Upstream: https://github.com/facebook/jest/tree/v27.4.7/packages/jest-diff
4 |
5 | Display differences clearly so people can review changes confidently.
6 |
7 | The `diff` named export serializes **values**, compares them line-by-line, and returns a string which includes comparison lines.
8 |
9 | Two named exports compare **strings** character-by-character:
10 |
11 | - `diffStringsUnified` returns a string.
12 | - `diffStringsRaw` returns an array of `Diff` objects.
13 |
14 | Three named exports compare **arrays of strings** line-by-line:
15 |
16 | - `diffLinesUnified` and `diffLinesUnified2` return a string.
17 | - `diffLinesRaw` returns an array of `Diff` objects.
18 |
19 | ---
20 |
21 | ### :pencil2: Notes
22 | * `CleanupSemantic.lua` is adapted from the Lua version of [`diff-match-patch`](https://github.com/google/diff-match-patch/blob/master/lua/diff_match_patch.lua) to resemble the upstream [`cleanupSemantics.ts`](https://github.com/facebook/jest/blob/v27.4.7/packages/jest-diff/src/cleanupSemantic.ts) instead of being a direct port of it.
23 | * Tests for it are added, which are not included in the upstream `jest-diff
24 | * Changes to tests:
25 | * Snapshots in `Diff.spec.lua` have their leading ``, ``, ``, and `` ANSI style codes manually removed.
26 | * Color formatting specific tests are omitted.
27 | * `changeColor` is assigned to a function that imitates `chalk.inverse` so we can test `diffStringsUnified`.
28 | * `Array[]`, `Object{}` are changed to `Table{}`.
29 |
--------------------------------------------------------------------------------
/src/jest-mock-rbx/README.md:
--------------------------------------------------------------------------------
1 | # jest-mock-rbx
2 |
3 | *No upstream. Roblox only.*
4 |
5 | This package implements Jest's data model mocking capabilities for Roblox:
6 |
7 | * `InstanceProxy`, used for constructing objects that act like an existing
8 | instance, except actions can be intercepted and mocked.
9 | * `DataModelMocker`, provides higher-level proxies that can interact with each
10 | other as part of a fake data model.
11 |
12 | ---
13 |
14 | ### :pencil2: Notes
15 | * Right now, only a limited subset of data model mocking features are
16 | implemented and available for use.
17 | * `DataModelMocker` should be used for constructing instance mocks, not
18 | `InstanceProxy`.
19 | * The `InstanceProxy` class is a minimal, self-contained implementation with
20 | no special behaviour.
21 | * The `DataModelMocker` class allows proxies to be reused, and provides
22 | useful default mock behaviour like returning proxied descendants or ancestry.
23 | * `InstanceProxy` intentionally only implements some of an `Instance`'s
24 | capabilities.
25 | * It is assumed that the instance proxy is being used on normal, idiomatic
26 | code that would correctly function if given an `Instance`.
27 | * Instance proxies have normal reference-based equality. They are not equal
28 | to the original instance, nor to any other proxies of that instance.
29 | * Instance proxies can't be consumed by functions expecting a "proper
30 | Instance".
31 | * In particular, calls to C such as `x:IsAncestorOf(InstanceProxy)` will
32 | error as these calls are not mockable.
33 |
34 |
--------------------------------------------------------------------------------
/src/jest-util/src/__tests__/isPromise.spec.lua:
--------------------------------------------------------------------------------
1 | -- ROBLOX upstream: https://github.com/facebook/jest/tree/v28.0.0/packages/jest-util/src/__tests__/isPromise.test.ts
2 |
3 | --[[*
4 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
5 | *
6 | * This source code is licensed under the MIT license found in the
7 | * LICENSE file in the root directory of this source tree.
8 | ]]
9 |
10 | local CurrentModule = script.Parent.Parent
11 | local Packages = CurrentModule.Parent
12 | local Promise = require(Packages.Promise)
13 | local LuauPolyfill = require(Packages.LuauPolyfill)
14 | local Symbol = LuauPolyfill.Symbol
15 | local isPromise = require(CurrentModule.isPromise).default
16 |
17 | local JestGlobals = require(Packages.Dev.JestGlobals)
18 | local expect = JestGlobals.expect
19 | local describe = JestGlobals.describe
20 | local it = JestGlobals.it
21 |
22 | describe("foo", function()
23 | describe("not a Promise: ", function()
24 | it("nil", function()
25 | expect(isPromise(nil)).toBe(false)
26 | end)
27 |
28 | -- ROBLOX FIXME: have to cast first Array element to `any` to avoid type narrowing issue
29 | for _, value in ipairs({ true :: any, 42, "1337", Symbol(), {} }) do
30 | it(tostring(value), function()
31 | expect(isPromise(value)).toBe(false)
32 | end)
33 | end
34 | end)
35 |
36 | it("a resolved Promise", function()
37 | expect(isPromise(Promise.resolve(42))).toBe(true)
38 | end)
39 |
40 | it("a rejected Promise", function()
41 | expect(isPromise(Promise.reject():catch(function() end))).toBe(true)
42 | end)
43 | end)
44 |
--------------------------------------------------------------------------------
/src/jest-util/src/__tests__/pluralize.roblox.spec.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | * Copyright (c) Roblox Corporation. All rights reserved.
3 | * Licensed under the MIT License (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * https://opensource.org/licenses/MIT
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | ]]
15 | -- ROBLOX NOTE: no upstream
16 |
17 | local CurrentModule = script.Parent
18 | local SrcModule = CurrentModule.Parent
19 | local Packages = SrcModule.Parent
20 |
21 | local JestGlobals = require(Packages.Dev.JestGlobals)
22 | local expect = JestGlobals.expect
23 | local describe = JestGlobals.describe
24 | local it = JestGlobals.it
25 |
26 | local pluralize = require(SrcModule.pluralize).default
27 |
28 | describe("pluralize", function()
29 | it("should not pluralize when count is 1", function()
30 | expect(pluralize("test", 1)).toEqual("1 test")
31 | end)
32 |
33 | it("should pluralize when count is 0", function()
34 | expect(pluralize("test", 0)).toEqual("0 tests")
35 | end)
36 |
37 | it("should pluralize when count is more than 1", function()
38 | for i = 2, 100 do
39 | expect(pluralize("test", i)).toEqual(tostring(i) .. " tests")
40 | end
41 | end)
42 | end)
43 |
--------------------------------------------------------------------------------
/src/jest-fake-timers/README.md:
--------------------------------------------------------------------------------
1 | # jest-fake-timers
2 |
3 | Upstream: https://github.com/facebook/jest/tree/v27.4.7/packages/jest-fake-timers
4 |
5 | This package contains the fake timers implementation for Jest. It can be activated by calling `jest.useFakeTimers()`. You can find its documentation in the [Jest documentation](https://roblox.github.io/jest-roblox-internal).
6 |
7 | The following timers are mocked:
8 | * `delay`
9 | * `tick`
10 | * `time`
11 | * `os`
12 | * `os.time`
13 | * `os.clock`
14 | * `task.delay`
15 | * `task.delay`
16 | * `task.cancel`
17 | * `task.wait`
18 | * `DateTime`
19 |
20 | ---
21 |
22 | ### :pencil2: Notes
23 | :exclamation: The fake timer API in Jest Roblox is aligned with the "modern" fake timer implementation in Jest. However, the actual implementation of fake timers in Jest Roblox under the hood massively deviates from upstream so that it works natively with the Roblox ecosystem.
24 |
25 | Similar to how Jest fake timers work by mocking the native timer functions (i.e. `setTimeout`, `setInterval`, `clearTimeout`, `clearInterval`) and `Date`, Jest Roblox fake timers work by mocking the native timer functions in Roblox (i.e. `delay`, `tick`), the Roblox `DateTime` and the Lua native timer methods `os.time` and `os.clock`.
26 | Additionally, Jest Roblox fake timers support a configurable engine frame time. By default, the engine frame time is 0 (i.e. continuous time), but if set, Jest Roblox fake timers will be processed by multiples of frame time. If engine frame time is set, then timers will be processed in the first frame after they are triggered.
27 |
--------------------------------------------------------------------------------
/src/jest-snapshot/src/__tests__/missingSnapshotFile.roblox.spec.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | * Copyright (c) Roblox Corporation. All rights reserved.
3 | * Licensed under the MIT License (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * https://opensource.org/licenses/MIT
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | ]]
15 | -- ROBLOX NOTE: no upstream
16 |
17 | local CurrentModule = script.Parent.Parent
18 | local Packages = CurrentModule.Parent
19 |
20 | local JestGlobals = require(Packages.Dev.JestGlobals)
21 | local expect = JestGlobals.expect
22 | local it = JestGlobals.it
23 |
24 | -- ROBLOX FIXME START: we can't call toMatchSnapshot and expect it to fail as this would affect the test state
25 | it.skip("tests that a missing snapshot file throws", function()
26 | expect(function()
27 | expect(nil :: any).toMatchSnapshot()
28 | end).toThrow(
29 | "Snapshot name: `tests that a missing snapshot file throws 1`\n\nNew snapshot was [1mnot written[22m. The update flag must be explicitly passed to write a new snapshot.\n\nThis is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default."
30 | )
31 | end)
32 | -- ROBLOX FIXME END
33 |
--------------------------------------------------------------------------------
/src/jest-matcher-utils/src/deepCyclicCopyReplaceable.lua:
--------------------------------------------------------------------------------
1 | -- ROBLOX upstream: https://github.com/facebook/jest/blob/v28.0.0/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts
2 | -- /**
3 | -- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
4 | -- *
5 | -- * This source code is licensed under the MIT license found in the
6 | -- * LICENSE file in the root directory of this source tree.
7 | -- */
8 |
9 | -- ROBLOX deviation: omitted isBuiltInObject and isMap functions because Lua only has one type, the table,
10 | -- for structuring data
11 |
12 | local deepCyclicCopyTable, deepCyclicCopyReplaceable
13 |
14 | type anyTable = { [any]: any }
15 |
16 | function deepCyclicCopyTable(tableToCopy: anyTable, cycles: anyTable)
17 | local newTable: anyTable = {}
18 |
19 | cycles[tableToCopy] = newTable
20 |
21 | for key, value in pairs(tableToCopy) do
22 | newTable[key] = deepCyclicCopyReplaceable(value, cycles)
23 | end
24 |
25 | return newTable
26 | end
27 |
28 | function deepCyclicCopyReplaceable(value: any, cycles: anyTable)
29 | if typeof(value) ~= "table" then
30 | return value
31 | elseif cycles[value] then
32 | return cycles[value]
33 | else
34 | local t = deepCyclicCopyTable(value, cycles)
35 | local mt = getmetatable(value)
36 | if mt and typeof(mt) == "table" then
37 | setmetatable(t, mt)
38 | end
39 | return t
40 | end
41 | end
42 |
43 | return function(value, cycles_: anyTable?)
44 | local cycles = cycles_ or {}
45 | setmetatable(cycles :: any, { _mode = "kv" })
46 |
47 | return deepCyclicCopyReplaceable(value, cycles)
48 | end
49 |
--------------------------------------------------------------------------------
/src/jest-diff/src/PrettyFormat.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | * Copyright (c) Roblox Corporation. All rights reserved.
3 | * Licensed under the MIT License (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * https://opensource.org/licenses/MIT
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | ]]
15 | -- ROBLOX NOTE: no upstream
16 | -- ROBLOX TODO: fix PrettyFormat types imports
17 |
18 | type CompareKeys = ((a: string, b: string) -> number) | nil
19 |
20 | type Plugin = any
21 |
22 | export type Plugins = { [number]: Plugin }
23 |
24 | type ThemeReceived = {
25 | comment: string?,
26 | content: string?,
27 | prop: string?,
28 | tag: string?,
29 | value: string?,
30 | }
31 |
32 | export type PrettyFormatOptions = {
33 | callToJSON: boolean?,
34 | compareKeys: CompareKeys,
35 | escapeRegex: boolean?,
36 | escapeString: boolean?,
37 | highlight: boolean?,
38 | indent: number?,
39 | maxDepth: number?,
40 | min: boolean?,
41 | plugins: Plugins?,
42 | printBasicPrototype: boolean?,
43 | printInstanceDefaults: boolean?,
44 | printFunctionName: boolean?,
45 | redactStackTracesInStrings: boolean?,
46 | theme: ThemeReceived?,
47 | }
48 |
49 | export type OptionsReceived = PrettyFormatOptions
50 |
51 | return {}
52 |
--------------------------------------------------------------------------------
/src/jest-snapshot/src/PrettyFormat.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | * Copyright (c) Roblox Corporation. All rights reserved.
3 | * Licensed under the MIT License (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * https://opensource.org/licenses/MIT
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | ]]
15 | -- ROBLOX NOTE: no upstream
16 | -- ROBLOX TODO: fix PrettyFormat types imports
17 |
18 | type CompareKeys = ((a: string, b: string) -> number) | nil
19 |
20 | type Plugin = any
21 |
22 | export type Plugins = { [number]: Plugin }
23 |
24 | type ThemeReceived = {
25 | comment: string?,
26 | content: string?,
27 | prop: string?,
28 | tag: string?,
29 | value: string?,
30 | }
31 |
32 | export type PrettyFormatOptions = {
33 | callToJSON: boolean?,
34 | compareKeys: CompareKeys,
35 | escapeRegex: boolean?,
36 | escapeString: boolean?,
37 | highlight: boolean?,
38 | indent: number?,
39 | maxDepth: number?,
40 | min: boolean?,
41 | plugins: Plugins?,
42 | printBasicPrototype: boolean?,
43 | printInstanceDefaults: boolean?,
44 | printFunctionName: boolean?,
45 | redactStackTracesInStrings: boolean?,
46 | theme: ThemeReceived?,
47 | }
48 |
49 | export type OptionsReceived = PrettyFormatOptions
50 |
51 | return {}
52 |
--------------------------------------------------------------------------------
/src/jest-matcher-utils/src/Replaceable.lua:
--------------------------------------------------------------------------------
1 | -- ROBLOX upstream: https://github.com/facebook/jest/blob/v28.0.0/packages/jest-matcher-utils/src/Replaceable.ts
2 | -- /**
3 | -- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
4 | -- *
5 | -- * This source code is licensed under the MIT license found in the
6 | -- * LICENSE file in the root directory of this source tree.
7 | -- */
8 |
9 | local CurrentModule = script.Parent
10 | local Packages = CurrentModule.Parent
11 | local getType = require(Packages.JestGetType).getType
12 |
13 | type ReplaceableForEachCallBack = (any, any, any) -> nil
14 |
15 | local Replaceable = {}
16 |
17 | Replaceable.__index = Replaceable
18 | function Replaceable.new(object: any)
19 | local self = {}
20 | self.object = object
21 | self.type = getType(object)
22 |
23 | if self.type ~= "table" then
24 | error("Type " .. self.type .. " is not supported in Replaceable!")
25 | end
26 |
27 | setmetatable(self, Replaceable)
28 |
29 | return self
30 | end
31 |
32 | function Replaceable.isReplaceable(obj1: any, obj2: any): boolean
33 | local obj1Type = getType(obj1)
34 | local obj2Type = getType(obj2)
35 |
36 | return obj1Type == obj2Type and obj1Type == "table"
37 | end
38 |
39 | function Replaceable:forEach(callback: ReplaceableForEachCallBack)
40 | for key, value in pairs(self.object) do
41 | callback(value, key, self.object)
42 | end
43 | end
44 |
45 | function Replaceable:get(key: any): any
46 | return self.object[key]
47 | end
48 |
49 | function Replaceable:set(key: any, value: any)
50 | self.object[key] = value
51 | end
52 |
53 | return Replaceable
54 |
--------------------------------------------------------------------------------
/src/jest-util/src/__tests__/errorWithStack.spec.lua:
--------------------------------------------------------------------------------
1 | -- ROBLOX upstream: https://github.com/facebook/jest/tree/v28.0.0/packages/jest-util/src/__tests__/errorWithStack.test.ts
2 |
3 | --[[*
4 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
5 | *
6 | * This source code is licensed under the MIT license found in the
7 | * LICENSE file in the root directory of this source tree.
8 | ]]
9 |
10 | local CurrentModule = script.Parent.Parent
11 | local Packages = CurrentModule.Parent
12 | local LuauPolyfill = require(Packages.LuauPolyfill)
13 | local Error = LuauPolyfill.Error
14 | local ErrorWithStack = require(CurrentModule.ErrorWithStack).default
15 |
16 | local JestGlobals = require(Packages.Dev.JestGlobals)
17 | local jest = JestGlobals.jest
18 | local expect = JestGlobals.expect
19 | local describe = JestGlobals.describe
20 | local it = JestGlobals.it
21 |
22 | describe("ErrorWithStack", function()
23 | local message = "💩 something went wrong"
24 | local function callsite() end
25 | it("calls Error.captureStackTrace with given callsite when capture exists", function()
26 | local originalCaptureStackTrace = Error["captureStackTrace"]
27 | local captureStackTraceSpy = jest.fn()
28 | Error["captureStackTrace"] = captureStackTraceSpy
29 | -- jest.spyOn(Error, "captureStackTrace")
30 | local actual = ErrorWithStack.new(message, callsite)
31 | expect(actual).toBeInstanceOf(Error)
32 | expect(actual.message).toBe(message)
33 | expect(Error["captureStackTrace"]).toHaveBeenCalledWith(actual, callsite)
34 |
35 | Error["captureStackTrace"] = originalCaptureStackTrace
36 | end)
37 | end)
38 |
--------------------------------------------------------------------------------
/src/jest-util/src/ErrorWithStack.lua:
--------------------------------------------------------------------------------
1 | -- ROBLOX upstream: https://github.com/facebook/jest/tree/v28.0.0/packages/jest-util/src/ErrorWithStack.ts
2 |
3 | --[[*
4 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
5 | *
6 | * This source code is licensed under the MIT license found in the
7 | * LICENSE file in the root directory of this source tree.
8 | ]]
9 |
10 | local CurrentModule = script.Parent
11 | local Packages = CurrentModule.Parent
12 | local LuauPolyfill = require(Packages.LuauPolyfill)
13 | local Boolean = LuauPolyfill.Boolean
14 | local Error = LuauPolyfill.Error
15 | type Error = LuauPolyfill.Error
16 | local exports = {}
17 |
18 | export type ErrorWithStack = Error & {}
19 | local ErrorWithStack = setmetatable({}, { __index = Error })
20 | ErrorWithStack.__index = ErrorWithStack
21 | function ErrorWithStack.new(
22 | message: string | nil,
23 | callsite: (...any) -> ...unknown,
24 | stackLimit: number?
25 | ): ErrorWithStack
26 | -- Ensure we have a large stack length so we get full details.
27 | local originalStackLimit = Error["stackTraceLimit"]
28 | if stackLimit ~= nil and stackLimit ~= 0 then
29 | Error["stackTraceLimit"] =
30 | math.max(stackLimit, Boolean.toJSBoolean(originalStackLimit) and originalStackLimit or 10)
31 | end
32 |
33 | local self = setmetatable(Error.new(message), ErrorWithStack)
34 | if Error.captureStackTrace then
35 | Error.captureStackTrace((self :: any) :: ErrorWithStack, callsite)
36 | end
37 | Error["stackTraceLimit"] = originalStackLimit
38 | return (self :: any) :: ErrorWithStack
39 | end
40 | exports.default = ErrorWithStack
41 | return exports
42 |
--------------------------------------------------------------------------------
/src/jest-core/src/lib/createContext.lua:
--------------------------------------------------------------------------------
1 | -- ROBLOX upstream: https://github.com/facebook/jest/blob/v28.0.0/packages/jest-core/src/lib/createContext.ts
2 | --[[*
3 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
4 | *
5 | * This source code is licensed under the MIT license found in the
6 | * LICENSE file in the root directory of this source tree.
7 | ]]
8 |
9 | local Packages = script.Parent.Parent.Parent
10 |
11 | local exports = {}
12 |
13 | local typesModule = require(Packages.JestTypes)
14 | type Config_ProjectConfig = typesModule.Config_ProjectConfig
15 | -- ROBLOX deviation START: no haste maps support
16 | -- local jest_haste_mapModule = require(Packages["jest-haste-map"])
17 | -- type HasteMapObject = jest_haste_mapModule.HasteMapObject
18 | type HasteMapObject = nil
19 | -- ROBLOX deviation END
20 | local jest_runtimeModule = require(Packages.JestRuntime)
21 | -- local Runtime = jest_runtimeModule.default
22 | type Context = jest_runtimeModule.Context
23 |
24 | -- ROBLOX deviation START: no haste maps support
25 | -- local function createContext(config: Config_ProjectConfig, ref0: HasteMapObject): TestContext
26 | -- local hasteFS, moduleMap = ref.hasteFS, ref.moduleMap
27 | -- ROBLOX deviation END
28 | local function createContext(config: Config_ProjectConfig, _ref: HasteMapObject): Context
29 | return {
30 | config = config,
31 | -- ROBLOX deviation START: no haste maps support
32 | -- hasteFS = hasteFS,
33 | -- moduleMap = moduleMap,
34 | -- resolver = Runtime:createResolver(config, moduleMap),
35 | -- ROBLOX deviation END
36 | }
37 | end
38 | exports.default = createContext
39 |
40 | return exports
41 |
--------------------------------------------------------------------------------
/src/jest-runtime/src/_types.lua:
--------------------------------------------------------------------------------
1 | --[[*
2 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | ]]
7 | -- ROBLOX NOTE: Not paired with upstream. Just using for the "Jest Object" type
8 |
9 | local CurrentModule = script.Parent
10 | local Packages = CurrentModule.Parent
11 |
12 | local JestFakeTimers = require(Packages.JestFakeTimers)
13 | type FakeTimers = JestFakeTimers.FakeTimers
14 |
15 | local moduleMockerModule = require(Packages.JestMock)
16 | type ModuleMocker = moduleMockerModule.ModuleMocker
17 |
18 | export type MockFactory = () -> ...unknown
19 |
20 | export type Jest = {
21 | -- autoMockOn: () -> Jest,
22 | -- autoMockOff: () -> Jest,
23 | -- disableAutomock: () -> Jest,
24 | -- enableAutomock: () -> Jest,
25 | -- mock: (scriptInstance: ModuleScript, mockFactory: MockFactory, options: any) -> Jest,
26 | clearAllMocks: () -> Jest,
27 | resetAllMocks: () -> Jest,
28 | restoreAllMocks: () -> Jest,
29 | useFakeTimers: () -> Jest,
30 | useRealTimers: () -> Jest,
31 | resetModules: () -> Jest,
32 | isolateModules: (fn: () -> ()) -> Jest,
33 | fn: () -> ModuleMocker,
34 | -- genMockFromModule: (scriptInstance: ModuleScript) -> any,
35 | getRealSystemTime: () -> (),
36 | getTimerCount: () -> number,
37 | runAllTicks: () -> (),
38 | runAllTimers: () -> (),
39 | runOnlyPendingTimers: () -> (),
40 | -- setMock: (scriptInstance: ModuleScript, mock: unknown, options: { virtual: boolean? }?) -> Jest,
41 | setSystemTime: (now: (number | DateTime)?) -> (),
42 | setTimeout: any,
43 | }
44 |
45 | return {}
46 |
--------------------------------------------------------------------------------
/src/jest-test-result/src/__tests__/formatTestResults.spec.lua:
--------------------------------------------------------------------------------
1 | -- ROBLOX upstream: https://github.com/facebook/jest/blob/v28.0.0/packages/jest-test-result/src/__tests__/formatTestResults.test.ts
2 | --[[*
3 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
4 | *
5 | * This source code is licensed under the MIT license found in the
6 | * LICENSE file in the root directory of this source tree.
7 | ]]
8 |
9 | local CurrentModule = script.Parent.Parent
10 | local Packages = CurrentModule.Parent
11 |
12 | local JestGlobals = require(Packages.Dev.JestGlobals)
13 | local expect = JestGlobals.expect
14 | local describe = JestGlobals.describe
15 | local it = JestGlobals.it
16 |
17 | local formatTestResults = require(CurrentModule.formatTestResults).default
18 |
19 | local types = require(CurrentModule.types)
20 | type AggregatedResult = types.AggregatedResult
21 |
22 | describe("formatTestResults", function()
23 | local assertion = {
24 | fullName = "TestedModule#aMethod when some condition is met returns true",
25 | status = "passed",
26 | title = "returns true",
27 | }
28 |
29 | -- ROBLOX deviation START - casted to any, TS should fail here
30 | local results: AggregatedResult = {
31 | testResults = {
32 | {
33 | numFailingTests = 0,
34 | perfStats = { end_ = 2, runtime = 1, slow = false, start = 1 }, -- @ts-expect-error
35 | testResults = { assertion },
36 | },
37 | },
38 | } :: any
39 | -- ROBLOX deviation END
40 |
41 | it("includes test full name", function()
42 | local result = formatTestResults(results, nil, nil)
43 | expect(result.testResults[1].assertionResults[1].fullName).toEqual(assertion.fullName)
44 | end)
45 | end)
46 |
--------------------------------------------------------------------------------
/src/roblox-shared/src/redactStackTrace.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | * Copyright (c) Roblox Corporation. All rights reserved.
3 | * Licensed under the MIT License (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * https://opensource.org/licenses/MIT
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | ]]
15 |
16 | local TRACE_LINE = `[%w_%-]+%.[%w_%-%.]+%:%d+[%w \t_]*`
17 | local REDACT_TRACE_WITH = ("\nRedacted.Stack.Trace:1337 function epicDuck"):rep(4):sub(2)
18 | local LUA_ERROR_LINE = `[%w_%-]+%.[%w_%-%.]+%:%d+%:[%w \t_]*`
19 | local REDACT_LUA_ERROR_WITH = "Redacted.Stack.Trace:1337: The epic duck is coming!"
20 |
21 | local function redactStackTrace(str: string?): string?
22 | if str == nil then
23 | return nil
24 | else
25 | local newLines = {}
26 | local lastLineRedacted = false
27 | for _, line in (str :: string):split("\n") do
28 | local lineWithRedactions = line:gsub(TRACE_LINE, if lastLineRedacted then "" else REDACT_TRACE_WITH)
29 | :gsub(LUA_ERROR_LINE, if lastLineRedacted then "" else REDACT_LUA_ERROR_WITH)
30 | lastLineRedacted = line ~= lineWithRedactions
31 | if not lastLineRedacted or lineWithRedactions:match("%S") then
32 | table.insert(newLines, lineWithRedactions)
33 | end
34 | end
35 | return table.concat(newLines, "\n")
36 | end
37 | end
38 |
39 | return redactStackTrace
40 |
--------------------------------------------------------------------------------
/src/jest-core/src/lib/logDebugMessages.lua:
--------------------------------------------------------------------------------
1 | -- ROBLOX upstream: https://github.com/facebook/jest/blob/v28.0.0/packages/jest-core/src/lib/logDebugMessages.ts
2 | --[[*
3 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
4 | *
5 | * This source code is licensed under the MIT license found in the
6 | * LICENSE file in the root directory of this source tree.
7 | ]]
8 |
9 | local Packages = script.Parent.Parent.Parent
10 | local LuauPolyfill = require(Packages.LuauPolyfill)
11 | type Array = LuauPolyfill.Array
12 |
13 | local exports = {}
14 |
15 | local typesModule = require(Packages.JestTypes)
16 | type Config_GlobalConfig = typesModule.Config_GlobalConfig
17 | type Config_ProjectConfig = typesModule.Config_ProjectConfig
18 | -- ROBLOX FIXME START: no version available
19 | -- local VERSION = require_("../../package.json").version -- if the output here changes, update `getConfig` in e2e/runJest.ts
20 | local VERSION = "27.4.7"
21 | -- ROBLOX FIXME END
22 |
23 | -- ROBLOX deviation START: added missing variables to limit nr deviations
24 | local RobloxShared = require(Packages.RobloxShared)
25 | local nodeUtils = RobloxShared.nodeUtils
26 | type NodeJS_WriteStream = RobloxShared.NodeJS_WriteStream
27 | local JSON = nodeUtils.JSON
28 | -- ROBLOX deviation END
29 |
30 | local function logDebugMessages(
31 | globalConfig: Config_GlobalConfig,
32 | configs: Array | Config_ProjectConfig,
33 | outputStream: NodeJS_WriteStream
34 | ): ()
35 | local output = { configs = configs, globalConfig = globalConfig, version = VERSION }
36 | outputStream:write((JSON.stringify(output, nil, " ")) .. "\n")
37 | end
38 | exports.default = logDebugMessages
39 |
40 | return exports
41 |
--------------------------------------------------------------------------------
/src/roblox-shared/src/__tests__/Writeable.spec.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | * Copyright (c) Roblox Corporation. All rights reserved.
3 | * Licensed under the MIT License (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * https://opensource.org/licenses/MIT
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | ]]
15 | -- ROBLOX note: no upstream
16 |
17 | local CurrentModule = script.Parent
18 | local Packages = CurrentModule.Parent.Parent
19 |
20 | local Writeable = require(CurrentModule.Parent.Writeable).Writeable
21 |
22 | local JestConfig = require(Packages.Dev.JestConfig)
23 |
24 | local ModuleMocker = require(Packages.JestMock).ModuleMocker
25 | local JestGlobals = require(Packages.Dev.JestGlobals)
26 | local expect = JestGlobals.expect
27 | local describe = JestGlobals.describe
28 | local it = JestGlobals.it
29 |
30 | local moduleMocker = ModuleMocker.new(JestConfig.projectDefaults)
31 | local mockWrite = moduleMocker:fn()
32 |
33 | describe("Writeable", function()
34 | it("takes a write function and returns a writeable object with the write method attached", function()
35 | local writeFn = function(data: string)
36 | mockWrite(data)
37 | end
38 | local writeable = Writeable.new({ write = writeFn })
39 | writeable:write("Hello, world!")
40 | expect(mockWrite).toBeCalledWith("Hello, world!")
41 | end)
42 | end)
43 |
--------------------------------------------------------------------------------
/src/jest-config/src/color.lua:
--------------------------------------------------------------------------------
1 | -- ROBLOX upstream: https://github.com/facebook/jest/blob/v28.0.0/packages/jest-config/src/color.ts
2 | --[[*
3 | * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
4 | *
5 | * This source code is licensed under the MIT license found in the
6 | * LICENSE file in the root directory of this source tree.
7 | ]]
8 |
9 | local Packages = script.Parent.Parent
10 | local LuauPolyfill = require(Packages.LuauPolyfill)
11 | type Array = LuauPolyfill.Array
12 | local exports = {}
13 | -- local createHash = require(Packages.crypto).createHash
14 | -- ROBLOX deviation START: inline as ChalkLua doesn't export this type
15 | -- local chalkModule = require(Packages.chalk)
16 | type ForegroundColor =
17 | "black"
18 | | "red"
19 | | "green"
20 | | "yellow"
21 | | "blue"
22 | | "magenta"
23 | | "cyan"
24 | | "white"
25 | | "gray"
26 | | "grey"
27 | | "blackBright"
28 | | "redBright"
29 | | "greenBright"
30 | | "yellowBright"
31 | | "blueBright"
32 | | "magentaBright"
33 | | "cyanBright"
34 | | "whiteBright"
35 | -- ROBLOX deviation END
36 | type Color = ForegroundColor
37 |
38 | local colors: Array = { "red", "green", "yellow", "blue", "magenta", "cyan", "white" }
39 |
40 | local function getDisplayNameColor(seed: string?): Color
41 | if seed == nil then
42 | return "white"
43 | end
44 |
45 | -- ROBLOX deviation START: randomize color using math.random
46 | -- local hash = createHash("sha256")
47 | -- hash:update(seed)
48 | -- local num = hash:digest():readUInt32LE(0)
49 | local num = math.random(#colors)
50 | return colors[num]
51 | -- ROBLOX deviation END
52 | end
53 | exports.getDisplayNameColor = getDisplayNameColor
54 |
55 | return exports
56 |
--------------------------------------------------------------------------------
/src/jest/src/__tests__/roblox.spec.lua:
--------------------------------------------------------------------------------
1 | --!strict
2 | --[[
3 | * Copyright (c) Roblox Corporation. All rights reserved.
4 | * Licensed under the MIT License (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://opensource.org/licenses/MIT
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | ]]
16 | -- ROBLOX NOTE: no upstream
17 |
18 | local CurrentModule = script.Parent.Parent
19 | local Packages = CurrentModule.Parent
20 |
21 | local JestGlobals = require(Packages.Dev.JestGlobals)
22 | local expect = JestGlobals.expect
23 | local describe = JestGlobals.describe
24 | local it = JestGlobals.it
25 |
26 | local jestModule = require(CurrentModule)
27 |
28 | describe("Jest", function()
29 | describe("re-exports JestCore", function()
30 | it("SearchSource", function()
31 | expect(jestModule.SearchSource).toBeDefined()
32 | end)
33 |
34 | it("TestWatcher", function()
35 | expect(jestModule.TestWatcher).toBeDefined()
36 | end)
37 |
38 | it("createTestScheduler", function()
39 | expect(jestModule.createTestScheduler).toBeDefined()
40 | end)
41 |
42 | -- ROBLOX NOTE: not ported
43 | it.skip("getVersion", function()
44 | -- expect(jestModule.getVersion).toBeDefined()
45 | end)
46 |
47 | it("runCLI", function()
48 | expect(jestModule.runCLI).toBeDefined()
49 | end)
50 | end)
51 | end)
52 |
--------------------------------------------------------------------------------
/src/jest-diff/src/__tests__/DiffStringsRaw.spec.lua:
--------------------------------------------------------------------------------
1 | -- ROBLOX upstream: https://github.com/facebook/jest/blob/v28.0.0/packages/jest-diff/src/__tests__/diffStringsRaw.test.ts
2 | -- /**
3 | -- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
4 | -- *
5 | -- * This source code is licensed under the MIT license found in the
6 | -- * LICENSE file in the root directory of this source tree.
7 | -- */
8 |
9 | local CurrentModule = script.Parent.Parent
10 | local Packages = CurrentModule.Parent
11 |
12 | local JestGlobals = require(Packages.Dev.JestGlobals)
13 | local expect = JestGlobals.expect
14 | local describe = JestGlobals.describe
15 | local it = JestGlobals.it
16 |
17 | local DIFF_DELETE = require(CurrentModule).DIFF_DELETE
18 | local DIFF_EQUAL = require(CurrentModule).DIFF_EQUAL
19 | local DIFF_INSERT = require(CurrentModule).DIFF_INSERT
20 | local Diff = require(CurrentModule).Diff
21 | local diffStringsRaw = require(CurrentModule).diffStringsRaw
22 |
23 | describe("diffStringsRaw", function()
24 | it("one-line with cleanup", function()
25 | local expected = {
26 | Diff.new(DIFF_EQUAL, "change "),
27 | Diff.new(DIFF_DELETE, "from"),
28 | Diff.new(DIFF_INSERT, "to"),
29 | }
30 | local received = diffStringsRaw("change from", "change to", true)
31 | expect(received).toEqual(expected)
32 | end)
33 |
34 | it("one-line without cleanup", function()
35 | local expected = {
36 | Diff.new(DIFF_EQUAL, "change "),
37 | Diff.new(DIFF_DELETE, "fr"),
38 | Diff.new(DIFF_INSERT, "t"),
39 | Diff.new(DIFF_EQUAL, "o"),
40 | Diff.new(DIFF_DELETE, "m"),
41 | }
42 | local received = diffStringsRaw("change from", "change to", false)
43 | expect(received).toEqual(expected)
44 | end)
45 | end)
46 |
--------------------------------------------------------------------------------
/src/jest-globals/src/index.lua:
--------------------------------------------------------------------------------
1 | -- ROBLOX upstream: https://github.com/facebook/jest/blob/v28.0.0/packages/jest-globals/src/index.ts
2 | -- /**
3 | -- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
4 | -- *
5 | -- * This source code is licensed under the MIT license found in the
6 | -- * LICENSE file in the root directory of this source tree.
7 | -- *
8 | -- */
9 |
10 | local Packages = script.Parent.Parent
11 | local LuauPolyfill = require(Packages.LuauPolyfill)
12 | local Error = LuauPolyfill.Error
13 |
14 | local JestEnvironment = require(Packages.JestEnvironment)
15 | type Jest = JestEnvironment.Jest
16 | local importedExpect = require(Packages.Expect)
17 |
18 | -- ROBLOX deviation START: additional imports
19 | local jestTypesModule = require(Packages.JestTypes)
20 | type TestFrameworkGlobals = jestTypesModule.Global_TestFrameworkGlobals
21 |
22 | local ExpectModule = require(Packages.Expect)
23 | type MatcherState = ExpectModule.MatcherState
24 | type ExpectExtended = ExpectModule.ExpectExtended
25 | -- ROBLOX deviation END
26 |
27 | type JestGlobals =
28 | {
29 | jest: Jest,
30 | expect: typeof(importedExpect),
31 | expectExtended: ExpectExtended<{ [string]: (...any) -> nil }>,
32 | }
33 | -- ROBLOX deviation START: using TestFrameworkGlobals instead of declaring variables one by one
34 | & TestFrameworkGlobals
35 | -- ROBLOX deviation END
36 |
37 | error(Error.new(
38 | -- ROBLOX deviation START: aligned message to make sense for jest-roblox
39 | "Do not import `JestGlobals` outside of the Jest 3 test environment.\n"
40 | .. "Tip: Jest 2 uses a different pattern - check your Jest version."
41 | -- ROBLOX deviation END
42 | ))
43 |
44 | return ({} :: any) :: JestGlobals
45 |
--------------------------------------------------------------------------------
/src/jest-util/src/__tests__/clearLine.roblox.spec.lua:
--------------------------------------------------------------------------------
1 | --[[
2 | * Copyright (c) Roblox Corporation. All rights reserved.
3 | * Licensed under the MIT License (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * https://opensource.org/licenses/MIT
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | ]]
15 |
16 | local CurrentModule = script.Parent
17 | local SrcModule = CurrentModule.Parent
18 | local Packages = SrcModule.Parent
19 |
20 | local JestGlobals = require(Packages.Dev.JestGlobals)
21 | local jest = JestGlobals.jest
22 | local expect = JestGlobals.expect
23 | local describe = JestGlobals.describe
24 | local it = JestGlobals.it
25 | local beforeEach = JestGlobals.beforeEach
26 |
27 | local clearLine = require(SrcModule.clearLine).default
28 |
29 | describe("clearLine", function()
30 | local writeMock
31 | local stream
32 | beforeEach(function()
33 | writeMock = jest.fn()
34 | stream = {
35 | write = writeMock,
36 | }
37 | end)
38 |
39 | it("should NOT clear line if stream is NOT TTY", function()
40 | clearLine(stream)
41 |
42 | expect(writeMock).never.toHaveBeenCalled()
43 | end)
44 |
45 | it("should clear line if stream is TTY", function()
46 | stream.isTTY = true
47 | clearLine(stream)
48 |
49 | expect(writeMock).toHaveBeenCalledTimes(1)
50 | expect(writeMock).toHaveBeenCalledWith(stream, "\x1b[999D\x1b[K")
51 | end)
52 | end)
53 |
--------------------------------------------------------------------------------