fix(data): detect DataTable structurally so Data() works under tsx/cjs (#5641)#5649
Merged
Conversation
#5641) `Data(table)` threw "Invalid data type" for a valid DataTable when the test file is loaded via `require: ['tsx/cjs']`. tsx transpiles the test to CommonJS and gives it its own copy of the `DataTable` class, while the framework runs as ESM with a different copy, so the `instanceof DataTable` check fails for a genuine DataTable. Detect a DataTable by its structure (`array`/`rows` arrays + `add` method) in addition to `instanceof`, which survives duplicate module instances. Plain arrays, generators and functions still fall through to their own branches. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5641
Problem
Data(table).Scenario(...)throwsInvalid data type. Data accepts either: DataTable || generator || Array || functionfor a perfectly validDataTableafter migrating to 4.x. It works in 3.x.Root cause
The check in
lib/data/context.jsis identity-based:In a 4.x project configured with
require: ['tsx/cjs'], the test file is transpiled to CommonJS, soimport { dataTable } from 'codeceptjs'resolves through tsx's loader and the test gets its own copy of theDataTableclass. The framework runs as ESM with a differentDataTableclass. Socases instanceof DataTableisfalseeven thoughcasesis a genuine DataTable, and thethrowfires.This worked in 3.x because everything was CommonJS — a single module registry and a single class. It's the same dual-module loading hazard behind #5632 / #5635.
Fix
Detect a DataTable structurally in addition to
instanceof, which survives duplicate module instances:The duck-type can't collide with the other accepted inputs — plain arrays, generators and functions all fail it and fall through to their existing branches, so behavior is otherwise unchanged.
Verification
tsx/cjsfixture, then confirmed all data rows run after the fix.test/unit/data/ui_test.jsthat feedsData()a DataTable from a different class identity (simulating the tsx/cjs hazard without needing tsx).🤖 Generated with Claude Code