The chat responses are generated using Generative AI technology for intuitive search and may not be entirely accurate. They are not intended as professional advice. For full details, including our use rights, privacy practices and potential export control restrictions, please refer to our Generative AI Service Privacy Information. As this is a test version, please let us know if something irritating comes up. Like you get recommended a chocolate fudge ice cream instead of an energy managing application. If that occurs, please use the feedback button in our contact form!
Skip to content

Develop locally

2612

Uploading a ZIP for every change is fine for integration testing but slow for UI work. Two techniques make the loop faster.

1. Mock the context in development mode

Outside Polarion, fetchContext() rejects after five seconds. Short-circuit it in development builds with a mock, so that npm run dev renders your view immediately:

src/context.ts
import { fetchContext, type PolarionContext } from 'polarion-app-sdk';

const mock: PolarionContext = {
  applicationId: 'com.example.workitemcard',
  viewId: 'card',
  projectId: 'test',
  workItemId: 'TEST-514',
  selectedWorkItemIds: ['test/TEST-514'],
  appEndpoint: 'http://localhost:5173/mock/rest',
  restBaseUrl: 'http://localhost:5173/mock/v1',
  restToken: 'dev',
};

export function getContext(): Promise<PolarionContext> {
  return import.meta.env.DEV ? Promise.resolve(mock) : fetchContext();
}

import.meta.env.DEV is true under vite and false in vite build, so the production package always uses the real SDK.

With the mock in place, REST calls go to http://localhost:5173/mock/…, which does not exist. Either mock the data layer the same way (import.meta.env.DEV ? fakeItems : restFetch(...)), or proxy to a real server as described next.

2. Proxy the REST API to a real server (untested recipe)

Vite's dev server can forward /polarion/rest/… to your Polarion server. Combined with a personal access token (PAT) that you generate in Polarion under My Account → Personal Access Tokens, the view talks to real data while you edit:

vite.config.ts
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '');
  return {
    plugins: [react()],
    base: './',
    server: {
      proxy: {
        '/polarion/rest': {
          target: env.POLARION_URL,           // https://polarion.example.com
          changeOrigin: true,
          headers: { Authorization: `Bearer ${env.POLARION_PAT}` },
        },
      },
    },
  };
});
.env.local (not committed)
POLARION_URL=https://polarion.example.com
POLARION_PAT=…

Set the mock context's restBaseUrl to /polarion/rest/v1 (relative, so it hits the proxy) and leave restToken empty; the proxy adds the PAT. In production the real context's absolute restBaseUrl and token are used.

Keep the PAT out of source control and remove it when you are done. It carries your full Polarion permissions.

3. Testing inside Polarion still needs an upload

The view that Polarion loads is a static page under /polarion/apps/<identifier>/<rootDirectory>/. Polarion serves it from its own storage; there is no way to point an installed application at your dev server. The fastest loop for inside-Polarion testing is therefore:

npm run package     # a few seconds

followed by the upload (which is an update, no configuration changes) and a hard reload of the Polarion page. Content-hashed asset names make cache problems impossible.

4. Open the view directly

https://<host>/polarion/apps/<identifier>/views/<viewId> opens the view in a tab of its own, without the Polarion page around it. The context fetch fails there, but static-file problems (404s, wrong base, missing icons) show up immediately in the browser's network panel.

Debugging inside Polarion

  • Use the browser's developer tools; the iframe appears as a separate frame in the console's frame selector and in the network panel. Filter the network panel by apps/ to see your files and endpoint calls.
  • console.log from the view appears in the same console as Polarion's own output. Prefix your messages ([myapp]) to find them.
  • React DevTools attaches to iframes on the same origin.
  • Vite source maps: build: { sourcemap: "inline" } in vite.config.ts puts readable stack traces into the JavaScript files, at the cost of larger packages. Do not use sourcemap: true: it writes separate .map files, which are not an allowed file type, so Polarion rejects the package. Turn source maps off for releases.

A note on hot reloading and the SDK

With the Vite dev server and React Fast Refresh, components remount often. The SDK tolerates this as long as your effect cleanup calls destroy(); otherwise the second mount's events.subscribe() throws Already subscribed to event.