Skip to content

Commit

Permalink
Add basic test for stat functions with 3 arguments when supported
Browse files Browse the repository at this point in the history
This commit adds a simple test for the stat functions with three
arguments to verify that they still work.
The test is guarded by a version check to verify the current runtime
supports optional options for the stat functions.
  • Loading branch information
ZauberNerd committed May 14, 2019
1 parent 168bdb8 commit 4c1b072
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/enoent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@

var t = require('tap')
var g = require('../')

var NODE_VERSION_MAJOR_WITH_BIGINT = 10
var NODE_VERSION_MINOR_WITH_BIGINT = 5
var NODE_VERSION_PATCH_WITH_BIGINT = 0
var nodeVersion = process.versions.node.split('.')
var nodeVersionMajor = Number.parseInt(nodeVersion[0], 10)
var nodeVersionMinor = Number.parseInt(nodeVersion[1], 10)
var nodeVersionPatch = Number.parseInt(nodeVersion[2], 10)

function nodeSupportsBigInt () {
if (nodeVersionMajor > NODE_VERSION_MAJOR_WITH_BIGINT) {
return true
} else if (nodeVersionMajor === NODE_VERSION_MAJOR_WITH_BIGINT) {
if (nodeVersionMinor > NODE_VERSION_MINOR_WITH_BIGINT) {
return true
} else if (nodeVersionMinor === NODE_VERSION_MINOR_WITH_BIGINT) {
if (nodeVersionPatch >= NODE_VERSION_PATCH_WITH_BIGINT) {
return true
}
}
}
return false
}

var file = 'this file does not exist even a little bit'
var methods = [
['open', 'r'],
Expand All @@ -18,6 +42,13 @@ if (process.version.match(/^v([6-9]|[1-9][0-9])\./)) {
methods.push(['readdir', {}])
}

// any version > v10.5 can do stat(path, options, cb)
if (nodeSupportsBigInt()) {
methods.push(['stat', {}])
methods.push(['lstat', {}])
}


t.plan(methods.length)
methods.forEach(function (method) {
t.test(method[0], runTest(method))
Expand Down

0 comments on commit 4c1b072

Please sign in to comment.