Skip to content

Commit

Permalink
test: improve test-fs-open-flags
Browse files Browse the repository at this point in the history
* use arrow funcion instead of function expression
* add second argument to method assert.throws
* check error messages from beginning to the end using ^ and $

PR-URL: #10908
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Adrian Estrada <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
vinimdocarmo authored and italoacasas committed Jan 30, 2017
1 parent 35d6659 commit aa4b028
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions test/parallel/test-fs-open-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,27 @@ assert.equal(stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
.split(' ')
.forEach(function(flags) {
assert.throws(function() { stringToFlags(flags); });
assert.throws(
() => stringToFlags(flags),
new RegExp(`^Error: Unknown file open flag: ${escapeRegExp(flags)}`)
);
});

assert.throws(
() => stringToFlags({}),
/Unknown file open flag: \[object Object\]/
/^Error: Unknown file open flag: \[object Object\]$/
);

assert.throws(
() => stringToFlags(true),
/Unknown file open flag: true/
/^Error: Unknown file open flag: true$/
);

assert.throws(
() => stringToFlags(null),
/Unknown file open flag: null/
/^Error: Unknown file open flag: null$/
);

function escapeRegExp(string) {
return string.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
}

4 comments on commit aa4b028

@MylesBorins
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing PR-URL

@jasnell
Copy link
Member

@jasnell jasnell commented on aa4b028 Mar 8, 2017

Choose a reason for hiding this comment

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

? I'm seeing a PR-URL in the commit log above

@MylesBorins
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm unsure why it isn't registering with branch diff
¯\_(ツ)_/¯

@Trott
Copy link
Member

@Trott Trott commented on aa4b028 Apr 13, 2017

Choose a reason for hiding this comment

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

Probably because it's not the full URL.

    test: improve test-fs-open-flags
    
    * use arrow funcion instead of function expression
    * add second argument to method assert.throws
    * check error messages from beginning to the end using ^ and $
    
    PR-URL: nodejs#10908
    Reviewed-By: Rich Trott <[email protected]>
    Reviewed-By: Adrian Estrada <[email protected]>
    Reviewed-By: Luigi Pinca <[email protected]>
    Reviewed-By: Michaël Zasso <[email protected]>
    Reviewed-By: Colin Ihrig <[email protected]>

Please sign in to comment.