在柏树测试运行之前,检查功能标志是否打开或关闭

发布于 2025-01-23 13:20:14 字数 722 浏览 2 评论 0 原文

我正在尝试为尚未启用的功能编写测试(隐藏在功能标志后面);我可以致电一个端点,以检查应用程序功能标志是否打开或关闭,我写了一个函数。

我的下一个任务是在功能标志打开的情况下,实现柏树仅运行特定测试的方法。如何实现我写的方法?我必须在cypress.config中的某个地方实现检查吗?

谢谢!

该方法的代码

checkTemplateFeatureFlag(): Chainable<Temp> {
  return (new Cypress.Promise(resolve => {
    cy.request({
      method: 'GET',
      url: `ENDPOINT_HERE`
    }).then(resp => {
      const array = JSON.parse(resp.body);
      const foundFlag = !!array.find(
        (obj: { flag_name: string; active: boolean }) =>
          obj.flag_name === 'FLAG_NAME' && obj.active
      );
      resolve(foundFlag);
    });
  }) as unknown) as Chainable<Temp>;
}

I am trying to write tests for features that aren't enabled yet (hidden behind feature flag); There's an endpoint I can call to check if the application feature flag is turned on or off and I wrote a function to do so.

My next task is to implement a way for Cypress to only run specific tests if the feature flag is ON. How do I implement that leveraging the method I wrote? Is there a check I have to implement somewhere in the Cypress.config?

Thanks!

code for the method

checkTemplateFeatureFlag(): Chainable<Temp> {
  return (new Cypress.Promise(resolve => {
    cy.request({
      method: 'GET',
      url: `ENDPOINT_HERE`
    }).then(resp => {
      const array = JSON.parse(resp.body);
      const foundFlag = !!array.find(
        (obj: { flag_name: string; active: boolean }) =>
          obj.flag_name === 'FLAG_NAME' && obj.active
      );
      resolve(foundFlag);
    });
  }) as unknown) as Chainable<Temp>;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

緦唸λ蓇 2025-01-30 13:20:14

跳过测试(或描述块)的一种简单方法是使用 function() compand cownbacks访问 this ,然后有条件地调用 this.skip()

您还需要在单独的块中调用 chceptemplatefeatureflag(),例如 theeach(),因为它具有异步内置。


let skipFeature;
beforeEach(() => {
  checkTemplateFeatureFlag().then(foundFlag => skipFeature = !foundFlag)
})

it('tests the feature', function() {  // function here for "this" access
  if (skipFeature) this.skip()
  ...
})

A simple way to skip tests (or describe blocks) dynamically is to use function() form callbacks to access this, then conditionally call this.skip().

You will also need to call checkTemplateFeatureFlag() in a separate block, say a beforeEach(), since it has async internals.


let skipFeature;
beforeEach(() => {
  checkTemplateFeatureFlag().then(foundFlag => skipFeature = !foundFlag)
})

it('tests the feature', function() {  // function here for "this" access
  if (skipFeature) this.skip()
  ...
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文