@isentinel/jest-roblox 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,9 @@ import { createRequire } from "node:module";
2
2
  import { type } from "arktype";
3
3
  import assert from "node:assert";
4
4
  import * as fs$1 from "node:fs";
5
- import { existsSync } from "node:fs";
5
+ import { existsSync, readFileSync } from "node:fs";
6
6
  import * as path$1 from "node:path";
7
- import path from "node:path";
7
+ import path, { dirname, join, relative } from "node:path";
8
8
  import process from "node:process";
9
9
  import color from "tinyrainbow";
10
10
  import { WebSocketServer } from "ws";
@@ -14,9 +14,9 @@ import * as crypto from "node:crypto";
14
14
  import { randomUUID } from "node:crypto";
15
15
  import buffer from "node:buffer";
16
16
  import { defuFn } from "defu";
17
+ import { execFileSync } from "node:child_process";
17
18
  import { TraceMap, originalPositionFor, sourceContentFor } from "@jridgewell/trace-mapping";
18
19
  import { getTsconfig } from "get-tsconfig";
19
- import { execFileSync } from "node:child_process";
20
20
  import hljs from "highlight.js/lib/core";
21
21
  import typescript from "highlight.js/lib/languages/typescript";
22
22
  import { parseJSONC } from "confbox";
@@ -243,6 +243,7 @@ const DEFAULT_CONFIG = {
243
243
  "**/rbxts_include/**"
244
244
  ],
245
245
  coverageReporters: ["text", "lcov"],
246
+ passWithNoTests: false,
246
247
  placeFile: "./game.rbxl",
247
248
  pollInterval: 500,
248
249
  port: 3001,
