Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: added tests for unixtimestamp generation #11886

Conversation

@lucamaraschi
Copy link
Contributor

commented Mar 16, 2017

This test checks for the different input types for the generation of
UNIX timestamps.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows [commit guidelines][]
Affected core subsystem(s)

test fs

test: added tests for unixtimestamp generation
This test checks for the different input types for the generation of
UNIX timestamps.

@mscdex mscdex added the fs label Mar 16, 2017


function throws(input) {
assert.throws(() => fs._toUnixTimestamp(input)
, 'Error: Cannot parse time: ' + input);

This comment has been minimized.

Copy link
@cjihrig

cjihrig Mar 16, 2017

Contributor

Can you make the second argument a regular expression (with ^ and $ to match the whole thing).

var assert = require('assert');
var fs = require('fs');

[undefined, null, {}, []].forEach((input) => throws(input));

This comment has been minimized.

Copy link
@cjihrig

cjihrig Mar 16, 2017

Contributor

You could probably just inline throws like you did in the "does not throw" case.

'use strict';
require('../common');
var assert = require('assert');
var fs = require('fs');

This comment has been minimized.

Copy link
@jasnell

jasnell Mar 16, 2017

Member

s/var/const


function throws(input) {
assert.throws(() => fs._toUnixTimestamp(input)
, 'Error: Cannot parse time: ' + input);

This comment has been minimized.

Copy link
@jasnell

jasnell Mar 16, 2017

Member

The second argument here should be either the type of error thrown or a check function. You can use common.expectsError() (see here)

This comment has been minimized.

Copy link
@jasnell

jasnell Mar 16, 2017

Member

Alternatively, make this second argument a regex... new RegExp(^Error: Cannot parse time: ${input}$)

This comment has been minimized.

Copy link
@lucamaraschi

lucamaraschi Mar 16, 2017

Author Contributor

@jasnell I guess the regex is going to fit better...let me push the change

@cjihrig

This comment has been minimized.

Copy link
Contributor

commented Mar 16, 2017

Might want to add tests for NaN, Infinity, and a negative number.

@lucamaraschi

This comment has been minimized.

Copy link
Contributor Author

commented Mar 16, 2017

I do have a PR read for the NaN as the current behaviour is to generate a timestamp when it should just return an error. Let me add Infinity and negative tho.

@lpinca
lpinca approved these changes Mar 17, 2017
@Fishrock123

This comment has been minimized.


[undefined, null, []].forEach((input) => {
assert.throws(() => fs._toUnixTimestamp(input)
, new RegExp('^Error: Cannot parse time: ' + input + '$'));

This comment has been minimized.

Copy link
@cjihrig

cjihrig Mar 17, 2017

Contributor

It passed the linter, but the comma that starts this line, and the comma starting line 12 should be moved to the preceding lines.

@cjihrig
Copy link
Contributor

left a comment

LGTM with a tiny style nit.

@cjihrig

This comment has been minimized.

Copy link
Contributor

commented Mar 20, 2017

Landed in 6aed32c with the comma style fix I suggested. Thanks!

@cjihrig cjihrig closed this Mar 20, 2017

cjihrig added a commit that referenced this pull request Mar 20, 2017
test: add tests for unixtimestamp generation
This test checks for the different input types for the generation
of UNIX timestamps in the fs module.

PR-URL: #11886
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
jungx098 added a commit to jungx098/node that referenced this pull request Mar 21, 2017
test: add tests for unixtimestamp generation
This test checks for the different input types for the generation
of UNIX timestamps in the fs module.

PR-URL: nodejs#11886
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@italoacasas

This comment has been minimized.

Copy link
Member

commented Mar 21, 2017

This PR need backport to v7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.