Handsontable e2e testing

From handsontable/handsontable · View interactive version

Handsontable e2e testing is an AI agent skill from the GitHub repository handsontable/handsontable. Use ONLY when maintaining the FROZEN legacy Jasmine/Puppeteer E2E suite (*.spec.js) – editing an existing spec, or migrating a broken one to Playwright. NOT for new E2E: new E2E is Playwright, use the `handsontable-playwright-e2e` skill. Covers the legacy boilerplate, async/await rules, global helpe

How to use this skill

Skill file

Handsontable E2E testing (legacy Jasmine/Puppeteer, frozen)

This suite is frozen. New E2E is Playwright: use the handsontable-playwright-e2e skill and put specs in tests/e2e/. This guide covers maintaining existing *.spec.js files. The presence gate blocks a newly added *.spec.js, and appending three or more new it blocks to a modified frozen spec draws its non-blocking frozen-suite-growth advisory (state the justification in the PR if the frozen tier is right). Migrate a broken or flaky legacy spec to Playwright.

Boilerplate

describe('MyFeature', () => {
  const id = 'testContainer';

  beforeEach(function() {
    this.$container = $(`<div id="${id}"></div>`).appendTo('body');
  });

  afterEach(function() {
    if (this.$container) {
      destroy();
      this.$container.remove();
    }
  });

  it('should do something', async() => {
    handsontable({ data: createSpreadsheetData(5, 5) });
    await selectCell(0, 0);
    expect(getDataAtCell(0, 0)).toBe('A1');
  });
});

ESLint enforces: every it() callback is async, and every HOT API call (~50+ methods) is await-ed.

handsontable() adds the internal test key to every grid it builds. A second grid built any other way (new Handsontable(el, {…}), $('<div>').handsontable({…})) passes licenseKey: TEST_LICENSE_KEY (a global in specs) itself, or it runs behind the license lock; the root test:tooling fails on one that does not (handsontable/.ai/TESTING.md, "The license key every test grid takes").

Global helpers

Injected automatically; full list in test/helpers/common.js.

Write the bare global (countCols(), await alter('remove_col', 2, 1)) instead of hot().countCols(). The mutating globals (alter(), setDataAtCell(), selectCell(), ...) auto-render and must be await-ed. Use hot() only for a method with no bare-global wrapper.

Theme-agnostic assertions

Every test passes under every theme. Never branch on getLoadedTheme(), layout.densityLevel, or a theme name in a spec, and never hardcode per-theme pixel values. Build expectations from const layout = getThemeLayout() (token-backed, from test/helpers/themeLayoutFromTokens.js: token primitives, overlayHeight / verticalScrollForRow helpers, and scenario helpers such as e2eGcrEditedCellOuterHeight, e2eManualRowResizerPositionFixedTopMasterFourthRow) or from live DOM measurements. themeLayoutFromTokens(themeName) reads density and tokens from handsontable/src/themes/theme/<name>.ts, so a density change propagates to all tests. Density triplets ({ compact: N, default: N, comfortable: N }) are not used anywhere.

For a value that is not token-derivable (text shaping, autosize widths, pixel rounding):

Viewport helpers (globals from common.js):

Order of preference: (1) a named layout.e2e*() helper when a shared formula exists, (2) a direct formula in primitives (layout.defaultDataRowHeight + layout.cellBorderWidth), (3) a DOM/plugin-API read, (4) a relational assertion. Express theme differences through layout primitives, which already vary per theme.

