-
Notifications
You must be signed in to change notification settings - Fork 33
chore(tests): Add initial full-journey tests #569
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
Conversation
…e scenario per file
👷 Deploy Preview for plugin-lighthouse processing.
|
@@ -8,7 +8,7 @@ | |||
"local-onsuccess": "RUN_ON_SUCCESS=true node -e 'import(\"./src/index.js\").then(index => index.default()).then(events => events.onSuccess());'", | |||
"lint": "eslint 'src/**/*.js'", | |||
"format": "prettier --write 'src/**/*.js'", | |||
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --collect-coverage", | |||
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --collect-coverage --maxWorkers=1", |
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.
We're currently not mocking express, so running multiple tests in parallel means we get domain conflicts. Adding this option runs tests sequentially (~4s total time at the moment). This could be a good follow-up issue to look into
@@ -53,7 +53,8 @@ | |||
"husky": "^8.0.1", | |||
"jest": "^29.0.0", | |||
"netlify-plugin-cypress": "^2.2.1", | |||
"prettier": "^2.0.0" | |||
"prettier": "^2.0.0", | |||
"strip-ansi": "^7.0.1" |
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.
Added to be able to more clearly compare log lines containing chalk colouring without needing to add the weird escape characters in our fixtures
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.
Most of these test runs follow a very similar format, other than for "success" based tests, I only mock console.error when testing that specifically, whereas "failure" based tests always need it mocked as we expect every test to throw a console error.
@@ -1,5 +1,3 @@ | |||
import chalk from 'chalk'; |
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 removed chalk from this file, as the generated strings are sent to the UI to be displayed – where we don't show color.
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.
lighthouse.js
was renamed to run-lighthouse.js
to avoid confusion when mocking 'lighthouse'.
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.
This is amaaaaaaazing 😍 So excited to have this level of testing! Love how clearly organised the mocks are ✨
This PR adds a lot of setup to enable e2e-style testing – including validating log lines written, data sent to backend, summaries surfaced in UI via plugin events.
It also includes a few initial tests to get a feel for the format. Currently they are one journey-type per file. Covered journeys are:
show
onPostBuild)show
onSuccess)show
onPostBuild)show
onSuccess)failBuild
onPostBuild)failPlugin
onSuccess)There is a lot of component mocking in place for these tests – Lighthouse, Chrome, Puppeteer. This reduced the test time from ~12s per test to ~12ms. We also mock console (log and error) to capture the content being output to build logs, but this can cause problems during testing as debugging logs get swallowed up too! Maybe in future we use a custom logging function which calls console.log/error or a mock function depending on live/test environment.
99% of the changes here are test-related files, within the
e2e
folder. Very little has changes in the plugin itself (a file name change, and some removed colors).