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

#39 add basic behaviour tests #43

Merged
merged 6 commits into from
Sep 27, 2023

Conversation

bofalke
Copy link
Contributor

@bofalke bofalke commented Aug 1, 2023

Ref #39

@bofalke
Copy link
Contributor Author

bofalke commented Aug 1, 2023

Took forever to get Cucumber working with typescript and our project structure but finally found some good guides and explanations on how to configure cucumber properly.

I installed https://github.com/timjroberts/cucumber-js-tsflow for the typescript integration, i hope that is fine

package.json Outdated Show resolved Hide resolved
@bofalke bofalke force-pushed the 39-add-basic-behaviour-tests branch 2 times, most recently from 2101356 to c7a203f Compare August 2, 2023 07:30
@bofalke
Copy link
Contributor Author

bofalke commented Aug 2, 2023

I was finally able to add a first version of a test

When i run npm run test-scenarios i get the following issue:

Error: Cannot find module '@app/shared/commands/fleet-management/add-car-to-fleet'

I guess the AddCarToFleetSteps.ts is not properly loaded. Probably a small typescript configuration which is not as clear to me currently :D

Also this first attempt would only check if the command handler yields the correct event. Better approach would be to test a little bit more from the outside and check if the command will trigger and store an event in the "database".

@codeliner
Copy link
Contributor

@bofalke I think the error is related to the fact that the namespace is not known within your script. Unfortunately, we have to use the helper package tsconfig-paths/register to tell TS about our namespaces defined in the root tsconfig.

Here you find the command the starts the backend server using ts-node: https://github.com/proophboard/cody-engine/blob/main/packages/be/nodemon.json#L5

As you can see, the helper is passed to ts-node so that the namespaces get registered. You have to do the same when executing cucumber.

@codeliner
Copy link
Contributor

Also this first attempt would only check if the command handler yields the correct event. Better approach would be to test a little bit more from the outside and check if the command will trigger and store an event in the "database".

You should set the env variable NODE_ENV to test if this is not already done by cucumber (Jest does it by default).
Then you can create an environment.test.ts file in the environments folder

Set event store and document store adapter to "memory", so that the default case is triggered and you get back an in-memory event store and document store from the factory functions: getConfiguredEventStore and getConfiguredDocumentStore

Cody Engine will use them during test run and you can check streams and documents afterwards for events and state.

@bofalke bofalke force-pushed the 39-add-basic-behaviour-tests branch from c7a203f to 91dafc3 Compare September 6, 2023 11:58
@bofalke
Copy link
Contributor Author

bofalke commented Sep 6, 2023

@bofalke I think the error is related to the fact that the namespace is not known within your script. Unfortunately, we have to use the helper package tsconfig-paths/register to tell TS about our namespaces defined in the root tsconfig.

Here you find the command the starts the backend server using ts-node: https://github.com/proophboard/cody-engine/blob/main/packages/be/nodemon.json#L5

As you can see, the helper is passed to ts-node so that the namespaces get registered. You have to do the same when executing cucumber.

To be honest i was not able to figure this out... I added a tsconfig.json in the features folder that extends the one in the be folder. So shouldn't it be loaded? The example you provided seems to be related to nodemon and references a main.ts, how would that work with my example? I have the issue, that i just don't know exactly what i need to actually register, the features folder into the rest of the project or vice versa. If i just extend the cucumber script in the be/package.json to :

"scripts": {
    "cucumber": "npx ts-node -r tsconfig-paths/register src/main.ts cucumber-js -p default"
  }

I get the error:

/home/bfalke/projects/cody-engine/packages/be/src/extensions/get-external-service.ts:17
    throw new Error(`Service "${name}" is not registered in @extensions/be/services`);
          ^

@codeliner
Copy link
Contributor

@bofalke That's not the same error as you got before, right? So I think the original error got solved :D
A not registered service might have to do with a recent change in Cody Engine. A default AuthService has been added to the system, which needs to be registered in packages/be/src/extensions/services.ts. See services.ts.cetmpl

@bofalke bofalke force-pushed the 39-add-basic-behaviour-tests branch 3 times, most recently from 1e2fde6 to 6da17da Compare September 19, 2023 14:42
@bofalke bofalke force-pushed the 39-add-basic-behaviour-tests branch from 6da17da to 4431130 Compare September 19, 2023 14:42
@bofalke bofalke changed the base branch from main to 45-add-hooks-for-tests September 27, 2023 14:01
@kaitorched kaitorched force-pushed the 45-add-hooks-for-tests branch from b4b103d to 9afd540 Compare September 27, 2023 14:02
@bofalke bofalke changed the title Draft: 39 add basic behaviour tests 39 add basic behaviour tests Sep 27, 2023
@bofalke bofalke changed the title 39 add basic behaviour tests #39 add basic behaviour tests Sep 27, 2023
@bofalke bofalke marked this pull request as ready for review September 27, 2023 14:03
@bofalke bofalke merged commit d45b5fa into 45-add-hooks-for-tests Sep 27, 2023
@bofalke bofalke deleted the 39-add-basic-behaviour-tests branch September 27, 2023 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants