-
Notifications
You must be signed in to change notification settings - Fork 1
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
mrc-4333 e2e tests #179
mrc-4333 e2e tests #179
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #179 +/- ##
==========================================
- Coverage 97.29% 97.16% -0.14%
==========================================
Files 150 150
Lines 1477 1479 +2
Branches 426 428 +2
==========================================
Hits 1437 1437
- Misses 39 41 +2
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Updates following last review The major changes were abandoning the
The other main change was to refactor the division of "local" and generic tests, which were previously matching on file name. Now there are tags for There are now three npm scripts in packit json:
I was going to include functionality to allow user to enter basic username and password interactively if not provided via environment variables, but stdin doesn't seem to be available in the auth.setup script (although I could get it to read input if I made a universal global setup). I presume something in Playwright is tampering with stdin. If it's useful, I can add that, in global setup, or in a separate node script but it's probably not worth it when we can just ask the user to set the variables! Various other changes from the review comments. Some detailed in replies, and also:
Testing The dev and prod scripts script are currently failing because the deployed main branch doesn't include the breadcrumb test id. To test running non-interactively with github login, run the You can test triggering the |
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 haven't re-read all of the test files themselves, only the surrounding infrastructure things. My main comment is to suggest a further bit of defence-in-depth to make triply sure we won't be mutating state on prod.
app/e2e/auth.setup.ts
Outdated
@@ -0,0 +1,93 @@ | |||
import { test as setup, expect, Page } from "@playwright/test"; |
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.
Should this import test
and expect
from tagCheckFixture instead?
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 am uncomfortable relying on developers to remember to check that they are importing 'test' from the correct place. Especially since IDEs often write imports for you. We could do something like the following, in a global setup script akin to auth.setup.js that is listed as a dependency for all test projects in playwright config:
function checkImports(filePath) {
const content = fs.readFileSync(filePath, 'utf-8');
const importRegex = /import\s+{[^}]*\btest\b[^}]*}\s+from\s+".\/tagCheckFixture";/;
if (!importRegex.test(content)) {
throw new Error(`Test file ${filePath} does not import 'test' from 'tagCheckFixture'.`);
}
}
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.
Don't think it really matters for the auth setup test but yeah, for the purposes of setting a good example let's do that!
checkImports
is a great idea. Actually, I'd be inclined to do that in auth.setup itself (possibly with a rename to reflect more generic concerns) as further defence, since people could still forget to include checkImports.setup.ts as a dependency, but their tests aren't going to get anywhere if they don't include the dep that does auth...
Co-authored-by: David Mears <[email protected]>
Co-authored-by: David Mears <[email protected]>
Co-authored-by: David Mears <[email protected]>
I've implemented the suggested The fs glob search is new and experimental in node 22 - I've updated the node version in CI. I've also updated the dev and prod urls now they're on proper subdomains, and also made sure the BASIC_AUTH variable is set in the dev-start script (it caused an error if running in github mode). |
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.
LGTM, just some minor bits
app/e2e/packetGroupPage.demo.spec.ts
Outdated
await expect(link).toHaveText(packetId); | ||
const expectedHref = getInstanceRelativePath(baseURL, `parameters/${packetId}`); | ||
await expect(await link.getAttribute("href")).toBe(expectedHref); | ||
// We expect servers we're testing on to have either GB or US locale. |
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 expect servers we're testing on to have either GB or US locale. | |
// We expect browsers we're testing on to have either GB or US locale. |
No? I'd be surprised if we did any date rendering server side. The JS should pick up the browser defaults.
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.
Actually you can set the locale in the playwright config, that should make this more reliable..
}; | ||
|
||
// Get a relative path which includes the packit instance, if any | ||
export const getInstanceRelativePath = (baseURL: string, path: string) => { |
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.
So as of last Friday we're now running all instances at the root path, meaning we could actually remove this function.
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.
Might just leave it in for now just in case we run any old style multi-tenancies again!
app/e2e/tagCheckFixture.ts
Outdated
export const TAG_DEMO_PACKETS = "@demoPackets"; | ||
|
||
const isLocal = (baseURL: string) => baseURL.startsWith("http://localhost"); | ||
const isDev = (baseURL: string) => baseURL.startsWith("https://packit-dev.dide.ic.ac.uk"); |
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 think this is broken now that the URL has changed. You would need to parse the URL, extract the domain name and check if that part ends in packit-dev.dide.ic.ac.uk
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.
Something like
const isDev = (baseURL: string) => baseURL.startsWith("https://packit-dev.dide.ic.ac.uk"); | |
const isDev = (baseURL: string) => new URL(baseURL).hostname.endsWith("https://packit-dev.dide.ic.ac.uk"); |
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.
Thanks, have added that.
Co-authored-by: Paul Liétar <[email protected]>
…ult e2e test script
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.
Thank you!
Perhaps the version of "@types/node" (package.json) wants to be kept in sync with the node version - it's still on 16.
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.
Sorry, just noticed app/Dockerfile has node 18 still as well. Also line 6 of app/README.md cites Node 18.
😱 So many node versions! Great spot! |
This branch adds some basic e2e tests, and the framework for running the tests, both locally and against any Packit server. Please see the changes to the top level README for details on how this works.
The index page, packet group page and parts of the packet page are tested.
Some other changes to note:
./scripts/run-e2e-tests-on-server
will run generic e2e tests on the specified server with specified auth method (basic or github). If github auth is required, it calls out to a python module,e2e_github_auth.py
, which in turn usespyorderly
to manage the github auth, and obtain a packit token. We then need to return this token to the bash script so it can set it as an environment variable which the playwright tests will use. Python scripts cannot set environment variables themselves (outside of the scope of their own copy of the environment) and also cannot return values to the calling script (other than return codes or values written to stdout, on which there is a lot of other chat during the auth process). So here the token is kludgily passed back to the calling script via writing out to a file.app/e2e/auth.setup.ts
does authentication according to the required method and credentials provided through environment variables. , or using default basic superuser and password. It is configured as a dependency of the main test projects inplaywright.config.ts
.This branch (which includes a couple of markup changes used by the tests) is deployed to packit-dev using the packit-infra PR here. You should be able to run the e2e tests against packit-dev by running:
There are separate tickets under the epic for testing:
We will also need to ensure that any future tests which change the state of the server e.g. running packets or changing user roles are not run on prod servers, but only on localhost or dev. (The tests in this branch are all read-only.).
Codecov is grumbling but there isn't any new untested code.