@@ -361,6 +362,7 @@ const configSchema = type({
361
362
  "maxWorkers?": type("number").or(type("string")),
362
363
  "noStackTrace?": "boolean",
363
364
  "outputFile?": "string",
365
+ "passWithNoTests?": "boolean",
364
366
  "placeFile?": "string",
365
367
  "pollInterval?": "number",
366
368
  "port?": "number",
@@ -780,6 +782,7 @@ async function loadConfig$1(configPath, cwd = process.cwd()) {
780
782
  cwd,
781
783
  dotenv: false,
782
784
  globalRc: false,
785
+ import: isSea() ? seaImport : void 0,
783
786
  merger,
784
787
  omit$Keys: true,
785
788
  packageJson: false,
@@ -799,6 +802,16 @@ async function loadConfig$1(configPath, cwd = process.cwd()) {
799
802
  config.rootDir ??= cwd;
800
803
  return resolveConfig(config);
801
804
  }
805
+ function isSea() {
806
+ return process.env["JEST_ROBLOX_SEA"] === "true";
807
+ }
808
+ async function seaImport(id) {
809
+ if (id.endsWith(".json")) {
810
+ const content = readFileSync(id, "utf-8");
811
+ return JSON.parse(content);
812
+ }
813
+ return import(id);
814
+ }
802
815
  function merger(...sources) {
803
816
  return defuFn(...sources.filter(Boolean));
804
817
  }
@@ -811,6 +824,52 @@ function resolveFunctionValues(config) {
811
824
  return resolved;
812
825
  }
813
826
  //#endregion
827
+ //#region src/utils/rojo-tree.ts
828
+ function resolveNestedProjects(tree, rootDirectory) {
829
+ return resolveTree(tree, rootDirectory, rootDirectory, /* @__PURE__ */ new Set());
830
+ }
831
+ function collectPaths(node, result) {
832
+ for (const [key, value] of Object.entries(node)) if (key === "$path" && typeof value === "string") result.push(value.replaceAll("\\", "/"));
833
+ else if (typeof value === "object" && !Array.isArray(value) && !key.startsWith("$")) collectPaths(value, result);
834
+ }
835
+ function inlineNestedProject(projectPath, currentDirectory, originalRoot, visited) {
836
+ const chain = new Set(visited);
837
+ chain.add(projectPath);
838
+ let content;
839
+ try {
840
+ content = readFileSync(projectPath, "utf-8");
841
+ } catch (err) {
842
+ const relativePath = relative(currentDirectory, projectPath);
843
+ throw new Error(`Could not read nested Rojo project: ${relativePath}`, { cause: err });
844
+ }
845
+ return resolveTree(JSON.parse(content).tree, dirname(projectPath), originalRoot, chain);
846
+ }
847
+ function resolveRootRelativePath(currentDirectory, value, originalRoot) {
848
+ return relative(originalRoot, join(currentDirectory, value)).replaceAll("\\", "/");
849
+ }
850
+ function resolveTree(node, currentDirectory, originalRoot, visited) {
851
+ const resolved = {};
852
+ for (const [key, value] of Object.entries(node)) {
853
+ if (key === "$path" && typeof value === "string" && value.endsWith(".project.json")) {
854
+ const projectPath = join(currentDirectory, value);
855
+ if (visited.has(projectPath)) throw new Error(`Circular project reference: ${value}`);
856
+ const innerTree = inlineNestedProject(projectPath, currentDirectory, originalRoot, visited);
857
+ for (const [innerKey, innerValue] of Object.entries(innerTree)) resolved[innerKey] = innerValue;
858
+ continue;
859
+ }
860
+ if (key === "$path" && typeof value === "string") {
861
+ resolved[key] = resolveRootRelativePath(currentDirectory, value, originalRoot);
862
+ continue;
863
+ }
864
+ if (key.startsWith("$") || typeof value !== "object" || Array.isArray(value)) {
865
+ resolved[key] = value;
866
+ continue;
867
+ }
868
+ resolved[key] = resolveTree(value, currentDirectory, originalRoot, visited);
869
+ }
870
+ return resolved;
871
+ }
872
+ //#endregion
814
873
  //#region src/types/rojo.ts
815
874
  const rojoProjectSchema = type({
816
875
  "name": "string",
@@ -2476,9 +2535,13 @@ function buildSourceMapper(config, tsconfigMappings) {
2476
2535
  try {
2477
2536
  const rojoResult = rojoProjectSchema(JSON.parse(fs$1.readFileSync(rojoProjectPath, "utf-8")));
2478
2537
  if (rojoResult instanceof type.errors) return;
2538
+ const resolvedTree = resolveNestedProjects(rojoResult.tree, path$1.dirname(rojoProjectPath));
2479
2539
  return createSourceMapper({
2480
2540
  mappings: tsconfigMappings,
2481
- rojoProject: rojoResult
2541
+ rojoProject: {
2542
+ ...rojoResult,
2543
+ tree: resolvedTree
2544
+ }
2482
2545
  });
2483
2546
  } catch {
2484
2547
  return;
@@ -2556,9 +2619,13 @@ function writeSnapshots(snapshotWrites, config, tsconfigMappings) {
2556
2619
  process.stderr.write("Warning: Cannot write snapshots - invalid rojo project\n");
2557
2620
  return;
2558
2621
  }
2622
+ const resolvedTree = resolveNestedProjects(rojoResult.tree, path$1.dirname(rojoProjectPath));
2559
2623
  const resolver = createSnapshotPathResolver({
2560
2624
  mappings: tsconfigMappings,
2561
- rojoProject: rojoResult
2625
+ rojoProject: {
2626
+ ...rojoResult,
2627
+ tree: resolvedTree
2628
+ }
2562
2629
  });
2563
2630
  let written = 0;
2564
2631
  for (const [virtualPath, content] of Object.entries(snapshotWrites)) {
@@ -3016,4 +3083,4 @@ function writeGameOutput(filePath, entries) {
3016
3083
  fs$1.writeFileSync(absolutePath, JSON.stringify(entries, null, 2));
3017
3084
  }
3018
3085
  //#endregion
3019
- export { generateTestScript as A, resolveConfig as C, createOpenCloudBackend as D, OpenCloudBackend as E, defineProject as F, isValidBackend as I, LuauScriptError as L, ROOT_ONLY_KEYS as M, VALID_BACKENDS as N, hashBuffer as O, defineConfig as P, extractJsonFromOutput as R, loadConfig$1 as S, createStudioBackend as T, formatResult as _, formatAnnotations as a, formatBanner as b, execute as c, findFormatterOptions as d, formatJson as f, formatMultiProjectResult as g, formatFailure as h, runTypecheck as i, DEFAULT_CONFIG as j, buildJestArgv as k, formatExecuteOutput as l, formatCompactMultiProject as m, parseGameOutput as n, formatJobSummary as o, writeJsonFile as p, writeGameOutput as r, resolveGitHubActionsOptions as s, formatGameOutputNotice as t, loadCoverageManifest as u, formatTestSummary as v, StudioBackend as w, rojoProjectSchema as x, formatTypecheckSummary as y, parseJestOutput as z };
3086
+ export { hashBuffer as A, extractJsonFromOutput as B, resolveNestedProjects as C, createStudioBackend as D, StudioBackend as E, VALID_BACKENDS as F, defineConfig as I, defineProject as L, generateTestScript as M, DEFAULT_CONFIG as N, OpenCloudBackend as O, ROOT_ONLY_KEYS as P, isValidBackend as R, collectPaths as S, resolveConfig as T, parseJestOutput as V, formatResult as _, formatAnnotations as a, formatBanner as b, execute as c, findFormatterOptions as d, formatJson as f, formatMultiProjectResult as g, formatFailure as h, runTypecheck as i, buildJestArgv as j, createOpenCloudBackend as k, formatExecuteOutput as l, formatCompactMultiProject as m, parseGameOutput as n, formatJobSummary as o, writeJsonFile as p, writeGameOutput as r, resolveGitHubActionsOptions as s, formatGameOutputNotice as t, loadCoverageManifest as u, formatTestSummary as v, loadConfig$1 as w, rojoProjectSchema as x, formatTypecheckSummary as y, LuauScriptError as z };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as defineConfig, C as FormatterEntry, D as ROOT_ONLY_KEYS, E as ProjectTestConfig, M as Argv, O as ResolvedConfig, S as DisplayName, T as ProjectEntry, _ as ResolvedProjectConfig, a as formatExecuteOutput, b as ConfigInput, c as Backend, d as extractJsonFromOutput, f as parseJestOutput, g as TestStatus, h as TestFileResult, i as execute, j as defineProject, k as SnapshotFormatOptions, l as BackendOptions, m as TestCaseResult, n as ExecuteResult, o as TimingResult, p as JestResult, r as FormatOutputOptions, s as SourceMapper, t as ExecuteOptions, u as BackendResult, v as CliOptions, w as InlineProjectConfig, x as DEFAULT_CONFIG, y as Config } from "./executor-DqZE3wME.mjs";
1
+ import { A as defineConfig, C as FormatterEntry, D as ROOT_ONLY_KEYS, E as ProjectTestConfig, M as Argv, O as ResolvedConfig, S as DisplayName, T as ProjectEntry, _ as ResolvedProjectConfig, a as formatExecuteOutput, b as ConfigInput, c as Backend, d as extractJsonFromOutput, f as parseJestOutput, g as TestStatus, h as TestFileResult, i as execute, j as defineProject, k as SnapshotFormatOptions, l as BackendOptions, m as TestCaseResult, n as ExecuteResult, o as TimingResult, p as JestResult, r as FormatOutputOptions, s as SourceMapper, t as ExecuteOptions, u as BackendResult, v as CliOptions, w as InlineProjectConfig, x as DEFAULT_CONFIG, y as Config } from "./executor-D6BzDfQ_.mjs";
2
2
  import { WebSocket, WebSocketServer } from "ws";
3
3
  import buffer from "node:buffer";
4
4
 
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { A as generateTestScript, C as resolveConfig, D as createOpenCloudBackend, E as OpenCloudBackend, F as defineProject, M as ROOT_ONLY_KEYS, P as defineConfig, R as extractJsonFromOutput, S as loadConfig, T as createStudioBackend, _ as formatResult, a as formatAnnotations, c as execute, f as formatJson, h as formatFailure, i as runTypecheck, j as DEFAULT_CONFIG, k as buildJestArgv, l as formatExecuteOutput, n as parseGameOutput, o as formatJobSummary, p as writeJsonFile, r as writeGameOutput, t as formatGameOutputNotice, v as formatTestSummary, w as StudioBackend, z as parseJestOutput } from "./game-output-C0_-YIAY.mjs";
1
+ import { B as extractJsonFromOutput, D as createStudioBackend, E as StudioBackend, I as defineConfig, L as defineProject, M as generateTestScript, N as DEFAULT_CONFIG, O as OpenCloudBackend, P as ROOT_ONLY_KEYS, T as resolveConfig, V as parseJestOutput, _ as formatResult, a as formatAnnotations, c as execute, f as formatJson, h as formatFailure, i as runTypecheck, j as buildJestArgv, k as createOpenCloudBackend, l as formatExecuteOutput, n as parseGameOutput, o as formatJobSummary, p as writeJsonFile, r as writeGameOutput, t as formatGameOutputNotice, v as formatTestSummary, w as loadConfig } from "./game-output-BU-9pJ93.mjs";
2
2
  export { DEFAULT_CONFIG, OpenCloudBackend, ROOT_ONLY_KEYS, StudioBackend, buildJestArgv, createOpenCloudBackend, createStudioBackend, defineConfig, defineProject, execute, extractJsonFromOutput, formatAnnotations, formatExecuteOutput, formatFailure, formatGameOutputNotice, formatJobSummary, formatJson, formatResult, formatTestSummary, generateTestScript, loadConfig, parseGameOutput, parseJestOutput, resolveConfig, runTypecheck, writeGameOutput, writeJsonFile };
Binary file