Skip to content

Importing Global CSS in Next.js with Webpack #16879

@smhmd

Description

@smhmd

Current behavior

Following this migration guide, it is recommended to add (global) stylesheets to your tests. Nextjs's webpack wouldn't allow you to add them to your components anyway. But, when you add styles to a test, all tests (in cypress open-ct) hang on Your tests are loading....

import 'tailwindcss/tailwind.css' // or '../styles/index.css'

import { mount } from '@cypress/react'
import Button from '.'

describe('<Button />', () => {
  it('should mount', () => {
    mount(<Button />)
    cy.contains('click me')
  })
})

Desired behavior

For the global styles to get applied.

Test code to reproduce

// cypress/plugins/index.ts
const injectNextDevServer = require('@cypress/react/plugins/next')

const pluginConfig: Cypress.PluginConfig = (on, config) => {
  if (config.testingType === 'component') {
    injectNextDevServer(on, config)
  }

  return config
}

module.exports = pluginConfig

Versions

Cypress package version: 7.5.0
Cypress binary version: 7.5.0
Electron version: 12.0.0-beta.14
Bundled Node version: 14.15.1
OS: (Linux) 5.10.36-2-MANJARO

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions