cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.88k stars 3.18k forks source link

Headless does not take into consideration the config.viewportWidth and config.viewportHeight #30455

Open alexsch01 opened 19 hours ago

alexsch01 commented 19 hours ago

Current behavior

$ npx cypress run

DevTools listening on ws://127.0.0.1:57100/devtools/browser/d909cab7-fff6-45a2-8123-d318d726b2db

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        13.15.0                                                                        │
  │ Browser:        Electron 118 (headless)                                                        │
  │ Node Version:   v18.13.0 (C:\Program Files\nodejs\node.exe)                                    │
  │ Specs:          1 found (spec.cy.js)                                                           │
  │ Searched:       cypress/e2e/**/*.cy.{js,jsx,ts,tsx}                                            │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  spec.cy.js                                                                      (1 of 1)

720 1280
  √  (41ms)

  1 passing (55ms)

  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        1                                                                                │
  │ Passing:      1                                                                                │
  │ Failing:      0                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  0                                                                                │
  │ Video:        false                                                                            │
  │ Duration:     0 seconds                                                                        │
  │ Spec Ran:     spec.cy.js                                                                       │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

====================================================================================================

  (Run Finished)

       Spec                                              Tests  Passing  Failing  Pending  Skipped
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ √  spec.cy.js                                57ms        1        1        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    √  All specs passed!                         57ms        1        1        -        -        -

Desired behavior

$ npx cypress run

DevTools listening on ws://127.0.0.1:57100/devtools/browser/d909cab7-fff6-45a2-8123-d318d726b2db

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        13.15.0                                                                        │
  │ Browser:        Electron 118 (headless)                                                        │
  │ Node Version:   v18.13.0 (C:\Program Files\nodejs\node.exe)                                    │
  │ Specs:          1 found (spec.cy.js)                                                           │
  │ Searched:       cypress/e2e/**/*.cy.{js,jsx,ts,tsx}                                            │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  spec.cy.js                                                                      (1 of 1)

1080 1920
  √  (41ms)

  1 passing (55ms)

  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        1                                                                                │
  │ Passing:      1                                                                                │
  │ Failing:      0                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  0                                                                                │
  │ Video:        false                                                                            │
  │ Duration:     0 seconds                                                                        │
  │ Spec Ran:     spec.cy.js                                                                       │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

====================================================================================================

  (Run Finished)

       Spec                                              Tests  Passing  Failing  Pending  Skipped
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ √  spec.cy.js                                57ms        1        1        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    √  All specs passed!                         57ms        1        1        -        -        -

Test code to reproduce

cypress.config.js

const { defineConfig } = require('cypress');

module.exports = defineConfig({
    e2e: {
        setupNodeEvents(on, config) {
            on('task', {
                log(args) {
                    console.log(...args)
                    return null;
                },
            });
        },
    },
    viewportWidth: 1920,
    viewportHeight: 1080,
});

cypress/e2e/console.js

class console {
    log(...args) {
        cy.task('log', args)
    }
};

export default new console;

cypress/e2e/spec.js

import console from './console'

it('', () => {
    console.log(window.outerHeight, window.outerWidth)
})

Cypress Version

13.15.1

Node version

v20.18.0

Operating System

Windows 10.0.19045

Debug Logs

No response

Other

No response

alexsch01 commented 18 hours ago

related: https://github.com/cypress-io/cypress/issues/6210#issuecomment-583269127