Adding a new theme: the handsontable-css-dev skill has the four-layer token process. E2E-specific steps: (1) tokens at src/themes/static/variables/tokens/<name>.ts, (2) colors at src/themes/static/variables/colors/<name>.ts, (3) icons at src/themes/static/variables/icons/<name>.ts (or reuse one), (4) CSS source src/themes/static/css/theme/ht-theme-<name>.css + -no-icons.css variant, (5) theme module src/themes/theme/<name>.ts exporting { name, density, icons, colors, tokens }, (6) re-export from src/themes/theme/index.ts, (7) add new token keys to the VALID_TOKEN_KEYS allow-list in src/themes/engine/utils/validation.ts, (8) add new token keys to the TokenKey union in src/themes/types.ts, (9) add the theme to the six-leg theme literal of the puppeteer job's matrix in .github/workflows/e2e.yml (the bundle literal holds {label, dump} pairs and needs nothing), add the new theme's legs as rows of the Playwright job's include table (one row per shard), then update the expected theme list and SHARD_TABLE in .github/scripts/__tests__/e2e-legs.test.mjs and DURATIONS_LEGS in .github/scripts/lib/playwright-durations.mjs; the pins hold the Jasmine literals by value and the two matrices to the same legs, so test:tooling stays red until all of them agree — a pull request still runs the main theme alone, the new theme runs on the E2E nightly. themeLayoutFromTokens.js, common.js, and specs need no edits.

Details: handsontable/.ai/TESTING.md ("Data-Driven Theme Assertions").

Event simulation

Waiting in an edited spec (hard rules)

A broken or flaky spec migrates to Playwright; these rules cover an edit you must make in place.

What to test for plugins

Run commands

Parallel runs: invocations with different patterns or themes can run simultaneously. The dump step hashes testPathPattern + theme into a run ID and writes test/dist/main.entry.<runId>.js and test/E2ERunner-<runId>.html; the Puppeteer runner picks its own free port starting at 8086.

Iterating on one area: test:e2e.watch keeps the dev server running and re-bundles and re-runs on every source change:

npm run test:e2e.watch --prefix handsontable --testPathPattern=filters --theme=horizon

Split dump + puppeteer (what CI does): pass --testPathPattern AND --theme to both npm run commands. The Puppeteer script recomputes the dump's hash to find the runner HTML, and a mismatch fails with "Runner HTML not found at ...". The puppeteer job of .github/workflows/e2e.yml is the canonical example; the same applies to test:production.dump + test:e2e.puppeteer. The one-shot npm run test:e2e passes the flags to both halves itself.

A generic test/E2ERunner.html (no run ID) is regenerated alongside the per-run variant for manual browser testing. Specs that inject iframes with relative CSS paths (e.g. afterRefreshDimensions, Selection) rely on the runner living in test/, which is why the per-run HTML stays there too.

Where the suite runs in CI

A pull request and a develop push run this suite on one leg, E2E / UMD (theme: main) — plain UMD on the main theme, the shape npm run test:e2e defaults to. The six legs (three themes × UMD / the minified bundle of test:production) run on the E2E nightly (weeknights on develop), on the rc/stable publish path and on a master push (.ai/CI.md, the Jasmine single-leg entry). Two consequences:

Debugging (capturing values from the browser)

Specs run in a headless browser. The Puppeteer runner (test/scripts/run-puppeteer.mjs) forwards only console messages whose text starts with DEBUG, printed as [BROWSER] <text>:

console.log(`DEBUG state ${JSON.stringify({ labels: getColHeaders(), count: countCols() })}`);

Filter the run output: npm run test:e2e --prefix handsontable --testPathPattern=<regex> 2>&1 | grep DEBUG.

Test location

Specs live under src/ next to the code they test. The spec filename matches the method, hook, or setting name exactly (getSourceData.spec.js, afterChange.spec.js, height.spec.js).

| What is tested | Directory |

|---|---|

| Core method (e.g., getSourceData) | src/__tests__/core/<methodName>.spec.js |

| Hook (e.g., afterChange) | src/__tests__/hooks/<hookName>.spec.js |

| Setting (e.g., height) | src/__tests__/settings/<settingName>.spec.js |

| Plugin | src/plugins/{name}/__tests__/*.spec.js |

| Keyboard shortcuts | src/shortcuts/__tests__/keyboardShortcuts/<name>.spec.js |

| i18n | src/i18n/__tests__/<name>.spec.js |

| Mobile-specific | src/__tests__/mobile/<name>.spec.js |

Do not add spec files to test/e2e/; it is no longer their home.

Reference organization: src/plugins/pagination/__tests__/ (separate dirs for options, methods, hooks, strategies).

Common mistakes

Full testing docs: handsontable/.ai/TESTING.md. Key files: test/helpers/common.js, test/helpers/mouseEvents.js, test/helpers/keyboardEvents.js.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.