All jobs

Write Component Tests for a SolidJS App

Yes. An agent sets up Vitest with jsdom and Solid Testing Library in your SolidJS app, tests the components that hold state, mocks the API, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads the app and its build before it writes a test. In an app like solidjs/solid-realworld, package.json depends on solid-js ^1.3.3, builds with Rollup 2.52.3 through @rollup/plugin-babel using babel-preset-solid, and has a test script that is the placeholder string test; there are no test files. The components live in .js files that contain JSX, and App.js, NavBar.js, ListErrors.js and pages/Article/Comments.js use Show, For, Switch, Match and Suspense without importing them, which works because the Solid preset auto-imports those built-ins, so whatever compiles the tests has to apply the same preset to .js files. src/store/index.js exports a Provider that creates the hash router from createRouteHandler, a store with token from localStorage and appName set to conduit, and an agent from createAgent that calls https://api.realworld.io/api with fetch and a Token header; useStore() and useRouter() read those contexts. .prettierrc asks for double quotes and a 100-column width, and .github/workflows/gh-pages.yml installs on Node 14, runs npm run build on pull requests and deploys public/ from main.

It installs vitest, jsdom, vite-plugin-solid, @solidjs/testing-library and @testing-library/jest-dom as devDependencies and writes vitest.config.js: the Solid plugin configured to compile .js files as JSX with the same preset, test.environment set to jsdom, resolve.conditions with development and browser so the browser build of Solid loads under jsdom, and a setup file that registers the jest-dom matchers. A test helper renders a component inside the real Provider after stubbing globalThis.fetch with a vi.fn that answers each path with a JSON body, so createAgent is exercised as written and no request leaves the process.

Then it writes tests for the components with the most conditions. ListErrors renders one li per key of props.errors and nothing when the prop is missing. NavLink renders an href of #/login for route="login" and gets the active class when the router's current routeName matches, which the test drives by setting window.location.hash and firing hashchange. ArticlePreview shows the favourite button only when a token is passed, renders favoritesCount inside it, and calls onClickFavorite with the article on click; the /*@once*/ tag list renders each tag. The Comment card in Comments.js shows the delete icon only when currentUser.username equals the comment author's, and the page shows the sign-in prompt when there is no user. For the store, createArticles.makeFavorite raises favoritesCount at once and rolls it back when the mocked fetch rejects, which is the optimistic update the component relies on. Each test asserts on rendered text and attributes, not on signals.

It sets test to vitest run, adds a step that runs it in gh-pages.yml before the build, and, because Vitest needs a newer Node than the 14 the workflow pins, moves the workflow to a current LTS and runs npm run build on it in the sandbox to show the Rollup 2 build still succeeds there. It runs the suite, runs Prettier on the new files, and opens a pull request that lists each component and what its tests cover, changing no component code.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Write component tests for this SolidJS app and open a pull request. Read package.json, rollup.config.js, .prettierrc, .github/workflows/gh-pages.yml, src/index.js, src/App.js, every file under src/components, src/pages/Article/Comments.js and every file under src/store first. Add Vitest with jsdom, vite-plugin-solid and Solid Testing Library, with a config that compiles the .js files as Solid JSX using the same preset as the Rollup build and resolves the browser build of solid-js. Write a helper that renders inside the real store Provider with globalThis.fetch stubbed so no request leaves the process. Test ListErrors, NavLink, ArticlePreview and the Comment card as a user would, asserting on visible output, and test the optimistic favourite and rollback in createArticles. Set the test script to vitest run, add a test step to the Pages workflow before the build, and if the workflow's Node is too old for Vitest move it to a current LTS and prove the build still passes. Run the tests and Prettier, and open a pull request that lists each component and what its tests cover. Change no component code.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch that adds vitest.config.js, a setup file, a render helper and test files beside the components and the store, changes package.json and package-lock.json for the devDependencies and the test script, and edits .github/workflows/gh-pages.yml to run the tests on every pull request. The description lists each component with the behaviours its tests cover, quotes the Vitest summary with every test named, and shows npm run build succeeding on the Node the workflow now uses.

Before merging, a reviewer checks that the tests describe the components the way the team thinks about them, that the fetch stub's answers match the RealWorld API shapes the app expects, and whether the Node bump in the workflow should land in this pull request or its own. The tests run on the pull request itself, so the check is visible before anyone reads the diff.

Run it on every new component in the app

Add an automation to the Project with a github trigger on pull_request.opened and a saved prompt that asks for tests for the components the pull request adds or changes under src/components and src/pages; the trigger appends the pull request event after the prompt, so the agent reads the changed files from it. Each run opens its own pull request against the feature branch with tests for just those components, so coverage lands with the feature rather than later.

For the backlog, a schedule trigger once a week with the same prompt picks the next few untested components each time. Give the API key a webhook URL and read run.completed to post each pull request link where the team reviews tests.

The use case this job follows, with its automation and trigger: Write the missing tests.

Why run it on Rush?

The first tests in a Solid app fail for reasons that have nothing to do with the components: JSX in .js files the test transform does not pick up, built-ins the preset auto-imports in the build but not in the test, the server build of Solid loading under jsdom, a hash router that reads window.location at construction. On Rush the agent works through those in its own sandbox with the repository's own Rollup config as the reference, and the transcript shows every failed render and the config line that fixed it.

Because the result is a pull request with the Vitest output in its record and a test step on the workflow, the review is about whether the tests describe the components well, not whether they run. The same request runs on every Solid app a team owns at once, each in its own sandbox, and nothing is installed on a laptop.

Frequently asked questions

Why Vitest rather than Jest, when the app builds with Rollup?

Vitest compiles through Vite plugins, and vite-plugin-solid applies the same babel-preset-solid the Rollup build uses, including the auto-imported built-ins, so the tests see the components as the app does. The Rollup build itself is untouched; Vitest is used for tests only.

Do the tests call the RealWorld API?

No. The render helper replaces globalThis.fetch with a stub that answers each path with a JSON body, so createAgent runs as written and nothing leaves the process. The stub's answers are small fixtures in the test files that you can adjust to your own API.

Does it change any component?

No. The prompt forbids it, and the tests render the files as they are, including .js files with JSX and the untyped props. Where a component is hard to test as written, the pull request says what change would help and leaves it to you.

What about the Node 14 in the Pages workflow?

Vitest does not run on it, so the agent moves setup-node to a current LTS and runs the Rollup build on that version in the sandbox to show the deploy still works. The bump is one line, called out in the pull request, and you can ask for it in a separate change instead.

More SolidJS jobs

The same job on other stacks

Keep reading