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: refactor mkdtemp test and added async #12080

Conversation

lucamaraschi
Copy link
Contributor

@lucamaraschi lucamaraschi commented Mar 27, 2017

This test refactored the original test for mkdtempSync prefix validation
and added the test also for the async function mkdtemp.

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

test fs

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Mar 27, 2017
@mscdex mscdex added the fs Issues and PRs related to the fs subsystem / file system. label Mar 27, 2017

function failAsync(value) {
assert.throws(
() => fs.mkdtemp(value, () => {}),
Copy link
Member

@lpinca lpinca Mar 28, 2017

Choose a reason for hiding this comment

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

Nit: there is common.noop, so I think it makes sense to use it.

@lucamaraschi lucamaraschi force-pushed the test-mkdtemp-async-prefix-check branch from 6c6690f to 278d515 Compare March 28, 2017 12:18
@hiroppy
Copy link
Member

hiroppy commented Mar 28, 2017

Copy link
Member

@richardlau richardlau left a comment

Choose a reason for hiding this comment

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

I'd prefer the variables are renamed. As they currently are they sound like they refer to the values that occurred during execution and are being tested rather than the expected error or test inputs.

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

const assertedError = /^TypeError: filename prefix is required$/;
Copy link
Member

Choose a reason for hiding this comment

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

Could this be expectedError?

const fs = require('fs');

const assertedError = /^TypeError: filename prefix is required$/;
const assertValues = [undefined, null, 0, true, false, 1];
Copy link
Member

Choose a reason for hiding this comment

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

prefixValues?

@lucamaraschi lucamaraschi force-pushed the test-mkdtemp-async-prefix-check branch from 278d515 to 1323058 Compare March 28, 2017 15:09

function failAsync(value) {
assert.throws(
() => fs.mkdtemp(value, common.noop),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the callback be be () => common.fail('Async callback should not be called')?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That could work!

Copy link
Contributor

Choose a reason for hiding this comment

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

On second thought, I'm not sure that can happen because of the throw, but it would be good insurance anyways imo

@Fishrock123
Copy link
Contributor

Oops, didn't mean to approve. Oh well lol

@lucamaraschi lucamaraschi force-pushed the test-mkdtemp-async-prefix-check branch from 1323058 to b83338c Compare March 28, 2017 15:29
function failAsync(value) {
assert.throws(
() => fs.mkdtemp(value, () => {
common.fail('Async callback should not be called');
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be common.mustNotCall()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Semantically the two have the same result. We should probably start defining a list of guidelines to use (or maybe I just missed it) for tests.
@cjihrig I guess common.mustNotCall() should be the right pick here, I am right?

Copy link
Contributor

Choose a reason for hiding this comment

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

common.mustNotCall() was added to prevent calling common.fail() in an otherwise empty function.

@lucamaraschi lucamaraschi force-pushed the test-mkdtemp-async-prefix-check branch from b83338c to 12cc305 Compare March 28, 2017 20:55
This test refactored the original test for mkdtempSync prefix validation
and added the test also for the async function mkdtemp.
@lucamaraschi lucamaraschi force-pushed the test-mkdtemp-async-prefix-check branch from 12cc305 to daa39cd Compare March 28, 2017 21:04
@jasnell
Copy link
Member

jasnell commented Mar 30, 2017

@jasnell
Copy link
Member

jasnell commented Apr 4, 2017

jasnell pushed a commit that referenced this pull request Apr 4, 2017
This test refactored the original test for mkdtempSync prefix validation
and added the test also for the async function mkdtemp.

PR-URL: #12080
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
@jasnell
Copy link
Member

jasnell commented Apr 4, 2017

Landed in 085c1f8

@jasnell jasnell closed this Apr 4, 2017
@jasnell jasnell mentioned this pull request Apr 4, 2017
italoacasas pushed a commit to italoacasas/node that referenced this pull request Apr 10, 2017
This test refactored the original test for mkdtempSync prefix validation
and added the test also for the async function mkdtemp.

PR-URL: nodejs#12080
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
@italoacasas italoacasas mentioned this pull request Apr 10, 2017
2 tasks
@MylesBorins
Copy link
Contributor

MylesBorins commented Apr 18, 2017

This test does not pass on LTS. would you be willing to backport to v6.x-staging?

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.

10 participants