Skip to content

Commit 7f4a7d1

Browse files
authored
Add cypress server-function test (#1719)
* add cypress server-function test * add workflow * pick node from .nvmrc * path * split install * use pnpm filter * use quotes * use cypress wd * back to filter * debug github action * debug tests dir * add pwd * debug * don't echo package.json * split cypress, because lacking pnpm support * try to keep wd at root * move cypress to test repo * cy install in test dir * pnpm ignore workspace * cypress run don't install * test:server-function * start server and test * move cypress to root * port 3456 * start only once the server * move cy to test * add cypress deps to * build * try to not ignore-workspace * use cypress action * remove cypress from root * cleanup * cypress root * use workspace instead of relative path * use prod build * build command
1 parent 85e758c commit 7f4a7d1

19 files changed

Lines changed: 3356 additions & 276 deletions
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
9+
jobs:
10+
11+
e2e-tests:
12+
name: "E2E tests using ${{ matrix.browser }}"
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
browser: [chrome, firefox]
17+
18+
runs-on: ubuntu-22.04
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version-file: '.nvmrc'
25+
26+
- uses: pnpm/action-setup@v4
27+
with:
28+
version: 9
29+
30+
- name: Install project dependencies
31+
run: pnpm i
32+
33+
- name: Install project dependencies
34+
run: pnpm run build
35+
36+
- name: Install dependencies
37+
uses: cypress-io/github-action@v6
38+
with:
39+
working-directory: .
40+
runTests: false
41+
42+
- name: Cypress test
43+
uses: cypress-io/github-action@v6
44+
with:
45+
install: false
46+
working-directory: tests/server-function
47+
build: pnpm run build
48+
start: pnpm run start
49+
browser: ${{ matrix.browser }}
50+

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@cloudflare/kv-asset-handler": "^0.2.0",
3333
"citty": "^0.1.5",
3434
"coveralls": "^3.1.1",
35+
"cypress": "^14.0.0",
3536
"debug": "^4.3.4",
3637
"rimraf": "^3.0.2",
3738
"tinyglobby": "^0.2.2",

pnpm-lock.yaml

Lines changed: 3000 additions & 276 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ packages:
22
# all packages in subdirs of packages/ and examples/
33
- "packages/*"
44
- "examples/*"
5+
- "tests/*"
56
- "docs"
67
- "!**/.tmp/**"
78
options:

tests/server-function/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SolidStart
2+
3+
Everything you need to build a Solid project, powered by [`solid-start`](https://start.solidjs.com);
4+
5+
## Creating a project
6+
7+
```bash
8+
# create a new project in the current directory
9+
npm init solid@latest
10+
11+
# create a new project in my-app
12+
npm init solid@latest my-app
13+
```
14+
15+
## Developing
16+
17+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
18+
19+
```bash
20+
npm run dev
21+
22+
# or start the server and open the app in a new browser tab
23+
npm run dev -- --open
24+
```
25+
26+
## Building
27+
28+
Solid apps are built with _presets_, which optimise your project for deployment to different environments.
29+
30+
By default, `npm run build` will generate a Node app that you can run with `npm start`. To use a different preset, add it to the `devDependencies` in `package.json` and specify in your `app.config.js`.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineConfig } from "@solidjs/start/config";
2+
3+
export default defineConfig({
4+
ssr: false
5+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineConfig } from "cypress";
2+
3+
// import { createRequire } from "module";
4+
// const require = createRequire(import.meta.url);
5+
6+
export default defineConfig({
7+
env: {
8+
codeCoverage: {
9+
exclude: "cypress/**/*.*",
10+
},
11+
},
12+
e2e: {
13+
setupNodeEvents(on, config) {
14+
// implement node event listeners here
15+
// require("@cypress/code-coverage/task")(on, config);
16+
return config;
17+
},
18+
baseUrl: "http://localhost:3000",
19+
retries: {
20+
runMode: 2,
21+
openMode: 0,
22+
},
23+
},
24+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
describe("server-function", () => {
2+
it("should isServer false on the client and true in the server function", () => {
3+
cy.visit("/");
4+
cy.get("#server-fn-test").contains(`{"client":false,"serverFn":true}`);
5+
})
6+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// ***********************************************************
2+
// This example support/e2e.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import "@cypress/code-coverage/support";
18+
import "cypress-plugin-tab";
19+
20+
// Alternatively you can use CommonJS syntax:
21+
// require('./commands')

tests/server-function/package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "server-function-test",
3+
"type": "module",
4+
"scripts": {
5+
"dev": "vinxi dev",
6+
"build": "vinxi build",
7+
"start": "vinxi start",
8+
"vitest": "vitest run",
9+
"test-watch": "vitest",
10+
"test-ui": "vitest --ui",
11+
"cy:open": "cypress open",
12+
"cy:run": "cypress run",
13+
"test": "pnpm run dev & cypress run"
14+
},
15+
"dependencies": {
16+
"@solidjs/start": "workspace:*",
17+
"@solidjs/testing-library": "^0.8.10",
18+
"@testing-library/jest-dom": "^6.6.2",
19+
"@testing-library/user-event": "^14.5.2",
20+
"@vitest/ui": "^2.1.4",
21+
"jsdom": "^25.0.1",
22+
"solid-js": "^1.9.2",
23+
"vinxi": "^0.4.3",
24+
"vite-plugin-solid": "^2.10.2",
25+
"vitest": "^3.0.0"
26+
},
27+
"overrides": {
28+
"vite": "5.4.10"
29+
},
30+
"engines": {
31+
"node": ">=18"
32+
},
33+
"devDependencies": {
34+
"cypress-vite": "^1.6.0",
35+
"@cypress/code-coverage": "^3.13.10",
36+
"cypress": "^14.0.0",
37+
"cypress-plugin-tab": "^1.0.5"
38+
}
39+
}

0 commit comments

Comments
 (0)