本文整理汇总了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();
});
示例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));
}
示例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();
});
示例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();
}