Skip to content

Commit

Permalink
chore(data-context): update runSpec mutation to support absolute spec…
Browse files Browse the repository at this point in the history
… path (#26973)

* fix(data-context): update runSpec mutation to support absolute spec path

* test(app): add currentProject to failin e2e runSpec test

* chore(data-context): use path.relative

* chore(graphql): update runSpec specPath description
  • Loading branch information
jordanpowell88 authored Jun 13, 2023
1 parent be12245 commit 3fc17c2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/app/cypress/e2e/cypress-in-cypress.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ describe('Cypress in Cypress', { viewportWidth: 1500, defaultCommandTimeout: 100

cy.withCtx(async (ctx) => {
const url = `http://127.0.0.1:${ctx.gqlServerPort}/__launchpad/graphql?`
const payload = `{"query":"mutation{\\nrunSpec(specPath:\\"cypress/e2e/dom-content.spec.js\\"){\\n__typename\\n... on RunSpecResponse{\\ntestingType\\nbrowser{\\nid\\nname\\n}\\nspec{\\nid\\nname\\n}\\n}\\n}\\n}","variables":null}`
const payload = `{"query":"mutation{\\nrunSpec(specPath:\\"${ctx.currentProject}/cypress/e2e/dom-content.spec.js\\"){\\n__typename\\n... on RunSpecResponse{\\ntestingType\\nbrowser{\\nid\\nname\\n}\\nspec{\\nid\\nname\\n}\\n}\\n}\\n}","variables":null}`

ctx.coreData.app.browserStatus = 'open'

Expand Down
21 changes: 11 additions & 10 deletions packages/data-context/src/actions/ProjectActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,26 +512,27 @@ export class ProjectActions {

let targetTestingType: TestingType

// Get relative path from the specPath to determine which testing type from the specPattern
const relativeSpecPath = path.relative(this.ctx.currentProject, specPath)

// Check to see whether input specPath matches the specPattern for one or the other testing type
// If it matches neither then we can't run the spec and we should error
if (await this.ctx.project.matchesSpecPattern(specPath, 'e2e')) {
if (await this.ctx.project.matchesSpecPattern(relativeSpecPath, 'e2e')) {
targetTestingType = 'e2e'
} else if (await this.ctx.project.matchesSpecPattern(specPath, 'component')) {
} else if (await this.ctx.project.matchesSpecPattern(relativeSpecPath, 'component')) {
targetTestingType = 'component'
} else {
throw new RunSpecError('NO_SPEC_PATTERN_MATCH', 'Unable to determine testing type, spec does not match any configured specPattern')
}

debug(`Spec %s matches '${targetTestingType}' pattern`, specPath)

const absoluteSpecPath = this.ctx.path.resolve(this.ctx.currentProject, specPath)

debug('Attempting to launch spec %s', absoluteSpecPath)
debug('Attempting to launch spec %s', specPath)

// Look to see if there's actually a file at the target location
// This helps us avoid switching testingType *then* finding out the spec doesn't exist
if (!this.ctx.fs.existsSync(absoluteSpecPath)) {
throw new RunSpecError('SPEC_NOT_FOUND', `No file exists at path ${absoluteSpecPath}`)
if (!this.ctx.fs.existsSync(specPath)) {
throw new RunSpecError('SPEC_NOT_FOUND', `No file exists at path ${specPath}`)
}

// We now know what testingType we need to be in - if we're already there, great
Expand Down Expand Up @@ -609,11 +610,11 @@ export class ProjectActions {
// a matching file exists above it may not end up loading as a valid spec so we validate that here
//
// Have to use toPosix here to align windows absolute paths with how the absolute path is storied in the data context
const spec = this.ctx.project.getCurrentSpecByAbsolute(toPosix(absoluteSpecPath))
const spec = this.ctx.project.getCurrentSpecByAbsolute(toPosix(specPath))

if (!spec) {
debug(`Spec not found with path: ${absoluteSpecPath}`)
throw new RunSpecError('SPEC_NOT_FOUND', `Unable to find matching spec with path ${absoluteSpecPath}`)
debug(`Spec not found with path: ${specPath}`)
throw new RunSpecError('SPEC_NOT_FOUND', `Unable to find matching spec with path ${specPath}`)
}

const browser = this.ctx.coreData.activeBrowser!
Expand Down
14 changes: 7 additions & 7 deletions packages/data-context/test/unit/actions/ProjectActions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('ProjectActions', () => {
describe('runSpec', () => {
context('no project', () => {
it('should fail with `NO_PROJECT`', async () => {
const result = await ctx.actions.project.runSpec({ specPath: 'e2e/abc.cy.ts' })
const result = await ctx.actions.project.runSpec({ specPath: '/Users/blah/Desktop/application/cypress/e2e/abc.cy.ts' })

sinon.assert.match(result, {
code: 'NO_PROJECT',
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('ProjectActions', () => {
})

it('should fail with `NO_SPEC_PATTERN_MATCH`', async () => {
const result = await ctx.actions.project.runSpec({ specPath: 'e2e/abc.cy.ts' })
const result = await ctx.actions.project.runSpec({ specPath: '/Users/blah/Desktop/application/e2e/abc.cy.ts' })

sinon.assert.match(result, {
code: 'NO_SPEC_PATTERN_MATCH',
Expand All @@ -155,7 +155,7 @@ describe('ProjectActions', () => {
})

it('should fail with `SPEC_NOT_FOUND`', async () => {
const result = await ctx.actions.project.runSpec({ specPath: 'e2e/abc.cy.ts' })
const result = await ctx.actions.project.runSpec({ specPath: '/Users/blah/Desktop/application/e2e/abc.cy.ts' })

sinon.assert.match(result, {
code: 'SPEC_NOT_FOUND',
Expand All @@ -174,7 +174,7 @@ describe('ProjectActions', () => {
})

it('should fail with `TESTING_TYPE_NOT_CONFIGURED`', async () => {
const result = await ctx.actions.project.runSpec({ specPath: 'e2e/abc.cy.ts' })
const result = await ctx.actions.project.runSpec({ specPath: '/Users/blah/Desktop/application/e2e/abc.cy.ts' })

sinon.assert.match(result, {
code: 'TESTING_TYPE_NOT_CONFIGURED',
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('ProjectActions', () => {
})

it('should succeed', async () => {
const result = await ctx.actions.project.runSpec({ specPath: 'e2e/abc.cy.ts' })
const result = await ctx.actions.project.runSpec({ specPath: '/Users/blah/Desktop/application/e2e/abc.cy.ts' })

sinon.assert.match(result, {
testingType: 'e2e',
Expand All @@ -228,7 +228,7 @@ describe('ProjectActions', () => {
})

it('should succeed', async () => {
const result = await ctx.actions.project.runSpec({ specPath: 'e2e/abc.cy.ts' })
const result = await ctx.actions.project.runSpec({ specPath: '/Users/blah/Desktop/application/e2e/abc.cy.ts' })

sinon.assert.match(result, {
testingType: 'e2e',
Expand All @@ -248,7 +248,7 @@ describe('ProjectActions', () => {
})

it('should succeed', async () => {
const result = await ctx.actions.project.runSpec({ specPath: 'e2e/abc.cy.ts' })
const result = await ctx.actions.project.runSpec({ specPath: '/Users/blah/Desktop/application/e2e/abc.cy.ts' })

sinon.assert.match(result, {
testingType: 'e2e',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ export const mutation = mutationType({
type: RunSpecResult,
args: {
specPath: nonNull(stringArg({
description: 'Relative path of spec to run from Cypress project root - must match e2e or component specPattern',
description: 'Absolute path of the spec to run - must match e2e or component specPattern',
})),
},
resolve: async (source, args, ctx) => {
Expand Down

5 comments on commit 3fc17c2

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3fc17c2 Jun 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.15.0/linux-arm64/develop-3fc17c25ac851390b12ab3240beba8accff8c088/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3fc17c2 Jun 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.15.0/linux-x64/develop-3fc17c25ac851390b12ab3240beba8accff8c088/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3fc17c2 Jun 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.15.0/darwin-arm64/develop-3fc17c25ac851390b12ab3240beba8accff8c088/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3fc17c2 Jun 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.15.0/darwin-x64/develop-3fc17c25ac851390b12ab3240beba8accff8c088/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3fc17c2 Jun 13, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.15.0/win32-x64/develop-3fc17c25ac851390b12ab3240beba8accff8c088/cypress.tgz

Please sign in to comment.