Optimal project layout for mocha integration test project

Viewed 15

I am creating a new Mocha integration test project that will house only tests, not product code, for a variety of products. The tests will share various functionality. These tests will be kicked off by product/subdirectory using CircleCI workflows. Essentially, the external "product A project" will want to kick off the A tests in the integration repo and push the test results someplace while the external "product B project" will kick off the B tests and push the results someplace else.

What I wondering is: what is the best project layout for this? I am new to Mocha and not that experienced with Circle CI so I thought I might benefit a lot from seeing if anyone has any opinions.

Here is a sample structure to go off of:

integrationTestProject
│   README.md
│   package.json    
│
└───.cirlceci
│   config.yml
│
└───productA
│   README.md
│   │
│   └───test
│       │   spec1.js
│       │   spec2.js
│       │   ...
│   
└───productB
│   README.md
│   │
│   └───test
│       │   spec3.js
│       │   spec4.js
│       │   ...
│
└───shared
│   index.js
│   │
│   └───sharedFunction1
│   │   │   auth.js
│   │   │   ...
│   │   
│   └───sharedFunction2
│       │   files.js
│       │   ...

Is there any issue with the shared directory being where it is? I am trying to avoid any complications with import paths not liking how many ".." sections are in there, etc.

Will running "mocha productB" do what I am expecting (just run those tests)?

1 Answers

This did work out to be fine. ../../shared imports worked fine and using index.js files worked (shared and sharedFunction1/sharedFunction2) but I had to add:

.mocharc.json

{
    "node-option": [
        "experimental-specifier-resolution=node"
    ]
}

in order to be able import from "../../common" in tests.

Related