Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #679 from jprichardson/fix-max-call-stack
util/stat: fix max call stack size exceeded
- Loading branch information
Showing
2 changed files
with
86 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict' | ||
|
||
const fs = require(process.cwd()) | ||
const os = require('os') | ||
const path = require('path') | ||
const assert = require('assert') | ||
const semver = require('semver') | ||
const stat = require('../stat.js') | ||
|
||
const NODE_VERSION_WITH_BIGINT = '10.5.0' | ||
|
||
/* global beforeEach, afterEach, describe, it */ | ||
|
||
describe('util/stat', () => { | ||
let TEST_DIR | ||
|
||
beforeEach(done => { | ||
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'util-stat') | ||
fs.emptyDir(TEST_DIR, done) | ||
}) | ||
|
||
afterEach(done => fs.remove(TEST_DIR, done)) | ||
|
||
describe('should use stats with bigint type for node versions >= 10.5.0 and number type for older versions', done => { | ||
it('stat.checkPaths()', () => { | ||
const nodeVersion = process.versions.node | ||
const src = path.join(TEST_DIR, 'src') | ||
const dest = path.join(TEST_DIR, 'dest') | ||
fs.ensureFileSync(src) | ||
fs.ensureFileSync(dest) | ||
stat.checkPaths(src, dest, 'copy', (err, stats) => { | ||
assert.ifError(err) | ||
const { srcStat } = stats | ||
if (semver.gte(nodeVersion, NODE_VERSION_WITH_BIGINT)) { | ||
assert.strictEqual(typeof srcStat.ino, 'bigint') | ||
} else { | ||
assert.strictEqual(typeof srcStat.ino, 'number') | ||
} | ||
}) | ||
}) | ||
|
||
it('stat.checkPathsSync()', () => { | ||
const nodeVersion = process.versions.node | ||
const src = path.join(TEST_DIR, 'src') | ||
const dest = path.join(TEST_DIR, 'dest') | ||
fs.ensureFileSync(src) | ||
fs.ensureFileSync(dest) | ||
const { srcStat } = stat.checkPathsSync(src, dest, 'copy') | ||
if (semver.gte(nodeVersion, NODE_VERSION_WITH_BIGINT)) { | ||
assert.strictEqual(typeof srcStat.ino, 'bigint') | ||
} else { | ||
assert.strictEqual(typeof srcStat.ino, 'number') | ||
} | ||
}) | ||
}) | ||
|
||
describe('should stop at src or root path and not throw max call stack size error', done => { | ||
it('stat.checkParentPaths()', () => { | ||
const src = path.join(TEST_DIR, 'src') | ||
let dest = path.join(TEST_DIR, 'dest') | ||
fs.ensureFileSync(src) | ||
fs.ensureFileSync(dest) | ||
dest = path.basename(dest) | ||
const srcStat = fs.statSync(src) | ||
stat.checkParentPaths(src, srcStat, dest, 'copy', err => { | ||
assert.ifError(err) | ||
}) | ||
}) | ||
|
||
it('stat.checkParentPathsSync()', () => { | ||
const src = path.join(TEST_DIR, 'src') | ||
let dest = path.join(TEST_DIR, 'dest') | ||
fs.ensureFileSync(src) | ||
fs.ensureFileSync(dest) | ||
dest = path.basename(dest) | ||
const srcStat = fs.statSync(src) | ||
stat.checkParentPathsSync(src, srcStat, dest, 'copy') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters