@saltcorn/builder 1.6.1-beta.0 → 1.7.0-alpha.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/builder",
3
- "version": "1.6.1-beta.0",
3
+ "version": "1.7.0-alpha.0",
4
4
  "description": "Drag and drop view builder for Saltcorn, open-source no-code platform",
5
5
  "main": "index.js",
6
6
  "homepage": "https://saltcorn.com",
@@ -8,7 +8,7 @@
8
8
  "build": "webpack --mode production",
9
9
  "builddev": "webpack --mode development",
10
10
  "watch": "webpack --watch --mode development",
11
- "test": "jest tests --runInBand",
11
+ "test": "NODE_ENV=test node --require ./setup-node-runner.js --test",
12
12
  "tsc": "echo \"Error: no TypeScript support yet\"",
13
13
  "clean": "echo \"Error: no TypeScript support yet\""
14
14
  },
@@ -30,16 +30,13 @@
30
30
  "@fortawesome/free-solid-svg-icons": "5.15.2",
31
31
  "@fortawesome/react-fontawesome": "0.1.14",
32
32
  "@monaco-editor/react": "4.7.0",
33
- "@saltcorn/common-code": "1.6.1-beta.0",
33
+ "@saltcorn/common-code": "1.7.0-alpha.0",
34
34
  "@tippyjs/react": "4.2.6",
35
- "babel-jest": "^29.7.0",
36
35
  "babel-loader": "9.2.1",
37
36
  "ckeditor4-react": "2.0.0",
38
37
  "classnames": "2.3.2",
39
38
  "glob-parent": "^5.1.2",
40
39
  "immer": "9.0.21",
41
- "jest": "29.7.0",
42
- "jest-environment-jsdom": "29.7.0",
43
40
  "jsdom": "26.0.0",
44
41
  "lodash": "4.17.21",
45
42
  "monaco-editor": "^0.52.2",
@@ -49,7 +46,7 @@
49
46
  "react-contenteditable": "3.3.7",
50
47
  "react-dom": "^18.2.0",
51
48
  "react-select": "5.8.0",
52
- "react-test-renderer": "^18.2.0",
49
+ "react-test-renderer": "18.2.0",
53
50
  "react-transition-group": "4.4.5",
54
51
  "webpack": "^5.105.1",
55
52
  "webpack-cli": "6.0.1"
@@ -67,8 +64,5 @@
67
64
  "undici": "7.12.0",
68
65
  "parse5": "7.2.1",
69
66
  "parse5-htmlparser2-tree-adapter": "7.0.0"
70
- },
71
- "jest": {
72
- "testEnvironment": "jsdom"
73
67
  }
74
68
  }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Preload for node's built-in test runner (`node --test`).
3
+ *
4
+ * The builder's test renders React components, which jest supported through
5
+ * two facilities node:test does not provide out of the box. This preload
6
+ * recreates both:
7
+ *
8
+ * 1. Transpilation of JSX + ESM. We install a require hook backed by
9
+ * @babel/core (already present via babel-loader) that applies the same
10
+ * presets as babel.config.js, but only to this package's own source -
11
+ * dependencies under node_modules ship runnable CommonJS and are loaded
12
+ * untouched.
13
+ *
14
+ * 2. A browser-like global environment. react-test-renderer itself needs no
15
+ * DOM, but the rendered components pull in libraries (e.g.
16
+ * @monaco-editor/react) that touch window/document at import time, so we
17
+ * install a jsdom global environment - the equivalent of jest's "jsdom"
18
+ * testEnvironment.
19
+ *
20
+ * The test runner forwards --require preloads to the per-file child processes,
21
+ * so this runs before each test file is loaded.
22
+ */
23
+ const path = require("path");
24
+ const Module = require("module");
25
+ const babel = require("@babel/core");
26
+
27
+ // --- 1. babel require hook -------------------------------------------------
28
+ const pkgRoot = __dirname;
29
+ const nodeModules = `${path.sep}node_modules${path.sep}`;
30
+ const defaultJsLoader = Module._extensions[".js"];
31
+
32
+ Module._extensions[".js"] = function (module, filename) {
33
+ // only this package's own sources need transpiling; deps are runnable CJS
34
+ if (!filename.startsWith(pkgRoot) || filename.includes(nodeModules)) {
35
+ return defaultJsLoader(module, filename);
36
+ }
37
+ const { code } = babel.transformFileSync(filename, {
38
+ configFile: false,
39
+ babelrc: false,
40
+ sourceMaps: "inline",
41
+ presets: [
42
+ ["@babel/preset-env", { targets: { node: "current" } }],
43
+ ["@babel/preset-react", { runtime: "automatic" }],
44
+ ],
45
+ });
46
+ module._compile(code, filename);
47
+ };
48
+
49
+ // --- 2. jsdom global environment -------------------------------------------
50
+ const { JSDOM } = require("jsdom");
51
+ const { window } = new JSDOM("<!doctype html><html><body></body></html>", {
52
+ url: "http://localhost/",
53
+ pretendToBeVisual: true,
54
+ });
55
+
56
+ global.window = window;
57
+ global.self = window;
58
+ global.document = window.document;
59
+ global.navigator = window.navigator;
60
+
61
+ // expose the remaining browser globals libraries expect (HTMLElement, Node,
62
+ // getComputedStyle, requestAnimationFrame, ...) without clobbering node's own
63
+ for (const key of Object.getOwnPropertyNames(window)) {
64
+ if (key in global) continue;
65
+ try {
66
+ global[key] = window[key];
67
+ } catch {
68
+ // some window properties throw on access; skip them
69
+ }
70
+ }
@@ -161,6 +161,15 @@ const fields = [
161
161
  input_type: "select",
162
162
  options: ["Default", "Left", "Center", "Right"],
163
163
  },
164
+ {
165
+ name: "cell_css_formula",
166
+ label: "Cell CSS formula",
167
+ sublabel:
168
+ "Bootstrap class or inline style expression based on row value. Ex: amount < 0 ? 'text-danger fw-bold' : null",
169
+ class: "validate-expression",
170
+ type: "String",
171
+ required: false,
172
+ },
164
173
  ];
165
174
  ListColumn.craft = {
166
175
  displayName: "ListColumn",
@@ -1,3 +1,10 @@
1
+ import {
2
+ describe,
3
+ it,
4
+ expect,
5
+ beforeEach,
6
+ jest,
7
+ } from "@saltcorn/db-common/test_expect";
1
8
  import React from "react";
2
9
  import renderer from "react-test-renderer";
3
10
 
@@ -19,13 +26,16 @@ import {
19
26
  expectedFive,
20
27
  expectedSix,
21
28
  } from "@saltcorn/common-code/tests/expected_relations";
22
- import { ViewSettings } from "../src/components/elements/View";
23
- import { ViewLinkSettings } from "../src/components/elements/ViewLink";
24
29
 
25
30
  jest.mock("@craftjs/core", () => ({
26
31
  useNode: jest.fn(),
27
32
  }));
28
33
 
34
+ // required after jest.mock so they pick up the mocked @craftjs/core (jest
35
+ // hoists mock calls above imports; node:test does not)
36
+ const { ViewSettings } = require("../src/components/elements/View");
37
+ const { ViewLinkSettings } = require("../src/components/elements/ViewLink");
38
+
29
39
  const doTest = (
30
40
  tables,
31
41
  views,