Skip to content

Commit 1ff9777

Browse files
committed
split into 4 tests
1 parent 6e03e2a commit 1ff9777

8 files changed

Lines changed: 179 additions & 57 deletions

File tree

pnpm-lock.yaml

Lines changed: 46 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
describe("server-function", () => {
2-
it("should isServer false on the client and true in the server function", () => {
2+
it("should isServer false on the client", () => {
33
cy.visit("/");
4-
cy.get("#server-fn-test").contains(`{"clientWithIsServer":false,"serverFnWithIsServer":true,"serverFnWithNodeBuiltin":"can/externalize"}`);
4+
cy.get("#server-fn-test").contains('{"clientWithIsServer":false}');
5+
})
6+
it("should isServer true in the server function", () => {
7+
cy.visit("/is-server");
8+
cy.get("#server-fn-test").contains('{"serverFnWithIsServer":true}');
9+
})
10+
it("should externalize node builtin in server function", () => {
11+
cy.visit("/node-builtin");
12+
cy.get("#server-fn-test").contains('{"serverFnWithNodeBuiltin":"can/externalize"}');
13+
})
14+
it("should externalize npm module in server function", () => {
15+
cy.visit("npm-module");
16+
cy.get("#server-fn-test").contains('{"serverFnWithNpmModule":[2,4,6]}');
517
})
618
});

tests/server-function/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
"test": "pnpm run dev & cypress run"
1414
},
1515
"dependencies": {
16+
"@solidjs/meta": "^0.29.4",
17+
"@solidjs/router": "^0.15.3",
1618
"@solidjs/start": "workspace:*",
1719
"@solidjs/testing-library": "^0.8.10",
1820
"@testing-library/jest-dom": "^6.6.2",
1921
"@testing-library/user-event": "^14.5.2",
2022
"@vitest/ui": "^2.1.4",
2123
"jsdom": "^25.0.1",
24+
"lodash": "^4.17.21",
2225
"solid-js": "catalog:",
2326
"vinxi": "catalog:",
2427
"vite-plugin-solid": "catalog:",
@@ -31,9 +34,10 @@
3134
"node": ">=18"
3235
},
3336
"devDependencies": {
34-
"cypress-vite": "^1.6.0",
3537
"@cypress/code-coverage": "^3.13.10",
38+
"@types/lodash": "^4.17.14",
3639
"cypress": "^14.0.0",
37-
"cypress-plugin-tab": "^1.0.5"
40+
"cypress-plugin-tab": "^1.0.5",
41+
"cypress-vite": "^1.6.0"
3842
}
3943
}

tests/server-function/src/app.tsx

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,24 @@
1-
import { join } from 'path';
2-
import { createEffect, createSignal } from "solid-js";
3-
import { isServer } from "solid-js/web";
4-
1+
import { MetaProvider, Title } from "@solidjs/meta";
2+
import { Router } from "@solidjs/router";
3+
import { FileRoutes } from "@solidjs/start/router";
4+
import { Suspense } from "solid-js";
55
import "./app.css";
66

7-
function serverFnWithIsServer() {
8-
"use server";
9-
10-
return isServer;
11-
}
12-
13-
function serverFnWithNodeBuiltin() {
14-
"use server";
15-
16-
return join('can','externalize');
17-
}
18-
197
export default function App() {
20-
const [output, setOutput] = createSignal<{ clientWithIsServer?: boolean; serverFnWithIsServer?: boolean, serverFnWithNodeBuiltin?: string }>({});
21-
22-
setOutput(prev => ({ ...prev, clientWithIsServer: isServer }));
23-
24-
createEffect(async () => {
25-
const restult = await serverFnWithIsServer();
26-
setOutput(prev => ({ ...prev, serverFnWithIsServer: restult }));
27-
});
28-
29-
createEffect(async () => {
30-
const restult = await serverFnWithNodeBuiltin();
31-
setOutput(prev => ({ ...prev, serverFnWithNodeBuiltin: restult }));
32-
});
33-
348
return (
35-
<main>
36-
<h1>Hello world!</h1>
37-
<span id="server-fn-test">{JSON.stringify(output())}</span>
38-
</main>
9+
<Router
10+
root={props => (
11+
<MetaProvider>
12+
<Title>SolidStart - Basic</Title>
13+
<a href="/">Client</a>
14+
<a href="/is-server">isserver</a>
15+
<a href="/node-builtin">node builtin</a>
16+
<a href="/npm-module">npm module (lodash)</a>
17+
<Suspense>{props.children}</Suspense>
18+
</MetaProvider>
19+
)}
20+
>
21+
<FileRoutes />
22+
</Router>
3923
);
4024
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import _ from "lodash";
2+
import { join } from 'path';
3+
import { createEffect, createSignal } from "solid-js";
4+
import { isServer } from "solid-js/web";
5+
6+
export default function App() {
7+
const [output, setOutput] = createSignal<{ clientWithIsServer?: boolean; }>({});
8+
9+
setOutput(prev => ({ ...prev, clientWithIsServer: isServer }));
10+
11+
return (
12+
<main>
13+
<span id="server-fn-test">{JSON.stringify(output())}</span>
14+
</main>
15+
);
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import _ from "lodash";
2+
import { join } from 'path';
3+
import { createEffect, createSignal } from "solid-js";
4+
import { isServer } from "solid-js/web";
5+
6+
function serverFnWithIsServer() {
7+
"use server";
8+
9+
return isServer;
10+
}
11+
12+
export default function App() {
13+
const [output, setOutput] = createSignal<{ serverFnWithIsServer?: boolean }>({});
14+
15+
16+
createEffect(async () => {
17+
const restult = await serverFnWithIsServer();
18+
setOutput(prev => ({ ...prev, serverFnWithIsServer: restult }));
19+
});
20+
21+
22+
return (
23+
<main>
24+
<span id="server-fn-test">{JSON.stringify(output())}</span>
25+
</main>
26+
);
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import _ from "lodash";
2+
import { join } from 'path';
3+
import { createEffect, createSignal } from "solid-js";
4+
import { isServer } from "solid-js/web";
5+
6+
function serverFnWithNodeBuiltin() {
7+
"use server";
8+
9+
return join('can','externalize');
10+
}
11+
12+
export default function App() {
13+
const [output, setOutput] = createSignal<{ serverFnWithNodeBuiltin?: string }>({});
14+
15+
16+
17+
createEffect(async () => {
18+
const restult = await serverFnWithNodeBuiltin();
19+
setOutput(prev => ({ ...prev, serverFnWithNodeBuiltin: restult }));
20+
});
21+
22+
return (
23+
<main>
24+
<span id="server-fn-test">{JSON.stringify(output())}</span>
25+
</main>
26+
);
27+
}

0 commit comments

Comments
 (0)