Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

timekeeper

Package Overview
Dependencies
Maintainers
5
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timekeeper - npm Package Compare versions

Comparing version 0.0.5 to 0.1.0

6

lib/timekeeper.js

@@ -72,3 +72,3 @@ /**

if (!length && freeze) return freeze;
if (!length && freeze) return new NativeDate(freeze.getTime());
if (!length && travel) return new NativeDate(time());

@@ -130,3 +130,3 @@

/**
* Set current Date Tieme and freeze it.
* Set current Date Time and freeze it.
*

@@ -203,2 +203,2 @@ * @param {Object|String|Number} Date.

return timekeeper;
});
});
{
"name": "timekeeper",
"description": "Easy testing of time-dependent code.",
"version": "0.0.5",
"version": "0.1.0",
"keywords": [

@@ -12,11 +12,6 @@ "fake date",

"contributors": [
{
"name": "Oleg Slobodskoi",
"email": "oleg008@gmail.com"
},
{
"name": "Guilherme Tramontina",
"email": "guilherme.tramontina@gmail.com"
}
"Oleg Slobodskoi <oleg008@gmail.com>",
"Guilherme Tramontina <guilherme.tramontina@gmail.com>"
],
"dependencies": {},
"devDependencies": {

@@ -26,8 +21,7 @@ "chai": "^1.9.2",

"mocha": "^2.0.1",
"mocha-phantomjs": "^3.5.1",
"phantomjs": "^1.9.12"
"mocha-phantomjs": "^4.0.2"
},
"repository": {
"type": "git",
"url": "http://github.com/vesln/timekeeper.git"
"url": "git+ssh://git@github.com/vesln/timekeeper.git"
},

@@ -38,3 +32,10 @@ "homepage": "http://github.com/vesln/timekeeper",

},
"main": "./lib/timekeeper.js"
"main": "./lib/timekeeper.js",
"bugs": {
"url": "https://github.com/vesln/timekeeper/issues"
},
"directories": {
"test": "test"
},
"license": "MIT"
}

@@ -1,7 +0,11 @@

[![Build Status](https://secure.travis-ci.org/vesln/timekeeper.png)](http://travis-ci.org/vesln/timekeeper)
# timekeeper
[![travis][travis-image]][travis-url]
[![npm][npm-image]][npm-url]
## Description
[travis-image]: https://travis-ci.org/vesln/timekeeper.svg?branch=master
[travis-url]: https://travis-ci.org/vesln/timekeeper
[npm-image]: https://img.shields.io/npm/v/timekeeper.svg?style=flat
[npm-url]: https://npmjs.org/package/timekeeper
This module mocks `Date` and `Date.now` in order to help you test time-dependent code.

@@ -12,9 +16,9 @@ Provides `travel` and `freeze` functionality for your Node.js tests.

- Please note, that if you are using time freezing, the `setTimeout` and
`setInteval` won't work as exepcted, since they are using the `Date`
class but the time will not change until you call `timekeeper#reset`.
- Please note, that if you are using time freezing, `setTimeout` and
`setInteval` won't work as expected, since they are using the `Date`
class, but the time will not change until you call `timekeeper#reset`.
## Installation
- NPM: `npm install timekeeper --save`
- NPM: `npm install timekeeper --save-dev`
- Bower: `bower install timekeeper`

@@ -72,3 +76,2 @@

## Requirements

@@ -79,8 +82,2 @@

## Install
```
$ npm install timekeeper
```
## Tests

@@ -96,3 +93,3 @@

Inspired by the [timecop](https://github.com/jtrupiano/timecop) ruby gem.
Inspired by the [timecop](https://github.com/travisjeffery/timecop) ruby gem.

@@ -99,0 +96,0 @@ ## License

@@ -8,17 +8,2 @@ /**

/**
* Sleep implementation.
*
* Thanks to Stoyan Stefanov.
* http://www.phpied.com/sleep-in-javascript/
*
* @param {Number} Milliseconds.
*/
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds) break;
}
};
describe('TimeKeeper', function() {

@@ -32,20 +17,32 @@ describe('freeze', function() {

it('freezes the time create with `new Date` to the supplied one', function() {
sleep(10);
var date = new Date;
date.getTime().should.eql(this.time.getTime());
afterEach(function() {
tk.reset();
});
it('freezes the time create with `Date#now` to the supplied one', function() {
sleep(10);
Date.now().should.eql(this.time.getTime());
tk.reset();
it('freezes the time create with `new Date` to the supplied one', function(done) {
setTimeout(function(time) {
var date = new Date();
date.getTime().should.eql(time.getTime());
done();
}, 10, this.time);
});
it('freezes the time create with `Date#now` to the supplied one', function(done) {
setTimeout(function(time) {
Date.now().should.eql(time.getTime());
done();
}, 10, this.time);
});
it('should not affect other date calls', function() {
tk.freeze(this.time);
(new Date(1330688329320)).getTime().should.eql(1330688329320);
tk.reset();
});
it('should be immutable', function() {
var firstDate = new Date();
firstDate.setFullYear(2001);
var secondDate = new Date();
secondDate.getFullYear().should.not.equal(2001);
})
});

@@ -59,9 +56,14 @@ });

tk.travel(this.time);
sleep(10);
});
afterEach(function() {
tk.reset();
});
describe('and used with `new Date`', function() {
it('should set the current date time to the supplied one', function() {
(new Date).getTime().should.be.greaterThan(this.time.getTime());
tk.reset();
it('should set the current date time to the supplied one', function(done) {
setTimeout(function(time) {
(new Date).getTime().should.be.greaterThan(time.getTime());
done();
}, 10, this.time);
});

@@ -71,6 +73,7 @@ });

describe('and used with `Date#now`', function() {
it('should set the current date time to the supplied one', function() {
sleep(10);
Date.now().should.be.greaterThan(this.time.getTime());
tk.reset();
it('should set the current date time to the supplied one', function(done) {
setTimeout(function(time) {
Date.now().should.be.greaterThan(time.getTime());
done();
}, 10, this.time);
});

@@ -77,0 +80,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc