Skip to content

Commit

Permalink
refactor: split jsx testing utils into template package (#4604)
Browse files Browse the repository at this point in the history
We can start using testing utilities for components meta. It will
drastically simplify maintenance of components, already works pretty
well for tests.

Here just replaced @webstudio-is/sdk/testing with
@webstudio-is/template.
  • Loading branch information
TrySound authored Dec 17, 2024
1 parent c768f11 commit 7f7a8fd
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apps/builder/app/builder/shared/commands.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test } from "vitest";
import * as baseMetas from "@webstudio-is/sdk-components-react/metas";
import { createDefaultPages } from "@webstudio-is/project-build";
import { renderJsx, $ } from "@webstudio-is/template";
import {
$instances,
$pages,
Expand All @@ -9,7 +10,6 @@ import {
import { registerContainers } from "~/shared/sync";
import { $awareness, selectInstance } from "~/shared/awareness";
import { deleteSelectedInstance, unwrap, wrapIn } from "./commands";
import { renderJsx, $ } from "@webstudio-is/sdk/testing";

registerContainers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "~/shared/nano-states";
import { TextEditor } from "./text-editor";
import { emitCommand, subscribeCommands } from "~/canvas/shared/commands";
import { $, renderJsx } from "@webstudio-is/sdk/testing";
import { $, renderJsx } from "@webstudio-is/template";
import { $awareness } from "~/shared/awareness";

export default {
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/app/shared/copy-paste/asset-upload.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "vitest";
import { $, renderJsx, AssetValue } from "@webstudio-is/sdk/testing";
import { $, renderJsx, AssetValue } from "@webstudio-is/template";
import { denormalizeSrcProps } from "./asset-upload";
import type { StyleDecl, WebstudioFragment } from "@webstudio-is/sdk";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
type WebstudioFragment,
type Instance,
} from "@webstudio-is/sdk";
import { $, renderJsx } from "@webstudio-is/sdk/testing";
import { $, renderJsx } from "@webstudio-is/template";
import * as defaultMetas from "@webstudio-is/sdk-components-react-remix/metas";
import { __testing__ } from "./plugin-webflow";
import {
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/app/shared/instance-utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@webstudio-is/react-sdk";
import type { Project } from "@webstudio-is/project";
import { createDefaultPages } from "@webstudio-is/project-build";
import { $, ws, renderJsx, ExpressionValue } from "@webstudio-is/sdk/testing";
import { $, ws, renderJsx, ExpressionValue } from "@webstudio-is/template";
import { parseCss } from "@webstudio-is/css-data";
import { coreMetas } from "@webstudio-is/react-sdk";
import * as defaultMetas from "@webstudio-is/sdk-components-react/metas";
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/app/shared/matcher.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test, vi } from "vitest";
import type { JSX } from "react";
import { renderJsx, $, ExpressionValue } from "@webstudio-is/sdk/testing";
import { renderJsx, $, ExpressionValue } from "@webstudio-is/template";
import { coreMetas } from "@webstudio-is/react-sdk";
import * as baseMetas from "@webstudio-is/sdk-components-react/metas";
import type { WsComponentMeta } from "@webstudio-is/react-sdk";
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/app/shared/style-object-model.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type StyleDecl,
getStyleDeclKey,
} from "@webstudio-is/sdk";
import { $, renderJsx } from "@webstudio-is/sdk/testing";
import { $, renderJsx } from "@webstudio-is/template";
import { parseCss } from "@webstudio-is/css-data";
import type { StyleValue } from "@webstudio-is/css-engine";
import {
Expand Down
1 change: 1 addition & 0 deletions apps/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@webstudio-is/sdk-components-react": "workspace:*",
"@webstudio-is/sdk-components-react-radix": "workspace:*",
"@webstudio-is/sdk-components-react-remix": "workspace:*",
"@webstudio-is/template": "workspace:*",
"@webstudio-is/trpc-interface": "workspace:*",
"arrgv": "^1.0.2",
"bcp-47": "^2.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@webstudio-is/icons": "workspace:^",
"@webstudio-is/image": "workspace:*",
"@webstudio-is/sdk": "workspace:*",
"@webstudio-is/template": "workspace:*",
"change-case": "^5.4.4",
"html-tags": "^4.0.0",
"nanoid": "^5.0.8"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-sdk/src/component-generator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
createProxy,
renderJsx,
ws,
} from "@webstudio-is/sdk/testing";
} from "@webstudio-is/template";
import {
generateJsxChildren,
generateWebstudioComponent,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-sdk/src/css/css.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, test } from "vitest";
import type { Breakpoint } from "@webstudio-is/sdk";
import { $, renderJsx } from "@webstudio-is/template";
import { generateCss, type CssConfig } from "./css";
import { descendantComponent, rootComponent } from "../core-components";
import { $, renderJsx } from "@webstudio-is/sdk/testing";

const toMap = <T extends { id: string }>(list: T[]) =>
new Map(list.map((item) => [item.id, item] as const));
Expand Down
4 changes: 1 addition & 3 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
"webstudio": "./src/__generated__/normalize.css.ts",
"types": "./lib/types/__generated__/normalize.css.d.ts",
"import": "./lib/__generated__/normalize.css.js"
},
"./testing": {
"webstudio": "./src/testing.ts"
}
},
"files": [
Expand All @@ -49,6 +46,7 @@
},
"devDependencies": {
"@webstudio-is/css-data": "workspace:*",
"@webstudio-is/template": "workspace:*",
"@webstudio-is/tsconfig": "workspace:*",
"html-tags": "^4.0.0",
"strip-indent": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/instances-utils.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "vitest";
import { $, renderJsx } from "./jsx";
import { $, renderJsx } from "@webstudio-is/template";
import {
findTreeInstanceIds,
findTreeInstanceIdsExcludingSlotDescendants,
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/resources-generator.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "vitest";
import { renderJsx, $ } from "./jsx";
import { renderJsx, $ } from "@webstudio-is/template";
import type { Page } from "./schema/pages";
import { createScope } from "./scope";
import {
Expand Down
26 changes: 26 additions & 0 deletions packages/template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@webstudio-is/template",
"version": "0.0.0-webstudio-version",
"description": "Webstudio templates based on React",
"author": "Webstudio <github@webstudio.is>",
"homepage": "https://webstudio.is",
"license": "AGPL-3.0-or-later",
"private": true,
"type": "module",
"exports": {
"webstudio": "./src/index.ts"
},
"sideEffects": false,
"scripts": {
"typecheck": "tsc",
"test": "vitest run"
},
"dependencies": {
"@webstudio-is/sdk": "workspace:*",
"react": "18.3.0-canary-14898b6a9-20240318"
},
"devDependencies": {
"@webstudio-is/tsconfig": "workspace:*",
"vitest": "^2.1.8"
}
}
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions packages/sdk/src/jsx.ts → packages/template/src/jsx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { JSX, ReactNode } from "react";
import type { Instances } from "./schema/instances";
import type { Props } from "./schema/props";
import type { Instances, Props } from "@webstudio-is/sdk";

export class ExpressionValue {
value;
Expand Down
3 changes: 3 additions & 0 deletions packages/template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@webstudio-is/tsconfig/base.json"
}
25 changes: 25 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7f7a8fd

Please sign in to comment.