Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 3 tasks
mmajkafmp opened this issue Aug 8, 2022 · 0 comments
Open
1 of 3 tasks

Comments

@mmajkafmp
Copy link

mmajkafmp commented Aug 8, 2022

I'm submitting a...

  • 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant