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

Mock dexie #664

Closed
raineorshine opened this issue May 16, 2020 · 3 comments · Fixed by #778
Closed

Mock dexie #664

raineorshine opened this issue May 16, 2020 · 3 comments · Fixed by #778
Assignees
Labels
test Testing and project configuration

Comments

@raineorshine
Copy link
Contributor

raineorshine commented May 16, 2020

I was not able to successfully mock dexie in setupTests.js. I tried conditionally mocking within db.js itself, which fixes initDB, but the tests still fail. All db calls have to be ignored until this is solved.

if (process.env.NODE_ENV === 'test') {
  Dexie.dependencies.indexedDB = require('fake-indexeddb')
  Dexie.dependencies.IDBKeyRange = require('fake-indexeddb/lib/FDBKeyRange')
}

Based on dexie/Dexie.js#495 (comment)

Also tried this to no avail:

require('fake-indexeddb/auto')
@raineorshine raineorshine added the test Testing and project configuration label May 16, 2020
@raineorshine raineorshine changed the title Fix unit tests and clear warnings Mock dexie May 24, 2020
@TiagoSilvaPereira
Copy link

I'm with problems too trying to mock using fake-indexeddb:

TypeError: Cannot read property 'all' of undefined
    at snapShot (/home/kingofcode/code/tools/pistache/dist/js/webpack:/node_modules/dexie/dist/dexie.es.js:1307:1)
    at Module../node_modules/dexie/dist/dexie.es.js (/home/kingofcode/code/tools/pistache/dist/js/webpack:/node_modules/dexie/dist/dexie.es.js:835:1)
    at __webpack_require__ (/home/kingofcode/code/tools/pistache/dist/js/webpack:/webpack/bootstrap:19:1)
    at Object../tests/unit/base/Seeder.js (/home/kingofcode/code/tools/pistache/dist/js/webpack:/tests/unit/base/Seeder.js:1:1)
    at __webpack_require__ (/home/kingofcode/code/tools/pistache/dist/js/webpack:/webpack/bootstrap:19:1)
    at Object../tests/unit/schema/relationships.spec.js (/home/kingofcode/code/tools/pistache/dist/js/webpack:/tests/unit/schema/relationships.spec.js:2:1)
    at __webpack_require__ (/home/kingofcode/code/tools/pistache/dist/js/webpack:/webpack/bootstrap:19:1)
    at run (/home/kingofcode/code/tools/pistache/dist/js/webpack:/node_modules/mochapack/lib/entry.js:3:1)
    at Array.forEach (<anonymous>)
    at Object../node_modules/mochapack/lib/entry.js (/home/kingofcode/code/tools/pistache/dist/js/webpack:/node_modules/mochapack/lib/entry.js:10:1)
    at __webpack_require__ (/home/kingofcode/code/tools/pistache/dist/js/webpack:/webpack/bootstrap:19:1)
    at /home/kingofcode/code/tools/pistache/dist/js/webpack:/webpack/bootstrap:83:1
    at Object.<anonymous> (/home/kingofcode/code/tools/pistache/dist/js/main.js:87:10)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object._module2.default._extensions.<computed> [as .js] (/home/kingofcode/code/tools/pistache/node_modules/mochapack/src/util/registerRequireHook.js:99:12)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at /home/kingofcode/code/tools/pistache/node_modules/mocha/lib/mocha.js:334:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/home/kingofcode/code/tools/pistache/node_modules/mocha/lib/mocha.js:331:14)
    at Mocha.run (/home/kingofcode/code/tools/pistache/node_modules/mocha/lib/mocha.js:809:10)
    at cb (/home/kingofcode/code/tools/pistache/node_modules/mochapack/src/runner/TestRunner.js:96:21)
    at /home/kingofcode/code/tools/pistache/node_modules/mochapack/src/webpack/compiler/registerReadyCallback.js:12:7
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/kingofcode/code/tools/pistache/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:43:1)
    at AsyncSeriesHook.lazyCompileHook (/home/kingofcode/code/tools/pistache/node_modules/tapable/lib/Hook.js:154:20)
    at /home/kingofcode/code/tools/pistache/node_modules/webpack/lib/Compiler.js:304:22
    at Compiler.emitRecords (/home/kingofcode/code/tools/pistache/node_modules/webpack/lib/Compiler.js:499:39)
    at /home/kingofcode/code/tools/pistache/node_modules/webpack/lib/Compiler.js:298:10
    at /home/kingofcode/code/tools/pistache/node_modules/webpack/lib/Compiler.js:485:14
    at eval (eval at create (/home/kingofcode/code/tools/pistache/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)
    at /home/kingofcode/code/tools/pistache/node_modules/copy-webpack-plugin/dist/index.js:115:7
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/kingofcode/code/tools/pistache/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at AsyncSeriesHook.lazyCompileHook (/home/kingofcode/code/tools/pistache/node_modules/tapable/lib/Hook.js:154:20)
    at /home/kingofcode/code/tools/pistache/node_modules/webpack/lib/Compiler.js:482:27
    at /home/kingofcode/code/tools/pistache/node_modules/neo-async/async.js:2818:7
    at done (/home/kingofcode/code/tools/pistache/node_modules/neo-async/async.js:3522:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/kingofcode/code/tools/pistache/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:4:1)
    at /home/kingofcode/code/tools/pistache/node_modules/webpack/lib/Compiler.js:464:33
    at MemoryFileSystem.writeFile (/home/kingofcode/code/tools/pistache/node_modules/memory-fs/lib/MemoryFileSystem.js:328:9)
    at writeOut (/home/kingofcode/code/tools/pistache/node_modules/webpack/lib/Compiler.js:462:30)
    at Immediate._onImmediate (/home/kingofcode/code/tools/pistache/node_modules/memory-fs/lib/MemoryFileSystem.js:288:4)
    at processImmediate (internal/timers.js:456:21)
    at process.topLevelDomainCallback (domain.js:137:15)

 ERROR  mochapack exited with code 1.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! pistache@0.1.0 test:unit: `vue-cli-service test:unit`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the pistache@0.1.0 test:unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/kingofcode/.npm/_logs/2020-06-04T19_27_47_537Z-debug.log

@raineorshine
Copy link
Contributor Author

@shresthabijay Could you take a stab at this? If we can mock dexie then we can expand our test coverage to include the local db.

@shresthabijay
Copy link
Collaborator

@shresthabijay Could you take a stab at this? If we can mock dexie then we can expand our test coverage to include the local db.

Sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Testing and project configuration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants