使用 TailwindCSS 3 运行 Cypress 测试

互联网 行业动态 更新时间:2024-06-13 00:19:06

Mic*_*ays 5

您可以使用Tailwind CLI即时生成样式表。

添加此插件cypress/plugins/tailwind.js(确保将-i源代码从更改./src/styles/globals.css为您的基本 CSS 文件):

before(() => {
  cy.exec('npx tailwindcss -i ./src/styles/globals.css -m').then(
    ({ stdout }) => {
      if (!document.head.querySelector('#tailwind-style')) {
        const link = document.createElement('style')
        link.id = 'tailwind-style'
        link.innerHTML = stdout

        document.head.appendChild(link)
      }
    },
  )
})

然后,通过将其导入来加载插件cypress/support/index.js

import '../plugins/tailwind'

您还应该为您的组件测试设置一个单独的配置文件,例如cypress/support/ponent.js,并在您的cypress.json配置文件中指定:

{
  "ponent": {
    "supportFile": "cypress/support/ponent.js",
  },
  "e2e": {
    "supportFile": "cypress/support/e2e.js"
  }
}

然后,只包含import '../plugins/tailwind'在您的cypress/support/ponent.js配置文件中,这样您就不会为您的 E2E 测试执行 JIT 编译(因为它是不必要的)。

更多推荐

测试,TailwindCSS,Cypress

本文发布于:2023-04-20 20:46:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/hyzx/cd4eb97b4b3f4fbc1edb8097b5afac7c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:测试   TailwindCSS   Cypress

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!