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

fix(file-list): do not define fs.statAsync #3467

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { promisify } = require('util')
const mm = require('minimatch')
const Glob = require('glob').Glob
const fs = require('graceful-fs')
fs.statAsync = promisify(fs.stat)
const statAsync = promisify(fs.stat.bind(fs))
const pathLib = require('path')
const _ = require('lodash')

Expand Down Expand Up @@ -189,7 +189,7 @@ class FileList {
const file = new File(path)
this._getFilesByPattern(pattern.pattern).push(file)

const [stat] = await Promise.all([fs.statAsync(path), this._refreshing])
const [stat] = await Promise.all([statAsync(path), this._refreshing])
file.mtime = stat.mtime
await this._preprocess(file)

Expand All @@ -207,7 +207,7 @@ class FileList {
return this.files
}

const [stat] = await Promise.all([fs.statAsync(path), this._refreshing])
const [stat] = await Promise.all([statAsync(path), this._refreshing])
if (force || stat.mtime > file.mtime) {
file.mtime = stat.mtime
await this._preprocess(file)
Expand Down
8 changes: 6 additions & 2 deletions test/unit/file-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ describe('FileList', () => {
clock = sinon.useFakeTimers()
// This hack is needed to ensure lodash is using the fake timers
// from sinon

// fs.stat needs to be spied before file-list is required
sinon.spy(mockFs, 'stat')

List = proxyquire('../../lib/file-list', {
lodash: _.runInContext(),
helper: helper,
Expand All @@ -455,6 +459,7 @@ describe('FileList', () => {

afterEach(() => {
clock.restore()
mockFs.stat.restore()
})

it('does not add excluded files', () => {
Expand Down Expand Up @@ -511,14 +516,13 @@ describe('FileList', () => {

return list.refresh().then(() => {
preprocess.resetHistory()
sinon.spy(mockFs, 'statAsync')

return Promise.all([
list.addFile('/some/d.js'),
list.addFile('/some/d.js')
]).then(() => {
expect(preprocess).to.have.been.calledOnce
expect(mockFs.statAsync).to.have.been.calledOnce
expect(mockFs.stat).to.have.been.calledOnce
})
})
})
Expand Down