Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: SDKs: custom components #1953

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ jobs:
- name: Build E2E tests
run: yarn e2e:build:specs

- name: Build E2E custom components
run: yarn workspace @builder.io/sdks-tests-custom-components build

- name: Build E2E apps
run: yarn e2e:build:${{ matrix.sdk }}

Expand Down Expand Up @@ -228,6 +231,9 @@ jobs:
- name: Build E2E tests
run: yarn workspace @builder.io/sdks-e2e-tests build

- name: Build E2E custom components
run: yarn workspace @builder.io/sdks-tests-custom-components build

- name: Build E2E apps
run: yarn workspace @builder.io/react-tests build

Expand Down
35 changes: 35 additions & 0 deletions examples/remix-minimal-starter/app/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Builder } from '@builder.io/react';

export function Button(props) {
return (
<>
{props.link ? (
<>
<a
role="button"
className="a-7ce05d40"
href={props.link}
target={props.openLinkInNewTab ? '_blank' : undefined}
{...props.attributes}
>
{props.text}
</a>
</>
) : (
<button className="button-7ce05d40" {...props.attributes}>
{props.text}
</button>
)}
<style>{`.button-7ce05d40 {
all: unset;
color: cyan;
}.a-7ce05d40 {
color: cyan;
}`}</style>
</>
);
}

