• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript timemachine.reset函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中timemachine.reset函数的典型用法代码示例。如果您正苦于以下问题:TypeScript reset函数的具体用法?TypeScript reset怎么用?TypeScript reset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了reset函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1:

test.beforeEach(async t => {
  await TestEnvironment.initialize({
    httpOrHttps: HttpHttpsEnvironment.Https
  });

  TestEnvironment.mockInternalOneSignal();
  timemachine.reset();
});
开发者ID:OneSignal,项目名称:OneSignal-Website-SDK,代码行数:8,代码来源:SubscriptionManager.ts


示例2: async

      async (pushManager, pushManagerSubscribeSpy) => {
        // After our subscription, check the subscription creation date was recorded
        const subscription = await Database.getSubscription();

        // timemachine must be reset to use native Date parse API
        timemachine.reset();

        t.deepEqual(subscription.createdAt, Date.parse(dateString));
      }
开发者ID:OneSignal,项目名称:OneSignal-Website-SDK,代码行数:9,代码来源:SubscriptionManager.ts


示例3: test

test("should set and get item without expiration", async t => {
  await TestEnvironment.initialize({
    httpOrHttps: HttpHttpsEnvironment.Https
  });
  TimedLocalStorage.setItem("my-key", "my-value");
  t.deepEqual(TimedLocalStorage.getItem("my-key"), "my-value");
  timemachine.config({
    timestamp: new Date().getTime() + 1000 * 60 * 60 * 24 * 9999
  });
  t.deepEqual(TimedLocalStorage.getItem("my-key"), "my-value");
  timemachine.reset();
});
开发者ID:OneSignal,项目名称:OneSignal-Website-SDK,代码行数:12,代码来源:timedLocalStorage.ts


示例4: expirationTestCase

async function expirationTestCase(
  /**
   * The browser to simulate. Chrome means using vapidPublicKey, while Firefox means using the
   * global onesignalVapidPublicKey.
   */
  t: GenericTestContext<AvaContext<any>>,
  subscriptionCreationTime: number,
  subscriptionExpirationTime: number,
  expirationCheckTime: number,
  skipCreationDateSet: boolean,
  env: IntegrationKind,
) {

  const initialVapidKeys = generateVapidKeys();

  // Force service worker active state dependency so test can run
  const stub = sandbox.stub(ServiceWorkerManager.prototype, "getActiveState")
    .resolves(ServiceWorkerActiveState.WorkerA);
  const integrationStub = sandbox.stub(SdkEnvironment, "getIntegration").resolves(env);

  const newTimeBeforeMidpoint = expirationCheckTime;

  // Set the initial datetime, which is used internally for the subscription created at
  timemachine.config({
    timestamp: subscriptionCreationTime
  });

  const initialSubscriptionOptions: PushSubscriptionOptions = {
    userVisibleOnly: true,
    applicationServerKey: base64ToUint8Array(initialVapidKeys.uniquePublic).buffer,
  };

  await testCase(
    t,
    BrowserUserAgent.ChromeMacSupported,
    initialVapidKeys.uniquePublic,
    initialVapidKeys.sharedPublic,
    SubscriptionStrategyKind.SubscribeNew,
    async (_pushManager, _subscriptionManager) => {
      // Set every subscription's expiration time to 30 days plus
      PushSubscription.prototype.expirationTime = subscriptionExpirationTime;
    },
    async (_pushManager, _pushManagerSubscribeSpy, subscriptionManager) => {
      if (skipCreationDateSet) {
        // Unset directly
        await Database.put("Options", { key: "subscriptionCreatedAt", value: null });
      }

      timemachine.config({
        timestamp: expirationCheckTime
      });

      const isExpiring = await subscriptionManager.isSubscriptionExpiring();

      if (subscriptionExpirationTime) {
        if (env === IntegrationKind.Secure || env === IntegrationKind.SecureProxy) {
          // Checks in an HTTPS environment expire at the midpoint because we can silently
          // resubscribe (HTTPS top frame silently resubscribe, HTTPS in child frame send message to
          // SW to resubscribe)
          const midpointExpirationTime =
            subscriptionCreationTime + (subscriptionExpirationTime - subscriptionCreationTime) / 2;
          if (expirationCheckTime >= midpointExpirationTime) {
            t.true(isExpiring);
          } else {
            t.false(isExpiring);
          }
        } else {
          // Checks in an HTTP environment only expire at or after the expiration time, since we
          // can't silently resubscribe
          if (expirationCheckTime >= subscriptionExpirationTime) {
            t.true(isExpiring);
          } else {
            t.false(isExpiring);
          }
        }
      } else {
        return t.false(isExpiring);
      }
    }
  );

  timemachine.reset();
  stub.restore();
  integrationStub.restore();
}
开发者ID:OneSignal,项目名称:OneSignal-Website-SDK,代码行数:85,代码来源:SubscriptionManager.ts



注:本文中的timemachine.reset函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript timer.clearInterval函数代码示例发布时间:2022-05-25
下一篇:
TypeScript timemachine.config函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap