-
Notifications
You must be signed in to change notification settings - Fork 2
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
Doc/getting started working tests #59
base: master
Are you sure you want to change the base?
Conversation
```bash | ||
git clone [email protected]:wizeline/access-decision-manager.git | ||
``` | ||
2. Install the dependencies. We use [`npm ci`](https://docs.npmjs.com/cli/v8/commands/npm-ci) to ensure the same packages are installed on all machines. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question:
It wasn't clear to me where should I do this, first I did it at root level and then realized I had to do it also at the package level. Shouldn't this be handle by lerna? or should we just clarify that you need to cd to each package and run npm ci
too there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You "shouldn't need" to run npm ci
in the packages. Because the root package.json
file has "install": "lerna bootstrap"
, after running npm ci
NPM should call this post-install hook, which should output something like:
> root@undefined install /Users/mfarmer/Sites/wizeline/access-decision-manager
> lerna bootstrap
lerna notice cli v3.15.0
lerna info Bootstrapping 2 packages
lerna info Installing external dependencies
lerna info Symlinking packages and binaries
lerna success Bootstrapped 2 packages
added 1048 packages in 23.431s
With this we should now see child node_modules
folders:
$ ls packages/access-decision-manager-express/node_modules
@wizeline http-status-codes
If you run for f in
find . -name 'node_modules'; do rm -rf $f; done
it will remove all child node_module
folders, and I think running these instructions should get the tests to all work just fine.
It's possible I'm missing something you are trying to do here, so maybe you could run these commands and then post the error you are seeing and I could better understand.
I think we should move to something like turborepo/nx, etc, and so hopefully these lerna difficulties will go away then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I managed to replicate it by removing the node_modules and running again npm ci
and then npm test
.
I do get the same lerna bootstrap message and dependencies installed:
> install
> lerna bootstrap
lerna notice cli v3.15.0
lerna info Bootstrapping 2 packages
lerna info Installing external dependencies
lerna info Symlinking packages and binaries
lerna success Bootstrapped 2 packages
added 1048 packages, and audited 1115 packages in 15s
but then this test fails:
● Test suite failed to run
Cannot find module '@wizeline/access-decision-manager' from 'access-decision-manager-provider.test.ts'
1 | // eslint-disable-next-line import/no-extraneous-dependencies
2 | import { Request } from 'express';
> 3 | import AccessDecisionManager from '@wizeline/access-decision-manager';
| ^
then I do the following to fix it:
cd packages/access-decision-manager-express
npm ci
added 2 packages, and audited 3 packages in 1s
found 0 vulnerabilities
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, this fixes the error
diff --git a/packages/access-decision-manager-express/src/__tests__/access-decision-manager-provider.test.ts b/packages/access-decision-manager-express/src/__tests__/access-decision-manager-provider.test.ts
index 0972bc9..9c93551 100644
--- a/packages/access-decision-manager-express/src/__tests__/access-decision-manager-provider.test.ts
+++ b/packages/access-decision-manager-express/src/__tests__/access-decision-manager-provider.test.ts
@@ -1,6 +1,6 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { Request } from 'express';
-import AccessDecisionManager from '@wizeline/access-decision-manager';
+import AccessDecisionManager from '../../../access-decision-manager/src';
import AccessDecisionManagerProvider from '../access-decision-manager-provider';
describe('src', () => {
diff --git a/packages/access-decision-manager-express/src/access-decision-manager-provider.ts b/packages/access-decision-manager-express/src/access-decision-manager-provider.ts
index 9694602..9fa806b 100644
--- a/packages/access-decision-manager-express/src/access-decision-manager-provider.ts
+++ b/packages/access-decision-manager-express/src/access-decision-manager-provider.ts
@@ -1,6 +1,6 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { NextFunction, Request, Response } from 'express';
-import AccessDecisionManager, { Voter } from '@wizeline/access-decision-manager';
+import AccessDecisionManager, { Voter } from '../../../packages/access-decision-manager/src';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type ADMArgumentFactory = (req: Request) => any;
but that it's not what we want to do, I will check the real solution but this was working in our latest CI/CD -> https://app.travis-ci.com/ (check this out)
What does this PR do?
Add instructions to run tests from root project
Why is this important?
Newcomers to the project will have an easier time if they can run the tests. This will also help us keep a standard where only working commits can be merged.
Where should the reviewer start?
README.md
How should this be manually tested?
node_modules
folders:README.md
file to ensure that you can run the testsType of change
Checklist