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

Jest or Mocha tests fail if file execution order changes #1550

Closed
tuhlmann opened this issue Sep 8, 2019 · 1 comment
Closed

Jest or Mocha tests fail if file execution order changes #1550

tuhlmann opened this issue Sep 8, 2019 · 1 comment

Comments

@tuhlmann
Copy link

@tuhlmann tuhlmann commented Sep 8, 2019

Steps to reproduce

  • Use the generator to create a feathers app with the following options:
    • Typescript
    • npm
    • Sequalize & sqlite3 // name of db: test_sqlite.sqlite
    • Rest & Socket.io
    • Has Authentication
    • name if users service and model is users
    • change "jest" script in package.json to remove the test database:
      "jest": "shx rm -f ./test_sqlite.sqlite && jest --forceExit"

I tested with Jest and Mocha.

  • Tell us what broke. The more detailed the better.

The tests only run if app.test.ts runs first and creates the users schema. In the cases (and Jest seems to change the order of execution of the files) when authentication.test.ts runs first, the execution fails with the following error msg:

> shx rm -f ./test_sqlite.sqlite && jest --forceExit

PASS  test/services/users.test.ts                           
FAIL  test/authentication.test.ts
- authentication › local strategy › authenticates user and creates accessToken                                                                                                                                                                    

GeneralError: SQLITE_ERROR: no such table: users                                                                     

As a Feather's newbie, what's the best way to initialize the database and add a beforeAll and afterAll call to make sure the db is always provided?

Ideally, the generator should create this code in future versions.

Thanks!

Expected behavior

Generated tests should always pass

Actual behavior

Tests only pass is app.test.ts is called first.

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working):

  • Feathers 4.3.0
  • Jest 24.9.0
  • Typescript 3.6.2
  • Sequelize 5.18.3
  • Sqlite2 4.1.0

NodeJS version:
v10.16.3

Operating System:
Ubuntu 18.04 in WSL for Windows 10

Module Loader: commonjs

@tuhlmann
Copy link
Author

@tuhlmann tuhlmann commented Sep 8, 2019

To solve the problem,

I added an app.setup() at the top of my Jest test files:

import app from "../src/server/app"

beforeAll(() => {
  app.setup()
})

...
@daffl daffl closed this Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.