From 55a59e70017af79d6f3c170d87d808acc8e21faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20O=C3=9Fwald?= <1410947+matz3@users.noreply.github.com> Date: Fri, 10 Apr 2020 00:54:31 +0200 Subject: [PATCH] fix(file-list): do not define fs.statAsync (#3467) Defining fs.statAsync affects other modules such as bluebird which throws an error because of the 'Async'-suffix: > Cannot promisify an API that has normal methods with 'Async'-suffix > See http://goo.gl/MqrFmX Fixes: https://github.com/karma-runner/karma/issues/3466 --- lib/file-list.js | 6 +++--- test/unit/file-list.spec.js | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/file-list.js b/lib/file-list.js index 2120ce6d3..6c9e93d16 100644 --- a/lib/file-list.js +++ b/lib/file-list.js @@ -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') @@ -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) @@ -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) diff --git a/test/unit/file-list.spec.js b/test/unit/file-list.spec.js index 002c56549..ca2d39fee 100644 --- a/test/unit/file-list.spec.js +++ b/test/unit/file-list.spec.js @@ -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, @@ -455,6 +459,7 @@ describe('FileList', () => { afterEach(() => { clock.restore() + mockFs.stat.restore() }) it('does not add excluded files', () => { @@ -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 }) }) })