Test-setup helper that binds Sequelize models to an OFFLINE Sequelize
instance in replay mode — the constructor performs no I/O, so no live DB is required.
Why: in replay the original connect() is replayed from the snapshot, so the model is
never bound to a Sequelize instance and its isInitialized flag stays false — the
original static build() would throw ModelNotInitializedError during replay
reconstruction (see rebuildInstance).
The binding runs with the global mode temporarily switched to 'off' and restored
afterwards, because Model.init() internally invokes wrapped statics (e.g.
getTableName) which must NOT route into a replay lookup during setup.
In replay the created instance is additionally made hermetic: its connection manager is
replaced with an offline stub (see makeConnectionManagerOffline), so any stray
raw call through the real library code (e.g. Model.sequelize?.query('SELECT setval(...)'))
never opens a live connection. This makes replay fully DB-less. When
UNIMOCK_FALLBACK_ON_MISS=1 the connection manager is left live so the replay-miss
fallback can execute against the real backend.
Description
Test-setup helper that binds Sequelize models to an OFFLINE
Sequelizeinstance in replay mode — the constructor performs no I/O, so no live DB is required.Why: in replay the original
connect()is replayed from the snapshot, so the model is never bound to aSequelizeinstance and itsisInitializedflag staysfalse— the original staticbuild()would throwModelNotInitializedErrorduring replay reconstruction (see rebuildInstance).The binding runs with the global mode temporarily switched to
'off'and restored afterwards, becauseModel.init()internally invokes wrapped statics (e.g.getTableName) which must NOT route into a replay lookup during setup.In replay the created instance is additionally made hermetic: its connection manager is replaced with an offline stub (see makeConnectionManagerOffline), so any stray raw call through the real library code (e.g.
Model.sequelize?.query('SELECT setval(...)')) never opens a live connection. This makes replay fully DB-less. WhenUNIMOCK_FALLBACK_ON_MISS=1the connection manager is left live so the replay-miss fallback can execute against the real backend.No-op (returns
undefined) outside replay mode.Example