Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Re-introduce Run All specs for End to End under experimentalRun…
…AllSpecs flag (#24745) * feat: re-enable Run All Specs (#24683) * fix: disable query in run-mode * feat: Run-all-specs-ui (#24738) * wip run-all-specs-ui * added component tests for specs-list, inline-specs-list, and run-all-specs * updated tests for specslist, inlinespeclist, and runAllSpecs * simplify test * make prop with default value optional * enable run all specs * use named slot for clarify * use Record type * remove un-necessary dynamic component * use group and hover to inline css * fix tests * fix tests and use snapshot for style testing Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com> * fix typescript * fix test * build binary for run all specs * fix: tweaks for Run All Specs (#24746) * update ui [skip ci] * change types to reflect run all specs is e2e only * chore: separate run all specs components * fix typescript error * fix: run-all UI tweaks and keyboard nav (#24757) Closes undefined * fix UI test * move listener and use i18n [skip ci] (#24761) * fix: run-all-specs duplicate file-matching (#24763) * chore: limit linting [skip ci] * do not get separator until app is loaded * fix test Co-authored-by: Zachary Williams <ZachJW34@gmail.com> Co-authored-by: amehta265 <65267668+amehta265@users.noreply.github.com>
- Loading branch information
1 parent
b9d053e
commit 4bbd78e
Showing
48 changed files
with
847 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { RUN_ALL_SPECS_KEY } from '@packages/types/src' | ||
|
||
describe('run-all-specs', () => { | ||
const ALL_SPECS = { | ||
spec1: { relative: 'cypress/e2e/folder-a/spec-a.cy.js', name: 'runs folder-a/spec-a' }, | ||
spec2: { relative: 'cypress/e2e/folder-a/spec-b.cy.js', name: 'runs folder-a/spec-b' }, | ||
spec3: { relative: 'cypress/e2e/folder-b/spec-a.cy.js', name: 'runs folder-b/spec-a' }, | ||
spec4: { relative: 'cypress/e2e/folder-b/spec-b.cy.js', name: 'runs folder-b/spec-b' }, | ||
} | ||
|
||
const clickRunAllSpecs = (directory: string) => { | ||
const command = cy.get('[data-cy=spec-item-directory]').contains(directory) | ||
|
||
return command.realHover().then(() => { | ||
cy.get(`[data-cy="run-all-specs-for-${directory}"]`).click({ force: true }) | ||
}) | ||
} | ||
|
||
it('can run all specs with filter and live-reloading', () => { | ||
cy.scaffoldProject('run-all-specs') | ||
cy.openProject('run-all-specs') | ||
cy.startAppServer() | ||
cy.visitApp() | ||
|
||
// Spawns new browser so we need to stub this | ||
cy.withCtx((ctx, { sinon }) => { | ||
sinon.stub(ctx.actions.project, 'launchProject').resolves() | ||
}) | ||
|
||
// Verify "Run All Specs" with sub-directory | ||
const subDirectorySpecs = [ALL_SPECS.spec1, ALL_SPECS.spec2] | ||
|
||
cy.get('[data-cy=sidebar-link-specs-page]').click() | ||
|
||
clickRunAllSpecs('folder-a') | ||
|
||
cy.waitForSpecToFinish({ passCount: 2 }) | ||
|
||
cy.withCtx((ctx, { specs }) => { | ||
expect(ctx.project.runAllSpecs).to.include.members(specs.map((spec) => spec.relative)) | ||
}, { specs: subDirectorySpecs }) | ||
|
||
for (const spec of subDirectorySpecs) { | ||
cy.get('.runnable-title').contains(spec.name) | ||
} | ||
|
||
// Verify "Run All Specs" with filter | ||
const filteredSpecs = [ALL_SPECS.spec1, ALL_SPECS.spec3] | ||
|
||
cy.get('[data-cy=sidebar-link-specs-page]').click() | ||
|
||
cy.findByLabelText('Search specs').clear().type('spec-a') | ||
cy.get('[data-cy=spec-list-file]').contains('spec-b').should('not.exist') | ||
|
||
clickRunAllSpecs('cypress/e2e') | ||
|
||
cy.waitForSpecToFinish({ passCount: 2 }) | ||
|
||
cy.withCtx((ctx, { specs }) => { | ||
expect(ctx.project.runAllSpecs).to.include.members(specs.map((spec) => spec.relative)) | ||
}, { specs: filteredSpecs }) | ||
|
||
for (const spec of filteredSpecs) { | ||
cy.get('.runnable-title').contains(spec.name) | ||
} | ||
|
||
// Verify "Run All Specs" with filter + folder | ||
const filteredWithSubDirectorySpecs = [ALL_SPECS.spec1] | ||
|
||
cy.get('[data-cy=sidebar-link-specs-page]').click() | ||
|
||
cy.findByLabelText('Search specs').clear().type('spec-a') | ||
cy.get('[data-cy=spec-list-file]').contains('spec-b').should('not.exist') | ||
|
||
clickRunAllSpecs('folder-a') | ||
|
||
cy.waitForSpecToFinish({ passCount: 1 }) | ||
|
||
cy.withCtx((ctx, { specs }) => { | ||
expect(ctx.project.runAllSpecs).to.include.members(specs.map((spec) => spec.relative)) | ||
}, { specs: filteredWithSubDirectorySpecs }) | ||
|
||
for (const spec of filteredWithSubDirectorySpecs) { | ||
cy.get('.runnable-title').contains(spec.name) | ||
} | ||
|
||
// Verify "Run All Specs" live-reload | ||
cy.get('[data-cy=sidebar-link-specs-page]').click() | ||
cy.findByLabelText('Search specs').clear() | ||
cy.get('[data-cy=spec-list-file]').should('have.length', 4) | ||
|
||
clickRunAllSpecs('cypress/e2e') | ||
|
||
cy.withCtx((ctx, { specs, runAllSpecsKey }) => { | ||
expect(ctx.actions.project.launchProject).to.have.been.calledWith('e2e', undefined, runAllSpecsKey) | ||
expect(ctx.project.runAllSpecs).to.include.members(specs.map((spec) => spec.relative)) | ||
}, { specs: Object.values(ALL_SPECS), runAllSpecsKey: RUN_ALL_SPECS_KEY }) | ||
|
||
cy.waitForSpecToFinish({ passCount: 4 }) | ||
|
||
for (const spec of Object.values(ALL_SPECS)) { | ||
cy.get('.runnable-title').contains(spec.name) | ||
} | ||
|
||
cy.withCtx(async (ctx, { spec }) => { | ||
const originalContent = await ctx.actions.file.readFileInProject(spec.relative) | ||
const newContent = originalContent.replace('expect(true)', 'expect(false)') | ||
|
||
expect(newContent).not.eq(originalContent) | ||
|
||
await ctx.actions.file.writeFileInProject(spec.relative, newContent) | ||
}, { spec: ALL_SPECS.spec1 }) | ||
|
||
cy.waitForSpecToFinish({ passCount: 3, failCount: 1 }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { RUN_ALL_SPECS_KEY } from '@packages/types/src' | ||
import { gql, useMutation, useQuery } from '@urql/vue' | ||
import { computed, ComputedRef } from 'vue' | ||
import { useRouter } from 'vue-router' | ||
import { RunAllSpecsDocument, RunAllSpecs_ConfigDocument } from '../generated/graphql' | ||
import { getSeparator, SpecTreeNode, UseCollapsibleTreeNode } from '../specs/tree/useCollapsibleTree' | ||
|
||
type ResolvedConfig = { value: any, from: 'string', field: string }[] | ||
|
||
gql` | ||
query RunAllSpecs_Config { | ||
currentProject { | ||
id | ||
config | ||
currentTestingType | ||
} | ||
} | ||
` | ||
|
||
gql` | ||
mutation RunAllSpecs ($specPath: String!, $runAllSpecs: [String!]!) { | ||
setRunAllSpecs(runAllSpecs: $runAllSpecs) | ||
launchOpenProject(specPath: $specPath) { | ||
id | ||
} | ||
} | ||
` | ||
|
||
const isRunMode = window.__CYPRESS_MODE__ === 'run' && window.top === window | ||
|
||
export function useRunAllSpecs (list: ComputedRef<{tree: UseCollapsibleTreeNode<SpecTreeNode>[]}>) { | ||
const separator = getSeparator() | ||
const router = useRouter() | ||
const query = useQuery({ query: RunAllSpecs_ConfigDocument, pause: isRunMode }) | ||
const setRunAllSpecsMutation = useMutation(RunAllSpecsDocument) | ||
|
||
return { | ||
runAllSpecs: async (runAllSpecs: string[]) => { | ||
await setRunAllSpecsMutation.executeMutation({ runAllSpecs, specPath: RUN_ALL_SPECS_KEY }) | ||
|
||
// Won't execute unless we are testing since the browser gets killed. In testing, | ||
// we can stub `launchProject` to verify the functionality is working | ||
router.push({ path: '/specs/runner', query: { file: RUN_ALL_SPECS_KEY } }) | ||
}, | ||
isRunAllSpecsAllowed: computed(() => { | ||
const isE2E = query.data.value?.currentProject?.currentTestingType === 'e2e' | ||
|
||
const config: ResolvedConfig = query.data.value?.currentProject?.config || [] | ||
const hasExperiment = config.find(({ field, value }) => field === 'experimentalRunAllSpecs' && value === true) | ||
|
||
return Boolean(isE2E && hasExperiment) | ||
}), | ||
directoryChildren: computed(() => { | ||
return list.value.tree.reduce<Record<string, string[]>>((acc, node) => { | ||
if (!node.isLeaf) { | ||
acc[node.id] = [] | ||
} else { | ||
Object.keys(acc).forEach((dir) => { | ||
if (node.id.startsWith(dir) && node.id.replace(dir, '').startsWith(separator)) { | ||
acc[dir].push(node.id) | ||
} | ||
}) | ||
} | ||
|
||
return acc | ||
}, {}) | ||
}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
4bbd78e
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.
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:
4bbd78e
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.
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:
4bbd78e
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.
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:
4bbd78e
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.
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:
4bbd78e
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.
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: