wisemen-digital / devops-github-actions

GNU General Public License v3.0
0 stars 1 forks source link

Node test setup isn't exectuted #7

Closed siemenvdn closed 3 months ago

siemenvdn commented 3 months ago

Refs: ENG-1724

For NestJS projects, we need to pre-run a single setup file before all tests start. We included this in the pnpm test command. So if the current tests are ran with node --test, those files won't be executed. Which results in all failing tests. We could provide a pnpm test:pipeline command where we'll add the --test-reporter=tap --test-reporter-destination=stdout --test-reporter=junit --test-reporter-destination=\"test-report-junit.xml\" since we like to use the spec test-reporter locally.

Then the cp -f '.env.test' '.env' command could also be forgotten about, since we already specify that the node-tests should use the .env.test

siemenvdn commented 3 months ago

I've created a PR for the desired changes. I'll take the responsibility to include the new commands in the project-template, and notify circle-node of these changes.

djbe commented 3 months ago

No I'd avoid y'all writing devops stuff in all your package.json. It is EXTREMELY limiting to us if we need to change it because we're changing actions, splitting stuff up, optimising stuff, etc…

Honestly I'm more interested in moving some current/existing pnpm lint and pnpm build to their actual node commands, so we can optimize them as needed.

djbe commented 3 months ago
siemenvdn commented 3 months ago

That wouldn't be ideal, our framework already handles alot of setup/teardown, but it doesnt provide a functionality to run a single file before all tests are executed.

The problem is that they're sharing a Typesense instance, if we'd include that setup in our test setup they'd all try to initialise the same instance at the same time. Which results in alot of errors.

If it would be included in a new step it would also be sufficient. There is no way to handle this on our end except running a setup script/command.

jorenvandeweyer commented 3 months ago

I suggest leaving things as be.

But, since tests suites run in parallel, which means any test suite can be the first. There needs to be a global setup hook for db migrations and other things that need to be run before the tests.

What do you suggest? @djbe

djbe commented 3 months ago

Like I said, tell us which script we should execute before actually running the tests, to set-up the services. We can check if the path exists, so it doesn't fail on older projects.

siemenvdn commented 3 months ago

@djbe The global-setup file will be placed at path dist/src/utils/test-setup/global-setup.js.

djbe commented 3 months ago

@siemenvdn added a check to see if the file exists, and then runs it: https://github.com/wisemen-digital/devops-github-actions/blob/main/.github/workflows/node-build-and-test.yml#L193-L195