Skip to content

Commit

Permalink
refactor: generalize features fixture (#4820)
Browse files Browse the repository at this point in the history
We have a fixture which is used for testing generated features.
Historically we use it as vercel template fixture.

Here migrated it to react-router, removed vercel stuff from it and
renamed it to webstudio-features.
  • Loading branch information
TrySound authored Feb 4, 2025
1 parent 870de38 commit e8de913
Show file tree
Hide file tree
Showing 70 changed files with 210 additions and 248 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fixtures-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

# Testing fixtures for vercel template
- name: Test cli --help flag
working-directory: ./fixtures/webstudio-remix-vercel
working-directory: ./fixtures/webstudio-features
run: pnpm cli --help

- name: Testing cli link command
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
const results = [
await assertSize('./fixtures/ssg/dist/client', 352),
await assertSize('./fixtures/webstudio-remix-netlify-functions/build/client', 440),
await assertSize('./fixtures/webstudio-remix-vercel/build/client', 926),
await assertSize('./fixtures/webstudio-features/build/client', 926),
]
for (const result of results) {
if (result.passed) {
Expand Down
6 changes: 6 additions & 0 deletions fixtures/webstudio-features/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
/node_modules/

# React Router
/.react-router/
/build/
File renamed without changes.
3 changes: 3 additions & 0 deletions fixtures/webstudio-features/.template/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
force=true
# to support using NODE_OPTIONS for windows tests
shell-emulator=true
12 changes: 12 additions & 0 deletions fixtures/webstudio-features/.template/app/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* We use mjs extension as constants in this file is shared with the build script
* and we use `node --eval` to extract the constants.
*/
export const assetBaseUrl = "/assets/";

/**
* @type {import("@webstudio-is/image").ImageLoader}
*/
export const imageLoader = ({ src }) => {
return src;
};
12 changes: 12 additions & 0 deletions fixtures/webstudio-features/.template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"dependencies": {
"@webstudio-is/image": "workspace:*",
"@webstudio-is/react-sdk": "workspace:*",
"@webstudio-is/sdk": "workspace:*",
"@webstudio-is/sdk-components-animation": "workspace:*",
"@webstudio-is/sdk-components-react": "workspace:*",
"@webstudio-is/sdk-components-react-radix": "workspace:*",
"@webstudio-is/sdk-components-react-router": "workspace:*",
"webstudio": "workspace:*"
}
}
5 changes: 5 additions & 0 deletions fixtures/webstudio-features/.template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"customConditions": ["webstudio"]
}
}
9 changes: 9 additions & 0 deletions fixtures/webstudio-features/.template/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vite";
// @ts-ignore
import { reactRouter } from "@react-router/dev/vite";
// @ts-ignore
import { dedupeMeta } from "./proxy-emulator/dedupe-meta";

export default defineConfig({
plugins: [reactRouter(), dedupeMeta],
});
File renamed without changes.

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

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

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

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

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

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

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

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

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

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

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

12 changes: 12 additions & 0 deletions fixtures/webstudio-features/app/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* We use mjs extension as constants in this file is shared with the build script
* and we use `node --eval` to extract the constants.
*/
export const assetBaseUrl = "/assets/";

