diff --git a/packages/example/cypress.json b/packages/example/cypress.json index 8b342cd2ecdc..628b3740dedd 100644 --- a/packages/example/cypress.json +++ b/packages/example/cypress.json @@ -1,3 +1,4 @@ { "projectId": "2pz86o" } + \ No newline at end of file diff --git a/packages/server/__snapshots__/7_record_spec.js b/packages/server/__snapshots__/7_record_spec.js index 4a79b4d1452f..84919a80e514 100644 --- a/packages/server/__snapshots__/7_record_spec.js +++ b/packages/server/__snapshots__/7_record_spec.js @@ -2531,3 +2531,98 @@ exports['e2e record api skips specs records tests and exits without executing in Exiting with non-zero exit code because the run was canceled. ` + +exports['e2e record empty specs succeeds when empty spec file 1'] = ` + +==================================================================================================== + + (Run Starting) + + ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ Cypress: 1.2.3 │ + │ Browser: FooBrowser 88 │ + │ Specs: 2 found (empty_suite.spec.js, empty.spec.js) │ + │ Searched: cypress/integration/empty_suite.spec.js, cypress/integration/empty.spec.js │ + │ Params: Tag: false, Group: false, Parallel: false │ + │ Run URL: https://dashboard.cypress.io/projects/cjvoj7/runs/12 │ + └────────────────────────────────────────────────────────────────────────────────────────────────┘ + + +──────────────────────────────────────────────────────────────────────────────────────────────────── + + Running: empty_suite.spec.js (1 of 2) + Estimated: 8 seconds + + + 0 passing + + + (Results) + + ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ Tests: 0 │ + │ Passing: 0 │ + │ Failing: 0 │ + │ Pending: 0 │ + │ Skipped: 0 │ + │ Screenshots: 0 │ + │ Video: true │ + │ Duration: X seconds │ + │ Estimated: 8 seconds │ + │ Spec Ran: empty_suite.spec.js │ + └────────────────────────────────────────────────────────────────────────────────────────────────┘ + + + (Uploading Results) + + - Nothing to Upload + +──────────────────────────────────────────────────────────────────────────────────────────────────── + + Running: empty.spec.js (2 of 2) + Estimated: 8 seconds + + + 0 passing + + + (Results) + + ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ Tests: 0 │ + │ Passing: 0 │ + │ Failing: 0 │ + │ Pending: 0 │ + │ Skipped: 0 │ + │ Screenshots: 0 │ + │ Video: true │ + │ Duration: X seconds │ + │ Estimated: 8 seconds │ + │ Spec Ran: empty.spec.js │ + └────────────────────────────────────────────────────────────────────────────────────────────────┘ + + + (Uploading Results) + + - Nothing to Upload + +==================================================================================================== + + (Run Finished) + + + Spec Tests Passing Failing Pending Skipped + ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ ✔ empty_suite.spec.js XX:XX - - - - - │ + ├────────────────────────────────────────────────────────────────────────────────────────────────┤ + │ ✔ empty.spec.js XX:XX - - - - - │ + └────────────────────────────────────────────────────────────────────────────────────────────────┘ + ✔ All specs passed! XX:XX - - - - - + + +─────────────────────────────────────────────────────────────────────────────────────────────────────── + + Recorded Run: https://dashboard.cypress.io/projects/cjvoj7/runs/12 + + +` diff --git a/packages/server/lib/modes/record.js b/packages/server/lib/modes/record.js index 429ccea57239..122ac9183217 100644 --- a/packages/server/lib/modes/record.js +++ b/packages/server/lib/modes/record.js @@ -721,9 +721,13 @@ const createRunAndRecordSpecs = (options = {}) => { const onTestsReceived = (async (runnables, cb) => { // we failed createInstance earlier, nothing to do if (!instanceId) { - return + return cb() } + // runnables will be null when there' no tests + // this also means runtimeConfig will be missing + runnables = runnables || {} + const r = testsUtils.flattenSuiteIntoRunnables(runnables) const runtimeConfig = runnables.runtimeConfig const resolvedRuntimeConfig = Config.getResolvedRuntimeConfig(config, runtimeConfig) diff --git a/packages/server/lib/util/tests_utils.ts b/packages/server/lib/util/tests_utils.ts index 3242b81a28b4..61c78e94e4a6 100644 --- a/packages/server/lib/util/tests_utils.ts +++ b/packages/server/lib/util/tests_utils.ts @@ -9,6 +9,11 @@ export const flattenSuiteIntoRunnables = (suite, tests = [], hooks = []) => { ) } + // if we dont have a suite, return early + if (!suite || !suite.suites) { + return [tests, hooks] + } + tests = tests.concat(suite.tests) hooks = hooks.concat(suite.hooks) diff --git a/packages/server/test/e2e/7_record_spec.js b/packages/server/test/e2e/7_record_spec.js index d5f3cff96ce9..ed1c0ef55cbf 100644 --- a/packages/server/test/e2e/7_record_spec.js +++ b/packages/server/test/e2e/7_record_spec.js @@ -406,6 +406,36 @@ describe('e2e record', () => { }) }) + context('empty specs', () => { + setupStubbedServer(createRoutes()) + + // https://github.com/cypress-io/cypress/issues/15512 + it('succeeds when empty spec file', async function () { + await e2e.exec(this, { + key: 'f858a2bc-b469-4e48-be67-0876339ee7e1', + record: true, + spec: 'empty_suite.spec.js,empty.spec.js', + snapshot: true, + expectedExitCode: 0, + }) + + expect(getRequestUrls()).deep.eq([ + 'POST /runs', + `POST /runs/${runId}/instances`, + `POST /instances/${instanceId}/tests`, + `POST /instances/${instanceId}/results`, + `PUT /instances/${instanceId}/stdout`, + + `POST /runs/${runId}/instances`, + `POST /instances/${instanceId}/tests`, + `POST /instances/${instanceId}/results`, + `PUT /instances/${instanceId}/stdout`, + + `POST /runs/${runId}/instances`, + ]) + }) + }) + context('projectId', () => { e2e.setup() diff --git a/packages/server/test/support/fixtures/projects/e2e/cypress/integration/empty.spec.js b/packages/server/test/support/fixtures/projects/e2e/cypress/integration/empty.spec.js new file mode 100644 index 000000000000..10a520a58a92 --- /dev/null +++ b/packages/server/test/support/fixtures/projects/e2e/cypress/integration/empty.spec.js @@ -0,0 +1 @@ +console.log('no tests!') diff --git a/packages/server/test/support/fixtures/projects/e2e/cypress/integration/empty_suite.spec.js b/packages/server/test/support/fixtures/projects/e2e/cypress/integration/empty_suite.spec.js new file mode 100644 index 000000000000..47543dfe3491 --- /dev/null +++ b/packages/server/test/support/fixtures/projects/e2e/cypress/integration/empty_suite.spec.js @@ -0,0 +1,4 @@ +console.log('no tests!') + +describe('suite', () => { +})