Skip to content

Commit

Permalink
fix: Determine global mode based on whether there is a current project (
Browse files Browse the repository at this point in the history
#22838)

Co-authored-by: Mark Noonan <mark@cypress.io>
  • Loading branch information
chrisbreiding and marktnoonan authored Jul 19, 2022
1 parent 2aa7b93 commit 1da95a7
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 20 deletions.
17 changes: 7 additions & 10 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mainBuildFilters: &mainBuildFilters
branches:
only:
- develop
- issue-22147-nohoist
- global-mode-issue

# usually we don't build Mac app - it takes a long time
# but sometimes we want to really confirm we are doing the right thing
Expand All @@ -36,8 +36,7 @@ macWorkflowFilters: &darwin-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ linux-arm64, << pipeline.git.branch >> ]
- equal: [ 'tbiethman/UNIFY-1816-prototype', << pipeline.git.branch >> ]
- equal: [ 'global-mode-issue', << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand All @@ -46,7 +45,6 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ linux-arm64, << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand All @@ -65,7 +63,6 @@ windowsWorkflowFilters: &windows-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ linux-arm64, << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand Down Expand Up @@ -129,7 +126,7 @@ commands:
- run:
name: Check current branch to persist artifacts
command: |
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "tbiethman/UNIFY-1816-prototype" ]]; then
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "global-mode-issue" ]]; then
echo "Not uploading artifacts or posting install comment for this branch."
circleci-agent step halt
fi
Expand Down Expand Up @@ -658,7 +655,7 @@ commands:
## by default, assert that at least 1 test ran
default: 0
steps:
- run:
- run:
name: 'Verify Mocha Results'
command: |
source ./scripts/ensure-node.sh
Expand Down Expand Up @@ -1614,7 +1611,7 @@ jobs:
path: /tmp/cypress
- store_artifacts:
path: /tmp/artifacts
- store-npm-logs
- store-npm-logs

run-vite-dev-server-integration-tests:
<<: *defaults
Expand All @@ -1636,7 +1633,7 @@ jobs:
path: /tmp/cypress
- store_artifacts:
path: /tmp/artifacts
- store-npm-logs
- store-npm-logs

