Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exception when recording with no tests in specfile #15517

Merged
merged 6 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/example/cypress.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"projectId": "2pz86o"
}

95 changes: 95 additions & 0 deletions packages/server/__snapshots__/7_record_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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


`
6 changes: 5 additions & 1 deletion packages/server/lib/modes/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions packages/server/lib/util/tests_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export const flattenSuiteIntoRunnables = (suite, tests = [], hooks = []) => {
)
}

// if we dont have a suite, return early
if (!suite || !suite.suites) {
kuceb marked this conversation as resolved.
Show resolved Hide resolved
return [tests, hooks]
}

tests = tests.concat(suite.tests)
hooks = hooks.concat(suite.hooks)

Expand Down
30 changes: 30 additions & 0 deletions packages/server/test/e2e/7_record_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
kuceb marked this conversation as resolved.
Show resolved Hide resolved
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()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('no tests!')
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
console.log('no tests!')

describe('suite', () => {
})