/**
* @type {import("@webstudio-is/image").ImageLoader}
*/
export const imageLoader = ({ src }) => {
return src;
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { AppLoadContext } from "@remix-run/server-runtime";
import { ResourceRequest } from "@webstudio-is/sdk";

declare module "@remix-run/server-runtime" {
declare module "react-router" {
interface AppLoadContext {
EXCLUDE_FROM_SEARCH: boolean;
getDefaultActionResource?: (options: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

import { Links, Meta, Outlet, useMatches } from "@remix-run/react";
import { Links, Meta, Outlet, useMatches } from "react-router";
// @todo think about how to make __generated__ typeable
// @ts-ignore
import { CustomCode } from "./__generated__/_index";
Expand Down
4 changes: 4 additions & 0 deletions fixtures/webstudio-features/app/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { type RouteConfig } from "@react-router/dev/routes";
import { flatRoutes } from "@react-router/fs-routes";

export default flatRoutes() satisfies RouteConfig;
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
type ServerRuntimeMetaFunction as MetaFunction,
type MetaFunction,
type LinksFunction,
type LinkDescriptor,
type ActionFunctionArgs,
type LoaderFunctionArgs,
type HeadersFunction,
json,
data,
redirect,
} from "@remix-run/server-runtime";
import { useLoaderData } from "@remix-run/react";
useLoaderData,
} from "react-router";
import {
isLocalResource,
loadResource,
Expand All @@ -20,7 +20,6 @@ import {
ReactSdkContext,
PageSettingsMeta,
PageSettingsTitle,
PageSettingsCanonicalLink,
} from "@webstudio-is/react-sdk/runtime";
import {
Page,
Expand Down Expand Up @@ -82,7 +81,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.status === 301 || pageMeta.status === 302
? pageMeta.status
: 302;
return redirect(pageMeta.redirect, status);
throw redirect(pageMeta.redirect, status);
}

// typecheck
Expand All @@ -92,7 +91,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
}

return json(
return data(
{
host,
url: url.href,
Expand Down Expand Up @@ -289,7 +288,6 @@ const Outlet = () => {
imageLoader={imageLoader}
/>
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
<PageSettingsCanonicalLink href={url} />
</ReactSdkContext.Provider>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
type ServerRuntimeMetaFunction as MetaFunction,
type MetaFunction,
type LinksFunction,
type LinkDescriptor,
type ActionFunctionArgs,
type LoaderFunctionArgs,
type HeadersFunction,
json,
data,
redirect,
} from "@remix-run/server-runtime";
import { useLoaderData } from "@remix-run/react";
useLoaderData,
} from "react-router";
import {
isLocalResource,
loadResource,
Expand All @@ -20,7 +20,6 @@ import {
ReactSdkContext,
PageSettingsMeta,
PageSettingsTitle,
PageSettingsCanonicalLink,
} from "@webstudio-is/react-sdk/runtime";
import {
Page,
Expand Down Expand Up @@ -82,7 +81,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.status === 301 || pageMeta.status === 302
? pageMeta.status
: 302;
return redirect(pageMeta.redirect, status);
throw redirect(pageMeta.redirect, status);
}

// typecheck
Expand All @@ -92,7 +91,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
}

return json(
return data(
{
host,
url: url.href,
Expand Down Expand Up @@ -289,7 +288,6 @@ const Outlet = () => {
imageLoader={imageLoader}
/>
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
<PageSettingsCanonicalLink href={url} />
</ReactSdkContext.Provider>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
type ServerRuntimeMetaFunction as MetaFunction,
type MetaFunction,
type LinksFunction,
type LinkDescriptor,
type ActionFunctionArgs,
type LoaderFunctionArgs,
type HeadersFunction,
json,
data,
redirect,
} from "@remix-run/server-runtime";
import { useLoaderData } from "@remix-run/react";
useLoaderData,
} from "react-router";
import {
isLocalResource,
loadResource,
Expand All @@ -20,7 +20,6 @@ import {
ReactSdkContext,
PageSettingsMeta,
PageSettingsTitle,
PageSettingsCanonicalLink,
} from "@webstudio-is/react-sdk/runtime";
import {
Page,
Expand Down Expand Up @@ -82,7 +81,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.status === 301 || pageMeta.status === 302
? pageMeta.status
: 302;
return redirect(pageMeta.redirect, status);
throw redirect(pageMeta.redirect, status);
}

// typecheck
Expand All @@ -92,7 +91,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
}

return json(
return data(
{
host,
url: url.href,
Expand Down Expand Up @@ -289,7 +288,6 @@ const Outlet = () => {
imageLoader={imageLoader}
/>
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
<PageSettingsCanonicalLink href={url} />
</ReactSdkContext.Provider>
);
};
Expand Down
Loading

0 comments on commit e8de913

Please sign in to comment.