testcafe-legacy-api

raw JSON →
5.1.9 verified Sat Apr 25 auth: no javascript

Provides legacy API support for TestCafe, allowing the use of older TestCafe APIs (e.g., `fixture.page`, `test.page`, `t.setSpeed`, `t.navigateTo`, etc.) in test scripts. Current stable version is 5.1.9. The package is maintained by DevExpress and is required when migrating tests from TestCafe v1.x to v2.x or higher, where the legacy APIs were removed. It acts as a compatibility layer and is only needed if you have existing tests that rely on deprecated TestCafe APIs. Key differentiator: it enables gradual migration without rewriting all tests at once, but is not intended for new projects.

error Error: The legacy API is not available. Ensure that the 'testcafe-legacy-api' plugin is installed.
cause Missing or incorrect import of the legacy API plugin.
fix
Run npm install testcafe-legacy-api and add import 'testcafe-legacy-api' at the top of your test file.
error TypeError: t.setSpeed is not a function
cause Using t.setSpeed without the legacy API plugin, or the plugin is not loaded.
fix
Ensure the legacy API plugin is imported and registered before the test runs.
error SyntaxError: Cannot use import statement outside a module
cause The package is ESM-only but your project uses CommonJS.
fix
Add "type": "module" to your package.json or use dynamic import: import('testcafe-legacy-api').
breaking This package is intended for TestCafe v2+; it does not work with TestCafe v1.x without the legacy API included.
fix Ensure you are using TestCafe v2.0.0 or later with this package.
deprecated Many legacy API methods are deprecated in favor of modern TestCafe APIs. Use only if you have existing tests that depend on them.
fix Migrate tests to use modern TestCafe API (e.g., t.click, t.typeText) instead of legacy methods.
gotcha The package must be imported and registered before any fixtures or tests that use legacy API.
fix Add `import 'testcafe-legacy-api'` at the top of your test file to ensure the plugin is loaded before fixtures.
breaking Version 5.x dropped CommonJS support; the package is now ESM-only.
fix Update your project to use ES modules or use dynamic import if necessary.
npm install testcafe-legacy-api
yarn add testcafe-legacy-api
pnpm add testcafe-legacy-api

Shows how to import legacyApi and use it in a TestCafe fixture to set test speed and skip JS errors, and how to use legacy t.setSpeed in a test.

import { legacyApi } from 'testcafe-legacy-api';
import { Selector } from 'testcafe';

// Use legacy API in a TestCafe fixture
export default {
  [legacyApi]: {
    speed: 0.5,
    skipJsErrors: true
  }
};

fixture`Legacy Test`.page`http://example.com`;

test('Legacy test with speed', async t => {
  await t
    .setSpeed(0.5) // requires legacy-api plugin
    .click(Selector('button'));
});