From d72b2050021a8011d74e8515403096ef44f92f0c Mon Sep 17 00:00:00 2001 From: Scott O'Hara Date: Tue, 11 Nov 2025 10:19:14 +1100 Subject: [PATCH 1/4] feat: experimentalRunAllSpecs for component testing --- .../client/initCypressTests.js | 50 +++++++++++++------ npm/webpack-dev-server/src/loader.ts | 5 +- packages/app/src/store/run-all-specs-store.ts | 6 +-- packages/config/src/options.ts | 10 ---- packages/data-context/schemas/schema.graphql | 1 - .../src/sources/HtmlDataSource.ts | 1 + packages/errors/src/errors.ts | 15 ------ .../errors/test/visualSnapshotErrors.spec.ts | 6 --- .../cypress/e2e/config-warning.cy.ts | 34 ------------- packages/server/lib/socket-base.ts | 19 +++++-- 10 files changed, 58 insertions(+), 89 deletions(-) diff --git a/npm/vite-dev-server/client/initCypressTests.js b/npm/vite-dev-server/client/initCypressTests.js index 0fbff852e16..9bd297e6c7d 100644 --- a/npm/vite-dev-server/client/initCypressTests.js +++ b/npm/vite-dev-server/client/initCypressTests.js @@ -47,20 +47,42 @@ if (supportFile) { }) } -// Using relative path wouldn't allow to load tests outside Vite project root folder -// So we use the "@fs" bit to load the test file using its absolute path -// Normalize path to not include a leading slash (different on Win32 vs Unix) -const normalizedAbsolutePath = CypressInstance.spec.absolute.replace(/^\//, '') -const testFileAbsolutePathRoute = `${devServerPublicPathBase}/@fs/${normalizedAbsolutePath}` - -/* Spec file import logic */ -// We need a slash before /src/my-spec.js, this does not happen by default. -importsToLoad.push({ - load: () => import(testFileAbsolutePathRoute), - absolute: CypressInstance.spec.absolute, - relative: CypressInstance.spec.relative, - relativeUrl: testFileAbsolutePathRoute, -}) +const specPath = new URLSearchParams(document.location.search).get('specPath') + +if (specPath === '__all' || CypressInstance.spec.relative === '__all') { + const runAllSpecs = window.parent.__RUN_ALL_SPECS__ || [] + const allSpecs = window.parent.__RUN_MODE_SPECS__ || [] + + runAllSpecs.forEach((specRelative) => { + const specObj = allSpecs.find((s) => s.relative === specRelative) + + if (specObj) { + const normalizedPath = specObj.absolute.replace(/^\//, '') + const specRoute = `${devServerPublicPathBase}/@fs/${normalizedPath}` + + importsToLoad.push({ + load: () => import(specRoute), + absolute: specObj.absolute, + relative: specObj.relative, + relativeUrl: specRoute, + }) + } + }) +} else { + // Using relative path wouldn't allow to load tests outside Vite project root folder + // So we use the "@fs" bit to load the test file using its absolute path + // Normalize path to not include a leading slash (different on Win32 vs Unix) + const normalizedAbsolutePath = CypressInstance.spec.absolute.replace(/^\//, '') + const testFileAbsolutePathRoute = `${devServerPublicPathBase}/@fs/${normalizedAbsolutePath}` + + // We need a slash before /src/my-spec.js, this does not happen by default. + importsToLoad.push({ + load: () => import(testFileAbsolutePathRoute), + absolute: CypressInstance.spec.absolute, + relative: CypressInstance.spec.relative, + relativeUrl: testFileAbsolutePathRoute, + }) +} if (!CypressInstance) { throw new Error('Tests cannot run without a reference to Cypress!') diff --git a/npm/webpack-dev-server/src/loader.ts b/npm/webpack-dev-server/src/loader.ts index 6008adbb3cf..a2b5166d7ae 100644 --- a/npm/webpack-dev-server/src/loader.ts +++ b/npm/webpack-dev-server/src/loader.ts @@ -18,7 +18,10 @@ const makeImport = (file: Cypress.Cypress['spec'], filename: string, chunkName: const magicComments = chunkName ? `/* webpackChunkName: "${chunkName}" */` : '' return `"${filename}": { - shouldLoad: () => new URLSearchParams(document.location.search).get("specPath") === "${file.absolute}", + shouldLoad: () => { + const specPath = new URLSearchParams(document.location.search).get("specPath") + return specPath === "__all" || specPath === "${file.absolute}" + }, load: () => import("${file.absolute}" ${magicComments}), absolute: "${file.absolute.split(path.sep).join(path.posix.sep)}", relative: "${file.relative.split(path.sep).join(path.posix.sep)}", diff --git a/packages/app/src/store/run-all-specs-store.ts b/packages/app/src/store/run-all-specs-store.ts index 6ad090b3889..675bf1a9770 100644 --- a/packages/app/src/store/run-all-specs-store.ts +++ b/packages/app/src/store/run-all-specs-store.ts @@ -76,15 +76,13 @@ export const useRunAllSpecsStore = defineStore('runAllSpecs', () => { directoryChildrenRef.value = directoryChildren } - const query = useQuery({ query: RunAllSpecsDataDocument, pause: isRunMode || window.__CYPRESS_TESTING_TYPE__ === 'component' }) + const query = useQuery({ query: RunAllSpecsDataDocument, pause: isRunMode }) const isRunAllSpecsAllowed = computed(() => { - const isE2E = query.data.value?.currentProject?.currentTestingType === 'e2e' - const config: ResolvedConfig = query.data.value?.currentProject?.config || [] const hasExperiment = config.some(({ field, value }) => field === 'experimentalRunAllSpecs' && value === true) - return (isE2E && hasExperiment) + return hasExperiment }) return { diff --git a/packages/config/src/options.ts b/packages/config/src/options.ts index 44521ba45ee..55cf33d547e 100644 --- a/packages/config/src/options.ts +++ b/packages/config/src/options.ts @@ -664,11 +664,6 @@ export const breakingRootOptions: Array = [ errorKey: 'CONFIG_FILE_INVALID_ROOT_CONFIG', isWarning: false, testingTypes: ['e2e'], - }, { - name: 'experimentalRunAllSpecs', - errorKey: 'EXPERIMENTAL_RUN_ALL_SPECS_E2E_ONLY', - isWarning: false, - testingTypes: ['e2e'], }, { name: 'experimentalOriginDependencies', @@ -724,11 +719,6 @@ export const testingTypeBreakingOptions: { e2e: Array, component errorKey: 'CONFIG_FILE_INVALID_TESTING_TYPE_CONFIG_COMPONENT', isWarning: false, }, - { - name: 'experimentalRunAllSpecs', - errorKey: 'EXPERIMENTAL_RUN_ALL_SPECS_E2E_ONLY', - isWarning: false, - }, { name: 'experimentalOriginDependencies', errorKey: 'EXPERIMENTAL_ORIGIN_DEPENDENCIES_E2E_ONLY', diff --git a/packages/data-context/schemas/schema.graphql b/packages/data-context/schemas/schema.graphql index adf7cfa627d..065eecab1a0 100644 --- a/packages/data-context/schemas/schema.graphql +++ b/packages/data-context/schemas/schema.graphql @@ -1181,7 +1181,6 @@ enum ErrorTypeEnum { EXPERIMENTAL_JIT_COMPILE_REMOVED EXPERIMENTAL_ORIGIN_DEPENDENCIES_E2E_ONLY EXPERIMENTAL_PROMPT_COMMAND_E2E_ONLY - EXPERIMENTAL_RUN_ALL_SPECS_E2E_ONLY EXPERIMENTAL_SESSION_AND_ORIGIN_REMOVED EXPERIMENTAL_SINGLE_TAB_RUN_MODE EXPERIMENTAL_SKIP_DOMAIN_INJECTION_REMOVED diff --git a/packages/data-context/src/sources/HtmlDataSource.ts b/packages/data-context/src/sources/HtmlDataSource.ts index c8272b85b9a..bc62c3e61f0 100644 --- a/packages/data-context/src/sources/HtmlDataSource.ts +++ b/packages/data-context/src/sources/HtmlDataSource.ts @@ -120,6 +120,7 @@ export class HtmlDataSource {