db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

Can't use programmatically with Jest #771

Closed derrik-fleming closed 2 years ago

derrik-fleming commented 2 years ago

I'm submitting a...

Current behavior

./jest-global-setup.js

import * as DBMigrate from "db-migrate";

module.exports = async () => {
    console.log( "\nRunning test setup . . ." );
    const dbmigrate = DBMigrate.getInstance( true, { env: "test" } );
    // ... do some stuff
};
Running test setup . . .
TypeError: Jest: Got error running globalSetup - /path/to/project/src/__tests__/setup/jest-global-setup.js, reason: Cannot set properties of undefined (setting 'isSilent')
    at Object.<anonymous> (/path/to/project/node_modules/db-migrate-shared/log.js:3:19)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Module._compile (/path/to/project/node_modules/pirates/lib/index.js:136:24)
    at Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Object.newLoader (/path/to/project/node_modules/pirates/lib/index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/path/to/project/node_modules/db-migrate-shared/index.js:4:8)

Expected behavior

I would think it should work.

I found that I don't even have to make use of DBMigrate for this error to get thrown. All I have to do is import it, in any way. I've tried ES6 import as shown above, as well as const DBMigrate = require("db-migrate").

Minimal reproduction of the problem with instructions

Not sure about "minimal" but I'm only trying to run some migrations in a test environment, before my e2e tests run. I'd also like to reset in the teardown.

My migrations will run via CLI fine.

What is the motivation / use case for changing the behavior?

Environment


db-migrate version: 0.11.13
plugins with versions: X.Y.Z
db-migrate driver with versions:
"db-migrate-pg": "^1.2.2",

Additional information:
- Node version: 16  
- Platform:  Alpine
- 
"jest": "^27.3.1"

Others: