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

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

This test checks for the different input types for the generation of
UNIX timestamps.
@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Mar 16, 2017
@mscdex mscdex added the fs Issues and PRs related to the fs subsystem / file system. label Mar 16, 2017

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/var/const


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@cjihrig
Copy link
Contributor

cjihrig commented Mar 16, 2017

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

@lucamaraschi
Copy link
Contributor Author

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.

@Fishrock123
Copy link
Contributor


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a tiny style nit.

@cjihrig
Copy link
Contributor

cjihrig commented Mar 20, 2017

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

@cjihrig cjihrig closed this Mar 20, 2017
cjihrig pushed a commit that referenced this pull request Mar 20, 2017
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 pushed a commit to jungx098/node that referenced this pull request Mar 21, 2017
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
Copy link
Contributor

This PR need backport to v7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants