Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 46 additions & 19 deletions pnpm-lock.yaml

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

16 changes: 14 additions & 2 deletions tests/server-function/cypress/e2e/server-function.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
describe("server-function", () => {
it("should isServer false on the client and true in the server function", () => {
it("should have isServer false in the client", () => {
cy.visit("/");
cy.get("#server-fn-test").contains(`{"client":false,"serverFn":true}`);
cy.get("#server-fn-test").contains('{"clientWithIsServer":false}');
})
it("should have isServer true in the server function", () => {
cy.visit("/is-server");
cy.get("#server-fn-test").contains('{"serverFnWithIsServer":true}');
})
it("should externalize node builtin in server function", () => {
cy.visit("/node-builtin");
cy.get("#server-fn-test").contains('{"serverFnWithNodeBuiltin":"can/externalize"}');
})
it("should externalize npm module in server function", () => {
cy.visit("npm-module");
cy.get("#server-fn-test").contains('{"serverFnWithNpmModule":[2,4,6]}');
})
});
8 changes: 6 additions & 2 deletions tests/server-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
"test": "pnpm run dev & cypress run"
},
"dependencies": {
"@solidjs/meta": "^0.29.4",
"@solidjs/router": "^0.15.3",
"@solidjs/start": "workspace:*",
"@solidjs/testing-library": "^0.8.10",
"@testing-library/jest-dom": "^6.6.2",
"@testing-library/user-event": "^14.5.2",
"@vitest/ui": "^2.1.4",
"jsdom": "^25.0.1",
"lodash": "^4.17.21",
"solid-js": "catalog:",
"vinxi": "catalog:",
"vite-plugin-solid": "catalog:",
Expand All @@ -31,9 +34,10 @@
"node": ">=18"
},
"devDependencies": {
"cypress-vite": "^1.6.0",
"@cypress/code-coverage": "^3.13.10",
"@types/lodash": "^4.17.14",
"cypress": "^14.0.0",
"cypress-plugin-tab": "^1.0.5"
"cypress-plugin-tab": "^1.0.5",
"cypress-vite": "^1.6.0"
}
}
37 changes: 18 additions & 19 deletions tests/server-function/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { createEffect, createSignal } from "solid-js";
import { isServer } from "solid-js/web";
import { MetaProvider, Title } from "@solidjs/meta";
import { Router } from "@solidjs/router";
import { FileRoutes } from "@solidjs/start/router";
import { Suspense } from "solid-js";
import "./app.css";

function useServer() {
"use server";
return isServer;
}
export default function App() {
const [output, setOutput] = createSignal<{ client?: boolean; serverFn?: boolean }>({});

setOutput(prev => ({ ...prev, client: isServer }));

createEffect(async () => {
const restult = await useServer();
setOutput(prev => ({ ...prev, serverFn: restult }));
});

return (
<main>
<h1>Hello world!</h1>
<span id="server-fn-test">{JSON.stringify(output())}</span>
</main>
<Router
root={props => (
<MetaProvider>
<Title>SolidStart - Basic</Title>
<a href="/">Client</a>
<a href="/is-server">isserver</a>
<a href="/node-builtin">node builtin</a>
<a href="/npm-module">npm module (lodash)</a>
<Suspense>{props.children}</Suspense>
</MetaProvider>
)}
>
<FileRoutes />
</Router>
);
}
16 changes: 16 additions & 0 deletions tests/server-function/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import _ from "lodash";
import { join } from 'path';
import { createEffect, createSignal } from "solid-js";
import { isServer } from "solid-js/web";

export default function App() {
const [output, setOutput] = createSignal<{ clientWithIsServer?: boolean; }>({});

setOutput(prev => ({ ...prev, clientWithIsServer: isServer }));

return (
<main>
<span id="server-fn-test">{JSON.stringify(output())}</span>
</main>
);
}
27 changes: 27 additions & 0 deletions tests/server-function/src/routes/is-server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import _ from "lodash";
import { join } from 'path';
import { createEffect, createSignal } from "solid-js";
import { isServer } from "solid-js/web";

function serverFnWithIsServer() {
"use server";

return isServer;
}

export default function App() {
const [output, setOutput] = createSignal<{ serverFnWithIsServer?: boolean }>({});


createEffect(async () => {
const restult = await serverFnWithIsServer();
setOutput(prev => ({ ...prev, serverFnWithIsServer: restult }));
});


return (
<main>
<span id="server-fn-test">{JSON.stringify(output())}</span>
</main>
);
}
27 changes: 27 additions & 0 deletions tests/server-function/src/routes/node-builtin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import _ from "lodash";
import { join } from 'path';
import { createEffect, createSignal } from "solid-js";
import { isServer } from "solid-js/web";

function serverFnWithNodeBuiltin() {
"use server";

return join('can','externalize');
}

export default function App() {
const [output, setOutput] = createSignal<{ serverFnWithNodeBuiltin?: string }>({});



createEffect(async () => {
const restult = await serverFnWithNodeBuiltin();
setOutput(prev => ({ ...prev, serverFnWithNodeBuiltin: restult }));
});

return (
<main>
<span id="server-fn-test">{JSON.stringify(output())}</span>
</main>
);
}
25 changes: 25 additions & 0 deletions tests/server-function/src/routes/npm-module.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import _ from "lodash";
import { join } from 'path';
import { createEffect, createSignal } from "solid-js";
import { isServer } from "solid-js/web";

function serverFnWithNpmModule() {
"use server";

return _.map([1, 2, 3], x => x * 2);
}

export default function App() {
const [output, setOutput] = createSignal<{ serverFnWithNpmModule?: number[] }>({});

createEffect(async () => {
const restult = await serverFnWithNpmModule();
setOutput(prev => ({ ...prev, serverFnWithNpmModule: restult }));
});

return (
<main>
<span id="server-fn-test">{JSON.stringify(output())}</span>
</main>
);
}