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

test: add e2e tests for CTB restarts from file changes #19801

Merged
merged 29 commits into from Apr 4, 2024

Conversation

innerdvations
Copy link
Contributor

@innerdvations innerdvations commented Mar 16, 2024

What does it do?

  • adds e2e test for creating a collection type and that the ctb tutorial modal appears
  • adds util to watch for the server restart
  • adds util to help ignore the ctb tutorial modal
  • adds a very hacky test framework and util for resetting the filesystem state after changes like CTB edits, uploads, etc
  • minor refactoring and docs

I'm not super happy with how hacky it is, but it seems stable enough from the time I've been working with it. The most important thing I would like to find a solution for is the delay() to wait for the server to realize files have changed and it begins its restart process. However, without access to the output of the server I can't think of anything better. Perhaps a custom winston logger could pipe it somewhere that we could watch that would be realtime?

Why is it needed?

We were limited by being unable to test the CTB because of the server restarts, filesystem changes, etc.

Roadmap

After this PR, I am planning the following changes:

  • bring CLI tests from v5/main to develop (and then work from there on further changes)
  • copy/paste and clean up first attempt at CTB tests from chore(e2e): CTB end-to-end tests #18065
  • refactor e2e+cli tests to share code, ideally everything except the test runner itself (jest vs playwright command)
  • lots of other little cleanups, like improving the restart monitoring being added here

How to test it?

Running the full test suite with multiple browsers (that is, re-using the same running instance of strapi across multiple test runs of the same suite, and re-using the test-apps between runs ie without using --setup) should work every time. And continuing to run them many times in a row, they should always succeed without flakiness.

Related issue(s)/PR(s)

DX-1166

@innerdvations innerdvations added source: tooling Source is GitHub tooling/tests/ect pr: chore This PR contains chore tasks (cleanups, configs, tooling...) labels Mar 16, 2024
@innerdvations innerdvations self-assigned this Mar 16, 2024
@innerdvations innerdvations marked this pull request as draft March 18, 2024 08:07
@innerdvations innerdvations removed the request for review from joshuaellis March 18, 2024 08:07
Copy link

vercel bot commented Mar 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
contributor-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 4, 2024 10:59am

@innerdvations innerdvations changed the title test: add e2e tests for CTB test: add e2e tests for CTB (proof of concept) Mar 19, 2024
@alexandrebodin
Copy link
Member

FYI there is also this historical PR with a bunch of good tests #18065

@innerdvations innerdvations added the flag: don't merge This PR should not be merged at the moment label Mar 20, 2024
@innerdvations
Copy link
Contributor Author

innerdvations commented Apr 2, 2024

I'm going ahead and opening this PR as-is with the delay() giving strapi time to detect file changes and restart. While it could technically be flakey, I haven't seen it fail in about 5 runs on github so far, and never locally either with many more runs.

I'm very open to better ideas, but trying to watch the logs for the restart / started also feels overly complicated and potentially flakey as well.

@innerdvations innerdvations marked this pull request as ready for review April 2, 2024 15:37
@innerdvations innerdvations changed the title test: add e2e tests for CTB test: add e2e tests for CTB restarts from file changes Apr 2, 2024
Copy link
Member

@joshuaellis joshuaellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great, well done for cracking this, super hard stuff. Just some minor comments to discuss

tests/e2e/scripts/dts-import.js Outdated Show resolved Hide resolved
// TODO: each test should have a beforeAll that does this, maybe combine all the setup into one util to simplify it
// to keep other suites that don't modify files from needing to reset files, clean up after ourselves at the end
test.afterAll(async () => {
await resetFiles();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you doing it afterAll but also in beforeEach? Maybe it should be in afterEach instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a tricky question here.

In this file, the correct thing would be only the beforeEach (since each test makes changes) and then other suites would ensure on their own it was clean with a beforeAll/beforeEach as needed. But doing the filesystem reset is slow and only a couple suites make file changes (ctb and uploading), and I didn't want to update every other test file to do that.

So I put the "bad" code (trying to clean up for other tests in afterAll is bad practice because you're not guaranteed it will run) separate even though it means we run it one extra time, because ultimately I want to remove it altogether once we have a faster method to detect/reset the files that would be ok to add universally.

@joshuaellis
Copy link
Member

V nice well done

@innerdvations
Copy link
Contributor Author

V nice well done

not quite, one of the runs failed 😞

I think I have another solution though that I'll try to run through the CI several times and see if it still happens

@innerdvations innerdvations merged commit 5ab818b into develop Apr 4, 2024
31 checks passed
@innerdvations innerdvations deleted the chore/e2e-ctb-tests branch April 4, 2024 16:55
@echoes-hq echoes-hq bot added the echoes/type: maintenance/testing For tests written to support improved automation QA label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes/type: maintenance/testing For tests written to support improved automation QA pr: chore This PR contains chore tasks (cleanups, configs, tooling...) source: tooling Source is GitHub tooling/tests/ect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants