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

run test starting server #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

run test starting server #45

wants to merge 1 commit into from

Conversation

pmosconi
Copy link

@pmosconi pmosconi commented Jan 1, 2019

ISSUE: Server: NPM Scripts for Testing #7

I moved database seeding to a dedicated tests/setup.js file from src/index.js.
src/index.js now exports httpServer wich will be imported by setup.js and starts it only when not in test mode.
tests/user.spec.js imports setup.js initializes the database in the before() function that is executed at the very beginning of the suite; likewise, the after() function terminates the process in order to prevent execution hanging for ever.
I also added a timeout in npm run test command to take into account the delay caused by seeding the database and set an IS_TEST environment test that is used to identify the enviroment (IMHO cleaner than testing for the existence of the test database name which can be now declared in .env).

To make all work in my environment I had to switch from pg to mssql and I apologise for this additional change being included in the PR, but this way I am sure this is a working project. To revert, just replace tedious with pg in package.json and replace 'mssql' with 'postgres' in models/index.js.
I also added the host parameter to account for a remote database (such as the one I am using): it is defined .env as well. Since the default is localhost, I guess that if not defined it will be ignored by Sequelize constructor.

Other changes, again not required:
.babelrc: useful for debug
.vscode/launch.json: debug startup for server and tests respectively

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

Successfully merging this pull request may close these issues.

1 participant