本文整理汇总了TypeScript中timemachine.config函数的典型用法代码示例。如果您正苦于以下问题:TypeScript config函数的具体用法?TypeScript config怎么用?TypeScript config使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了config函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test("should set and get item with expiration", async t => {
await TestEnvironment.initialize({
httpOrHttps: HttpHttpsEnvironment.Https
});
TimedLocalStorage.setItem("my-key", "my-value", 3);
t.deepEqual(TimedLocalStorage.getItem("my-key"), "my-value");
timemachine.config({
timestamp: new Date().getTime() + 1000 * 60 * 2
});
t.deepEqual(TimedLocalStorage.getItem("my-key"), "my-value");
timemachine.config({
timestamp: new Date().getTime() + 1000 * 60 * 3
});
t.deepEqual(TimedLocalStorage.getItem("my-key"), null);
timemachine.reset();
});
示例2: generateVapidKeys
async t => {
const initialVapidKeys = generateVapidKeys();
const dateString = "February 26, 2018 10:04:24 UTC";
// Set the initial datetime
timemachine.config({
timestamp: dateString
});
const initialSubscriptionOptions: PushSubscriptionOptions = {
userVisibleOnly: true,
applicationServerKey: base64ToUint8Array(initialVapidKeys.uniquePublic).buffer,
};
await testCase(
t,
BrowserUserAgent.ChromeMacSupported,
initialVapidKeys.uniquePublic,
initialVapidKeys.sharedPublic,
SubscriptionStrategyKind.SubscribeNew,
null,
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: async
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);
}
}
示例4: test
test('should not collect pageviews if system clock is out of sync', async t => {
timemachine.config({
dateString: "February 8 2018"
});
t.true(OneSignal.context.metricsManager.shouldCollectPageView());
// Anything before February 8th 2018 shouldn't be collecting data
timemachine.config({
dateString: "February 8 2017"
});
t.false(OneSignal.context.metricsManager.shouldCollectPageView());
timemachine.config({
dateString: "February 7 2018"
});
t.false(OneSignal.context.metricsManager.shouldCollectPageView());
timemachine.config({
dateString: "January 5 2018"
});
t.false(OneSignal.context.metricsManager.shouldCollectPageView());
timemachine.config({
dateString: "February 9 1980"
});
t.false(OneSignal.context.metricsManager.shouldCollectPageView());
// Feb 9th should be okay
timemachine.config({
dateString: "February 9 2018"
});
t.true(OneSignal.context.metricsManager.shouldCollectPageView());
// Feb 11th should not be okay
timemachine.config({
dateString: "February 11 2018"
});
t.false(OneSignal.context.metricsManager.shouldCollectPageView());
});
示例5: 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();
}