db-migrate / db-migrate/node-db-migrate

Argv bug when running createDatabase using the Programmable API as part of a Jest test run

Open
#796 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.3k
Forks
361
PR merge metrics
No merged PRs in 30d

Description

## I'm submitting a...
- [x] Bug report
- [ ] Feature request
- [ ] Question

## Current behavior
When running the following command (which runs some tests that create a DB in docker container):
```
yarn test some/test/file.spec.js
```

The DB created is actually called `some/test/file.spec.js` rather than the desired name, e.g. `random-uuid`.

Then you run all the Jest tests with `yarn test` it all works fine.

The code responsible: https://github.com/db-migrate/node-db-migrate/blob/master/lib/commands/db.js#L10 (it gets the first argument which gets populated by a combination of `rc`, `minimist` and `yargs` deep in the dependency tree (exactly here: https://github.com/db-migrate/node-db-migrate/blob/master/lib/commands/set-default-argv.js#L133)

## Expected behavior

The desired random DB name should be used.

## Minimal reproduction of the problem with instructions

Create a Jest test spec file and a npm script that will run it. You can use npm or yarn.

Use the node-db-migrate Programmable API (https://db-migrate.readthedocs.io/en/latest/API/programable/#createdatabasedbname-callback) `createDatabase` function to create a new DB in the test.

Run the script WITH the file name as an argument.

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

Sometimes you need to run a specific test spec file rather than an entire test suite.

## Environment



db-migrate version: 0.11.13
plugins with versions: 1.2.2 (db-migrate-pg)

Additional information:
- Node version: v16.14.0
- Platform: Mac, Linux, Windows

Others:

Temporary fix: run `process.argv.slice(2)` in your code before running the `createDatabase` API function. That solves the problem in a very hacky way.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.