ui-components-integration-tests:
<<: *defaults
Expand Down Expand Up @@ -2363,7 +2360,7 @@ linux-x64-workflow: &linux-x64-workflow
- run-vite-dev-server-integration-tests:
context: [test-runner:cypress-record-key, test-runner:percy]
requires:
- system-tests-node-modules-install
- system-tests-node-modules-install
- run-app-component-tests-chrome:
context: [test-runner:cypress-record-key, test-runner:launchpad-tests, test-runner:percy]
percy: true
Expand Down
6 changes: 6 additions & 0 deletions cli/lib/exec/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const { exitWithError } = require('../errors')
* @returns {string[]} list of CLI arguments
*/
const processOpenOptions = (options = {}) => {
// In addition to setting the project directory, setting the project option
// here ultimately decides whether cypress is run in global mode or not.
// It's first based off whether it's installed globally by npm/yarn (-g).
// A global install can be overridden by the --project flag, putting Cypress
// in project mode. A non-global install can be overridden by the --global
// flag, putting it in global mode.
if (!util.isInstalledGlobally() && !options.global && !options.project) {
options.project = process.cwd()
}
Expand Down
17 changes: 13 additions & 4 deletions packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import execa from 'execa'

import type { CyTaskResult, RemoteGraphQLInterceptor, ResetOptionsResult, WithCtxInjected, WithCtxOptions } from './support/e2eSupport'
import type { CyTaskResult, OpenGlobalModeOptions, RemoteGraphQLInterceptor, ResetOptionsResult, WithCtxInjected, WithCtxOptions } from './support/e2eSupport'
import { fixtureDirs } from '@tooling/system-tests'
// import type { CloudExecuteRemote } from '@packages/data-context/src/sources'
import { makeGraphQLServer } from '@packages/graphql/src/makeGraphQLServer'
Expand Down Expand Up @@ -86,6 +86,7 @@ async function makeE2ETasks () {
const { scaffoldCommonNodeModules, scaffoldProjectNodeModules } = require('@tooling/system-tests/lib/dep-installer')

const cli = require('../../../../cli/lib/cli')
const cliUtil = require('../../../../cli/lib/util')
const cliOpen = require('../../../../cli/lib/exec/open')

// Remove all the fixtures when the plugin starts
Expand Down Expand Up @@ -288,12 +289,18 @@ async function makeE2ETasks () {
return Fixtures.projectPath(opts.projectName)
},
__internal_scaffoldProject,
async __internal_openGlobal (argv: string[] = []): Promise<ResetOptionsResult> {
const openArgv = ['--global', ...argv]
async __internal_openGlobal ({ argv = [], byFlag = true }: OpenGlobalModeOptions): Promise<ResetOptionsResult> {
let isInstalledGloballyStub

if (byFlag) {
argv.unshift('--global')
} else {
isInstalledGloballyStub = sinon.stub(cliUtil, 'isInstalledGlobally').returns(true)
}

// Runs the launchArgs through the whole pipeline for the CLI open process,
// which probably needs a bit of refactoring / consolidating
const cliOptions = await cli.parseOpenCommand(['open', ...openArgv])
const cliOptions = await cli.parseOpenCommand(['open', ...argv])
const processedArgv = cliOpen.processOpenOptions(cliOptions)
const modeOptions = { ...argUtils.toObject(processedArgv), invokedFromCli: true }

Expand All @@ -303,6 +310,8 @@ async function makeE2ETasks () {
// Handle any pre-loading that should occur based on the launch arg settings
await ctx.initializeMode()

isInstalledGloballyStub?.restore()

return {
modeOptions,
e2eServerPort: ctx.appServerPort,
Expand Down
9 changes: 7 additions & 2 deletions packages/frontend-shared/cypress/e2e/support/e2eSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,14 @@ export interface ResetOptionsResult {
e2eServerPort?: number | null
}

function openGlobalMode (argv?: string[]) {
export interface OpenGlobalModeOptions {
argv?: string[]
byFlag?: boolean
}

function openGlobalMode (options: OpenGlobalModeOptions = {}) {
return logInternal({ name: 'openGlobalMode', message: '' }, () => {
return taskInternal('__internal_openGlobal', argv)
return taskInternal('__internal_openGlobal', options)
}).then((obj) => {
Cypress.env('e2e_serverPort', obj.e2eServerPort)

Expand Down
4 changes: 3 additions & 1 deletion packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,9 @@ type Query {
"""
invokedFromCli: Boolean!

"""Whether the app is in global mode or not"""
"""
Whether the app is in global mode or not. This is based off the presence of a project, which is set by the CLI (or absent if the app is run directly). See cli/lib/exec/open.js for the logic that sets the project or not.
"""
isGlobalMode: Boolean!

"""local settings on a device-by-device basis"""
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/schemaTypes/objectTypes/gql-Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export const Query = objectType({
})

t.nonNull.boolean('isGlobalMode', {
description: 'Whether the app is in global mode or not',
resolve: (source, args, ctx) => Boolean(ctx.modeOptions.global),
description: 'Whether the app is in global mode or not. This is based off the presence of a project, which is set by the CLI (or absent if the app is run directly). See cli/lib/exec/open.js for the logic that sets the project or not.',
resolve: (source, args, ctx) => !ctx.modeOptions.project,
})

t.nonNull.field('authState', {
Expand Down
16 changes: 15 additions & 1 deletion packages/launchpad/cypress/e2e/global-mode.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ import { getPathForPlatform } from './support/getPathForPlatform'
const sep = Cypress.platform === 'win32' ? '\\' : '/'

describe('Launchpad: Global Mode', () => {
describe('methods of opening global mode', () => {
it('shows global page when opened by --global flag', () => {
cy.openGlobalMode()
cy.visitLaunchpad()
cy.get('h1').should('contain', defaultMessages.globalPage.empty.title)
})

it('shows global page when opened by global install', () => {
cy.openGlobalMode({ byFlag: false })
cy.visitLaunchpad()
cy.get('h1').should('contain', defaultMessages.globalPage.empty.title)
})
})

describe('when no projects have been added', () => {
it('shows "Add Project" view', () => {
cy.openGlobalMode()
Expand Down Expand Up @@ -71,7 +85,7 @@ describe('Launchpad: Global Mode', () => {

describe('when projects have been added', () => {
const setupAndValidateProjectsList = (projectList, globalModeOptions?: string[] | undefined) => {
cy.openGlobalMode(globalModeOptions)
cy.openGlobalMode({ argv: globalModeOptions })

// Adding a project puts the project first in the list, so we reverse the list
// to ensure the projectList in the UI matches what is passed in.
Expand Down

5 comments on commit 1da95a7

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1da95a7 Jul 19, 2022

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.1/linux-x64/develop-1da95a7db1317bd6c66a7d9bf6ba6f8dd5b7d620/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1da95a7 Jul 19, 2022

Choose a reason for hiding this comment

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

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.1/linux-arm64/develop-1da95a7db1317bd6c66a7d9bf6ba6f8dd5b7d620/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1da95a7 Jul 19, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.1/darwin-arm64/develop-1da95a7db1317bd6c66a7d9bf6ba6f8dd5b7d620/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1da95a7 Jul 19, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.1/darwin-x64/develop-1da95a7db1317bd6c66a7d9bf6ba6f8dd5b7d620/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1da95a7 Jul 19, 2022

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.3.1/win32-x64/develop-1da95a7db1317bd6c66a7d9bf6ba6f8dd5b7d620/cypress.tgz

Please sign in to comment.