Skip to content

Commit 381494c

Browse files
Fix resolve config path warning when multiple configs found (#8)
* Fix resolve config path warning when multiple configs found * add entry to changelog
1 parent 2b5dec4 commit 381494c

File tree

3 files changed

+46
-38
lines changed

3 files changed

+46
-38
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# Jest Lua Changelog
1+
# Jest Lua Changelog
22

33
## Unreleased Changes
44

5+
* fix warning when multiple configuration are found ([#8](https://github.com/jsdotlua/jest-lua/pull/8))
56
* fix error message when no tests are found ([#7](https://github.com/jsdotlua/jest-lua/pull/7))
67

78
## 3.6.1 (2024-01-16)

src/jest-config/src/constants.lua

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ local exports = {}
2121
-- ROBLOX deviation END
2222
local JEST_CONFIG_BASE_NAME = "jest.config"
2323
exports.JEST_CONFIG_BASE_NAME = JEST_CONFIG_BASE_NAME
24-
-- ROBLOX deviation START: not needed
24+
-- ROBLOX deviation START: not supported
2525
-- local JEST_CONFIG_EXT_CJS = ".cjs"
2626
-- exports.JEST_CONFIG_EXT_CJS = JEST_CONFIG_EXT_CJS
2727
-- local JEST_CONFIG_EXT_MJS = ".mjs"
@@ -30,16 +30,30 @@ exports.JEST_CONFIG_BASE_NAME = JEST_CONFIG_BASE_NAME
3030
-- exports.JEST_CONFIG_EXT_JS = JEST_CONFIG_EXT_JS
3131
-- local JEST_CONFIG_EXT_TS = ".ts"
3232
-- exports.JEST_CONFIG_EXT_TS = JEST_CONFIG_EXT_TS
33-
-- local JEST_CONFIG_EXT_JSON = ".json"
34-
-- exports.JEST_CONFIG_EXT_JSON = JEST_CONFIG_EXT_JSON
35-
-- local JEST_CONFIG_EXT_ORDER = Object.freeze({
36-
-- JEST_CONFIG_EXT_JS,
37-
-- JEST_CONFIG_EXT_TS,
38-
-- JEST_CONFIG_EXT_MJS,
39-
-- JEST_CONFIG_EXT_CJS,
40-
-- JEST_CONFIG_EXT_JSON,
41-
-- })
42-
-- exports.JEST_CONFIG_EXT_ORDER = JEST_CONFIG_EXT_ORDER
4333
-- ROBLOX deviation END
34+
local JEST_CONFIG_EXT_JSON = ".json"
35+
exports.JEST_CONFIG_EXT_JSON = JEST_CONFIG_EXT_JSON
36+
-- ROBLOX deviation START: support Lua and Luau extensions
37+
local JEST_CONFIG_EXT_LUA = ".lua"
38+
exports.JEST_CONFIG_EXT_LUA = JEST_CONFIG_EXT_LUA
39+
local JEST_CONFIG_EXT_LUAU = ".luau"
40+
exports.JEST_CONFIG_EXT_LUAU = JEST_CONFIG_EXT_LUAU
41+
-- ROBLOX deviation END
42+
local JEST_CONFIG_EXT_ORDER = {
43+
-- ROBLOX deviation START: support Lua and Luau extensions
44+
JEST_CONFIG_EXT_LUA,
45+
JEST_CONFIG_EXT_LUAU,
46+
-- ROBLOX deviation END
47+
-- ROBLOX deviation START: not supported
48+
-- JEST_CONFIG_EXT_JS,
49+
-- JEST_CONFIG_EXT_TS,
50+
-- JEST_CONFIG_EXT_MJS,
51+
-- JEST_CONFIG_EXT_CJS,
52+
-- ROBLOX deviation END
53+
-- ROBLOX deviation START: not supported (but for now)
54+
-- JEST_CONFIG_EXT_JSON,
55+
-- ROBLOX deviation END
56+
}
57+
exports.JEST_CONFIG_EXT_ORDER = JEST_CONFIG_EXT_ORDER
4458

4559
return exports

src/jest-config/src/resolveConfigPath.lua

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ local LuauPolyfill = require("@pkg/@jsdotlua/luau-polyfill")
1010
local Array = LuauPolyfill.Array
1111
local Error = LuauPolyfill.Error
1212
local String = LuauPolyfill.String
13-
local console = LuauPolyfill.console
1413
type Array<T> = LuauPolyfill.Array<T>
1514

1615
local exports = {}
@@ -23,15 +22,18 @@ local chalk = require("@pkg/@jsdotlua/chalk")
2322
-- local fs = require("@pkg/graceful-fs")
2423
-- local slash = require("@pkg/slash")
2524
-- ROBLOX deviation END
25+
local jestValidateModule = require("@pkg/@jsdotlua/jest-validate")
26+
local ValidationError = jestValidateModule.ValidationError
2627
local typesModule = require("@pkg/@jsdotlua/jest-types")
2728
type Config_Path = typesModule.Config_Path
2829
local constantsModule = require("./constants")
2930
local JEST_CONFIG_BASE_NAME = constantsModule.JEST_CONFIG_BASE_NAME
31+
local JEST_CONFIG_EXT_ORDER = constantsModule.JEST_CONFIG_EXT_ORDER
3032
-- ROBLOX deviation START: not needed
31-
-- local JEST_CONFIG_EXT_ORDER = constantsModule.JEST_CONFIG_EXT_ORDER
3233
-- local PACKAGE_JSON = constantsModule.PACKAGE_JSON
3334
-- ROBLOX deviation END
3435
local utilsModule = require("./utils")
36+
local BULLET = utilsModule.BULLET
3537
local DOCUMENTATION_NOTE = utilsModule.DOCUMENTATION_NOTE
3638

3739
-- ROBLOX deviation START: predefine functions
@@ -127,7 +129,7 @@ function resolveConfigPathByTraversing(
127129
end) :: Array<any>
128130
) :: Array<ModuleScript>
129131
if not skipMultipleConfigWarning and #configFiles > 1 then
130-
console.warn(makeMultipleConfigsWarning(configFiles))
132+
error(ValidationError.new(makeMultipleConfigsWarning(configFiles)))
131133
end
132134
if #configFiles > 0 then
133135
return configFiles[1]
@@ -175,26 +177,18 @@ function makeResolutionErrorMessage(
175177
cwd: Instance
176178
): string
177179
return "Could not find a config file based on provided values:\n"
178-
.. ('path: "%s"\n'):format(tostring(initialPath))
179-
.. ('cwd: "%s"\n'):format(tostring(cwd))
180+
.. `path: "{initialPath}"\n`
181+
.. `cwd: "{cwd}"\n`
180182
-- ROBLOX deviation START: align message to make more sense in Luau context
181183
.. "Config paths must be specified by either a direct path to a config script\n"
182184
.. "or a path to a directory. If directory is given, Jest will try to\n"
183185
-- ROBLOX deviation END
184-
.. ("traverse directory tree up, until it finds one of those files in exact order: %s."):format(
185-
Array.join(
186-
Array.map(
187-
-- ROBLOX deviation START: only support Lua config files
188-
-- JEST_CONFIG_EXT_ORDER
189-
{ ".lua" },
190-
-- ROBLOX deviation END
191-
function(ext)
192-
return ('"%s"'):format((getConfigFilename(ext)))
193-
end
194-
),
195-
" or "
196-
)
197-
)
186+
.. `traverse directory tree up, until it finds one of those files in exact order: {Array.join(
187+
Array.map(JEST_CONFIG_EXT_ORDER, function(ext)
188+
return `"{getConfigFilename(ext)}"`
189+
end),
190+
" or "
191+
)}.`
198192
end
199193

200194
local function extraIfPackageJson(configPath: Config_Path)
@@ -206,14 +200,14 @@ local function extraIfPackageJson(configPath: Config_Path)
206200
return ""
207201
end
208202

209-
function makeMultipleConfigsWarning(configPaths: Array<ModuleScript>)
210-
return chalk.yellow({
203+
function makeMultipleConfigsWarning(configPaths: Array<ModuleScript>): (string, string, string)
204+
return `{BULLET}{chalk.bold("Multiple configurations found")}`,
211205
Array.join(
212206
Array.concat(
213-
{},
214-
{ chalk.bold("\u{25cf} Multiple configurations found:") },
215207
Array.map(configPaths, function(configPath)
216-
return (" * %s%s"):format(tostring(extraIfPackageJson(configPath)), tostring(configPath))
208+
-- ROBLOX deviation START: replace slash command with GetFullName
209+
return ` * {extraIfPackageJson(configPath)}{configPath:GetFullName()}`
210+
-- ROBLOX deviation END
217211
end),
218212
{
219213
"",
@@ -223,8 +217,7 @@ function makeMultipleConfigsWarning(configPaths: Array<ModuleScript>)
223217
),
224218
"\n"
225219
),
226-
DOCUMENTATION_NOTE,
227-
})
220+
DOCUMENTATION_NOTE
228221
end
229222

230223
return exports

0 commit comments

Comments
 (0)