Builder.registerComponent(Button, {
name: 'Core:Button',
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { Builder } from '@builder.io/sdk';
import { Links, Meta, Scripts, useCatch, useLoaderData } from '@remix-run/react';
import type { LoaderFunction } from '@remix-run/node';
import builderConfig from '../../builderConfig.json';
import { Button } from '../components/Button/Button';

builder.init(builderConfig.apiKey);
Builder.registerComponent(Button, {
name: 'Core:Button',
});

export const loader: LoaderFunction = async ({ params }) => {
const page = await builder
.get('page', {
userAttributes: {
urlPath: `/${params['*']}`,
urlPath: `/${params.slug || ''}`,
},
})
.toPromise();
Expand Down
28 changes: 0 additions & 28 deletions examples/remix-minimal-starter/app/routes/index.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions examples/remix-minimal-starter/builderConfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"apiKey": "cb3255f61d654ba7849be3b13e1c4151"
}
"apiKey": "f1a790f8c3204b3b8c5c1795aeac4660"
}
1 change: 1 addition & 0 deletions packages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"workspaces": [
"sdks-tests",
"sdks-tests-custom-components",
"sdks",
"react",
"react-tests",
Expand Down
1 change: 1 addition & 0 deletions packages/react-tests/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"@builder.io/react": "workspace:*",
"@builder.io/sdks-e2e-tests": "workspace:*",
"@builder.io/sdks-tests-custom-components": "workspace:*",
"next": "^12.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
10 changes: 8 additions & 2 deletions packages/react-tests/nextjs/pages/[[...index]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import type {
GetStaticPropsContext,
InferGetStaticPropsType,
} from 'next';
import { BuilderComponent, builder } from '@builder.io/react';
import { BuilderComponent, builder, Builder } from '@builder.io/react';
import DefaultErrorPage from 'next/error';
import Head from 'next/head';
import { useEffect } from 'react';
import { getCustomComponents } from '@builder.io/sdks-tests-custom-components/output/react/src/index';

builder.init(getAPIKey());

type StaticProps = { index: string[] };

export async function getStaticProps(x: GetStaticPropsContext<StaticProps>) {
return { props: getProps(x.params.index ? `/${x.params.index.join('/')}` : '/') };
const path = x.params.index ? `/${x.params.index.join('/')}` : '/';
return { props: { ...getProps(path), customComponents: getCustomComponents(path) } };
}

export function getStaticPaths(): GetStaticPathsResult<StaticProps> {
Expand All @@ -40,6 +42,10 @@ builder.canTrack = false;
export default function Page(props: PageProps & { apiVersion: any }) {
const router = useRouter();

props.customComponents.forEach(({ component, ...info }) => {
Builder.registerComponent(component, info);
});

if (props?.apiVersion) {
builder.apiVersion = props?.apiVersion;
}
Expand Down
17 changes: 14 additions & 3 deletions packages/react-tests/react-remix/app/routes/($slug).tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Links, Meta, Scripts, useCatch, useLoaderData, useParams } from '@remix-run/react';
import type { LoaderFunction } from '@remix-run/node';
import { BuilderComponent, builder } from '@builder.io/react';
import { BuilderComponent, builder, Builder } from '@builder.io/react';
import { getAPIKey, getProps } from '@builder.io/sdks-e2e-tests';
import { useEffect } from 'react';
import { getCustomComponents } from '@builder.io/sdks-tests-custom-components/output/react/src/index';

builder.init(getAPIKey());

export const loader: LoaderFunction = async ({ params }) => getProps(`/${params.slug || ''}`);
export const loader: LoaderFunction = async ({ params }) => {
const path = `/${params.slug || ''}`;
const props = { ...getProps(path), customComponents: getCustomComponents(path) };
return { props: props };
};

export function CatchBoundary() {
const caught = useCatch();
Expand Down Expand Up @@ -34,9 +39,15 @@ export function CatchBoundary() {
}

export default function Page() {
const props = useLoaderData<ReturnType<typeof getProps>>();
const props = useLoaderData<
ReturnType<typeof getProps> & { customComponents: ReturnType<typeof getCustomComponents> }
>();
const params = useParams();

props.customComponents.forEach(({ component, ...info }) => {
Builder.registerComponent(component, info);
});

if (props?.apiVersion) {
builder.apiVersion = props?.apiVersion;
}
Expand Down
1 change: 1 addition & 0 deletions packages/react-tests/react-remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"@builder.io/react": "workspace:*",
"@builder.io/sdks-e2e-tests": "workspace:*",
"@builder.io/sdks-tests-custom-components": "workspace:*",
"@remix-run/node": "^1.14.3",
"@remix-run/react": "^1.14.3",
"@remix-run/serve": "^1.14.3",
Expand Down
1 change: 1 addition & 0 deletions packages/react-tests/react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@builder.io/react": "workspace:*",
"@builder.io/sdks-e2e-tests": "workspace:*",
"@builder.io/sdks-tests-custom-components": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
9 changes: 7 additions & 2 deletions packages/react-tests/react-vite/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { getAPIKey, getProps } from '@builder.io/sdks-e2e-tests';
import { BuilderComponent, builder } from '@builder.io/react';
import { BuilderComponent, builder, Builder } from '@builder.io/react';
import { useEffect } from 'react';
import { getCustomComponents } from '@builder.io/sdks-tests-custom-components/output/react/src/index';

builder.init(getAPIKey());
// default to not tracking, and re-enable when appropriate
builder.canTrack = false;

function App() {
const props = getProps() as any;
const props = { ...getProps(), customComponents: getCustomComponents() };

props.customComponents.forEach(({ component, ...info }) => {
Builder.registerComponent(component, info);
});

if (props?.apiVersion) {
builder.apiVersion = props?.apiVersion;
Expand Down
38 changes: 38 additions & 0 deletions packages/sdks-tests-custom-components/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @type {import('eslint').Linter.Config}
*/
module.exports = {
env: {
node: true,
es2021: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: './tsconfig.json',
},
plugins: ['@typescript-eslint', 'unused-imports'],
rules: {
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-empty-function': 'off',
'unused-imports/no-unused-imports': 'error',
'object-shorthand': 'error',
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports', disallowTypeAnnotations: false },
],
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],

// Note: you must disable the base rule as it can report incorrect errors
'require-await': 'off',
'@typescript-eslint/require-await': 'error',

'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/no-floating-promises': 'error',
},
};
3 changes: 3 additions & 0 deletions packages/sdks-tests-custom-components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/

output/
7 changes: 7 additions & 0 deletions packages/sdks-tests-custom-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# E2E App and Specification

This package contains a set of Mitosis which form a small working application,
and Playwright specs for that application.

To the extent mitosis works correctly, the app will pass the same set of tests
regardless of which target framework is used.
43 changes: 43 additions & 0 deletions packages/sdks-tests-custom-components/mitosis.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @typedef {import('@builder.io/mitosis')} Mitosis
* @typedef {import('@builder.io/mitosis').MitosisNode} MitosisNode
* @typedef {import('@builder.io/mitosis').StateValue} StateValue
* @typedef {import('@builder.io/mitosis').MitosisConfig} MitosisConfig
* @typedef {import('@builder.io/mitosis').Plugin} Plugin
*/

/**
* @type {MitosisConfig['options']['vue']}
*/
const vueConfig = {
typescript: true,
namePrefix: path => (path.includes('/blocks/') ? 'builder' : ''),
asyncComponentImports: true,
api: 'options',
};

/**
* @type {MitosisConfig}
*/
module.exports = {
files: 'src/**',
targets: ['reactNative', 'vue2', 'rsc', 'vue3', 'solid', 'svelte', 'react', 'qwik'],
options: {
vue2: {
...vueConfig,
},
vue3: vueConfig,
react: {
stylesType: 'style-tag',
},
reactNative: {
typescript: true,
},
qwik: {
typescript: true,
},
svelte: {
typescript: true,
},
},
};
16 changes: 16 additions & 0 deletions packages/sdks-tests-custom-components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@builder.io/sdks-tests-custom-components",
"description": "Mitosis codebase containing custom components used for SDK tests",
"private": true,
"scripts": {
"start": "watch 'yarn run build' ./src",
"build": "mitosis build"
},
"type": "module",
"dependencies": {
"@builder.io/mitosis": "^0.0.93",
"@builder.io/mitosis-cli": "^0.0.52",
"@builder.io/sdks": "workspace:*",
"watch": "^1.0.2"
}
}
34 changes: 34 additions & 0 deletions packages/sdks-tests-custom-components/src/button.lite.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Show } from '@builder.io/mitosis';

export interface ButtonProps {
attributes?: any;
text?: string;
link?: string;
openLinkInNewTab?: boolean;
}

/**
* Custom Button component that adds a `cyan` color.
*/
export default function Button(props: ButtonProps) {
return (
<Show
when={props.link}
else={
<button css={{ all: 'unset', color: 'cyan' }} {...props.attributes}>
{props.text}
</button>
}
>
<a
css={{ color: 'cyan' }}
role="button"
href={props.link}
target={props.openLinkInNewTab ? '_blank' : undefined}
{...props.attributes}
>
{props.text}
</a>
</Show>
);
}