thenativeweb / node-cqrs-domain

Node-cqrs-domain is a node.js module based on nodeEventStore that. It can be very useful as domain component if you work with (d)ddd, cqrs, eventdenormalizer, host, etc.
http://cqrs.js.org/pages/domain.html
MIT License
269 stars 57 forks source link

How to use domainPath in unit tests #141

Closed bikerp closed 5 years ago

bikerp commented 5 years ago

Hi, I'm trying to write unit tests for commands. My directory structure is following:

`|-- src
 |   |-- domain
 |       `-- lib
 |           `-- item
 |               |-- aggregate.js 
 |               |-- command.js 
 |               `-- event.js
  `-- tests
       `-- test.js

The issue is that referencing the item folder from tests folder doesn't work if in test.js i have: const domain = require('cqrs-domain')({ domainPath: path.join(__dirname, '../src/domain/lib') }); I have checked the examples in integrationTests but I don't think I'm doing anything wrong. Thanks for any help

nanov commented 5 years ago

Depending on your environment, you could try using :

path.join(process.cwd(), './src/whenever/you/might/need')
bikerp commented 5 years ago

I tried but the result is the same. I still get the error message ' No structure loaded for ...!'

nanov commented 5 years ago

In order to be able to provide more detailed help I would need a test repro which demonstrates the problem.

Hints:

bikerp commented 5 years ago

I have forked the cqrs-sample project and set up the tests. The repo is here https://github.com/bikerp/cqrs-sample I think I found the issue. If the folder src/domain contains node_modules then the test fails with the mentioned error. If I delete the node_modules folder the the test succeed

bikerp commented 5 years ago

@nanov Any idea what could cause the issue?

nanov commented 5 years ago

You did answer yourself, I guess you would have to introduce another folder layer in order for this to work.

bikerp commented 5 years ago

Ok, so when I require 'cqrs-domain' package directly from the tested folder and it works. Thanks