Skip to content

Commit 26cf6ea

Browse files
authored
Update Cypress to v12 (#1641)
Summary: Update Cypress from 9.x to 12.x, and perform all relevant migrations. Changes are the results of [10.0 migration](https://docs.cypress.io/guides/references/migration-guide#Migrating-to-Cypress-100), [11.0 migration](https://docs.cypress.io/guides/references/migration-guide#Migrating-to-Cypress-110), and [12.0 migration](https://docs.cypress.io/guides/references/migration-guide#Migrating-to-Cypress-120) guides. The reason for using `cypress.config.mjs` instead of `cypress.config.ts` is that the latter is not working with Yarn 3 yet ([1](cypress-io/cypress#24209), [2](cypress-io/cypress#22747), [3](cypress-io/cypress#25958)). If that changes, we can revisit. Notably, one of the larger changes is that test isolation is now on by default. This means the page is refreshed between each test rather than each suite, so some tests needed to be reconfigured to work with that paradigm. Cypress' UI has gotten a major refresh as well, so I changed the commands to account for it. Relevant Issues: N/A Type of change: /kind cleanup Test Plan: Follow instructions in `src/ui/cypress/README.md`. In particular, try `yarn run cypress:run:chrome`. All of the tests should pass, totally headlessly. Signed-off-by: Nick Lanam <nlanam@pixielabs.ai>
1 parent bb52f39 commit 26cf6ea

File tree

14 files changed

+102
-92
lines changed

14 files changed

+102
-92
lines changed

src/ui/.eslintrc.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
"src/testing/**/*"
102102
],
103103
"excludedFiles": [
104-
"cypress/**/*"
104+
"cypress/**/*",
105+
"cypress.config.mjs"
105106
],
106107
"env": {
107108
"node": true,
@@ -137,7 +138,8 @@
137138
"*.tsx"
138139
],
139140
"excludedFiles": [
140-
"cypress/**/*"
141+
"cypress/**/*",
142+
"cypress.config.mjs"
141143
],
142144
"extends": [
143145
"airbnb-typescript/base",

src/ui/cypress.config.mjs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2018- The Pixie Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
19+
import { defineConfig } from 'cypress';
20+
// import loadPlugins from 'plugins/index';
21+
22+
export default defineConfig({
23+
e2e: {
24+
specPattern: 'cypress/integration/**/*.spec.{js,jsx,ts,tsx}',
25+
supportFile: 'cypress/support/index.ts',
26+
baseUrl: 'https://dev.withpixie.dev',
27+
video: false, // Turn this on only if you are struggling to debug something, it only works locally and in Chrome.
28+
setupNodeEvents(on/*, config*/) {
29+
// Reduce motion
30+
on('before:browser:launch', (browser, launchOptions) => {
31+
if (browser.family === 'chromium') {
32+
if (browser.name === 'electron') {
33+
// Electron doesn't seem to have a setting for this.
34+
// https://www.electronjs.org/docs/latest/api/browser-window#new-browserwindowoptions
35+
// launchOptions.preferences.SOMETHING = true;
36+
} else {
37+
launchOptions.args.push('--force-prefers-reduced-motion');
38+
}
39+
} else if (browser.family === 'firefox') {
40+
launchOptions.preferences['ui.prefersReducedMotion'] = 1;
41+
}
42+
return launchOptions;
43+
});
44+
},
45+
},
46+
});

src/ui/cypress.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/ui/cypress/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ To run them, you need two things:
88
To get this, load the UI, open the dev tools, and look for the `default-sessionSOME_NUMBER` cookie. That is what you'll use to set `CYPRESS_GOOGLE_SESSION_COOKIE`.
99
The name of that cookie will set `CYPRESS_GOOGLE_SESSION_COOKIE_KEY`.
1010

11-
Then, run this command:
12-
`CYPRESS_BASE_URL='https://dev.withpixie.dev' CYPRESS_GOOGLE_SESSION_COOKIE_KEY='default-sessionSOME_NUMBER' CYPRESS_GOOGLE_SESSION_COOKIE='paste-your-session-cookie-value-here' yarn cypress:open`
11+
Then, run this command to access Cypress' UI:
12+
`CYPRESS_BASE_URL='https://dev.withpixie.dev' CYPRESS_GOOGLE_SESSION_COOKIE_KEY='default-sessionSOME_NUMBER' CYPRESS_GOOGLE_SESSION_COOKIE='paste-your-session-cookie-value-here' yarn cypress open`
1313

14-
You can use `... yarn cypress:run` instead if you want to run the tests immediately and headlessly.
14+
You can use `... yarn cypress:run:chrome` (or `... yarn cypress:run:firefox`) instead if you want to run the tests immediately and headlessly.
1515

1616
If you don't want to set these environment variables every time, you can override everything except the base URL in `cypress.env.json` (copy from `cypress.template.env.json`):
1717
```json

src/ui/cypress/integration/admin/api-and-deployment-keys.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,5 @@ function keyTests(prefix: string, url: string) {
129129
});
130130
}
131131

132-
keyTests('API', '/admin/api-keys');
133-
keyTests('Deployment', '/admin/deployment-keys');
132+
keyTests('API', '/admin/keys/api');
133+
keyTests('Deployment', '/admin/keys/deployment');

src/ui/cypress/integration/live/keyboard-shortcuts.spec.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ describe('Live view keyboard shortcuts', () => {
2424

2525
const modalTitle = 'Available Shortcuts';
2626

27-
// Note: this is a before, not a beforeEach.
28-
// Each test needs to close whatever its shortcut opened to reset properly and test that.
29-
before(() => {
27+
beforeEach(() => {
3028
cy.loginGoogle();
3129
cy.visit('/');
3230

@@ -36,10 +34,6 @@ describe('Live view keyboard shortcuts', () => {
3634
cy.wait('@exec-auto');
3735
});
3836

39-
beforeEach(() => {
40-
cy.loginGoogle();
41-
});
42-
4337
it('Opens shortcut help from profile menu', () => {
4438
cy.get('header.MuiPaper-root > .MuiToolbar-root > *:last-child').as('profile-menu-trigger');
4539
cy.get('@profile-menu-trigger').click();
@@ -62,13 +56,11 @@ describe('Live view keyboard shortcuts', () => {
6256
// Note: the way :nth-child works is weird; n+2 means "everything after the first child"
6357
cy.contains(modalTitle).parent().find('> div:nth-child(n+2)').as('rows');
6458
cy.get('@rows').should('have.length', 5);
65-
cy.get('@rows').within(() => {
66-
cy.contains('Show/hide script editor').should('exist');
67-
cy.contains('Show/hide data drawer').should('exist');
68-
cy.contains('Show/hide command palette').should('exist');
69-
cy.contains('Execute current Live View script').should('exist');
70-
cy.contains('Show all keyboard shortcuts').should('exist');
71-
});
59+
cy.get('@rows').contains('Show/hide script editor').should('exist');
60+
cy.get('@rows').contains('Show/hide data drawer').should('exist');
61+
cy.get('@rows').contains('Show/hide command palette').should('exist');
62+
cy.get('@rows').contains('Execute current Live View script').should('exist');
63+
cy.get('@rows').contains('Show all keyboard shortcuts').should('exist');
7264
cy.get('body').type('{esc}');
7365
cy.contains(modalTitle).should('not.exist');
7466
});

src/ui/cypress/integration/live/navbars.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ describe('Live View navbars', () => {
2424
before(() => {
2525
cy.loginGoogle();
2626
stubExecuteScript();
27-
cy.visit('/');
2827
});
2928

3029
beforeEach(() => {
3130
// Re-apply one-time intercepts each run.
3231
cy.loginGoogle();
3332
stubExecuteScript();
33+
cy.visit('/');
3434
cy.get('.MuiToolbar-root').as('topbar');
3535
});
3636

@@ -42,7 +42,7 @@ describe('Live View navbars', () => {
4242
it('Has the right contents', () => {
4343
cy.get('@topbar').should('exist').within(() => {
4444
cy.get('a[href="/"]').should('exist');
45-
cy.contains('Cluster:').find('+span').should(($span) => expect($span.text()).not.to.be.empty);
45+
cy.contains('cluster:').find('+span').should(($span) => expect($span.text()).not.to.be.empty);
4646
// Items that have tooltips: the share/edit/move/run buttons.
4747
// The sidebar expander also has an aria-label but isn't a Material tooltip.
4848
// The trigger for the Command Palette sets aria-label in the same way.

src/ui/cypress/integration/live/share-dialog.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Share dialog', () => {
4848
]);
4949
});
5050

51-
// TODO(nick,PC-1450): This only tests for a Google org; need to test email/password too.
51+
// TODO(NickLanam): This only tests for a Google org; need to test email/password too.
5252
cy.location('href').then((href) => {
5353
cy.get('@copy-to-clipboard').should('be.calledOnceWithExactly', href);
5454
});

src/ui/cypress/integration/live/sidebar-scripts.spec.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@
1919
import { stubExecuteScript, waitExecuteScript } from 'support/utils/grpc';
2020

2121
describe('Sidebar script shortcuts', () => {
22-
before(() => {
23-
cy.loginGoogle();
24-
stubExecuteScript().as('exec-auto');
25-
cy.visit('/');
26-
});
27-
2822
beforeEach(() => {
29-
// Once in before all for the auto exec;
23+
// Once for the auto exec;
3024
// Once each for the manual clicks that fire more requests.
3125
// Remember, Cypress intercepts only trigger once each by default.
3226
cy.loginGoogle();
27+
stubExecuteScript().as('exec-auto');
28+
cy.visit('/');
3329
});
3430

3531
it('Auto-runs cluster script before anything is pressed', () => {

src/ui/cypress/integration/unauthenticated/credits.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
*/
1818

1919
describe('Credits view', () => {
20-
// Only need to load the page once for this test suite.
21-
before(() => {
20+
beforeEach(() => {
2221
cy.visit('/credits');
2322
});
2423

0 commit comments

Comments
 (0)