diff --git a/packages/app/cypress/e2e/cypress-in-cypress.cy.ts b/packages/app/cypress/e2e/cypress-in-cypress.cy.ts index 5e553e0e9ddd..b03785765182 100644 --- a/packages/app/cypress/e2e/cypress-in-cypress.cy.ts +++ b/packages/app/cypress/e2e/cypress-in-cypress.cy.ts @@ -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' diff --git a/packages/data-context/src/actions/ProjectActions.ts b/packages/data-context/src/actions/ProjectActions.ts index 5834d542c7f7..b06fe5ff53ec 100644 --- a/packages/data-context/src/actions/ProjectActions.ts +++ b/packages/data-context/src/actions/ProjectActions.ts @@ -512,11 +512,14 @@ 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') @@ -524,14 +527,12 @@ export class ProjectActions { 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 @@ -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! diff --git a/packages/data-context/test/unit/actions/ProjectActions.spec.ts b/packages/data-context/test/unit/actions/ProjectActions.spec.ts index 6420d8366126..1ac2c1e127b6 100644 --- a/packages/data-context/test/unit/actions/ProjectActions.spec.ts +++ b/packages/data-context/test/unit/actions/ProjectActions.spec.ts @@ -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', @@ -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', @@ -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', @@ -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', @@ -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', @@ -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', @@ -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', diff --git a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts index 8b4ede38e41c..cb3c61285902 100644 --- a/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts +++ b/packages/graphql/src/schemaTypes/objectTypes/gql-Mutation.ts @@ -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) => {