From 1e21aaaaf211b4eef3085fd937f69b6cf3c10302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 14 Jan 2016 23:18:06 +0100 Subject: [PATCH] fix: Switch all requires from fs to graceful-fs --- lib/cli.js | 2 +- lib/completion.js | 2 +- lib/constants.js | 2 +- lib/file-list.js | 2 +- lib/helper.js | 2 +- lib/init/formatters.js | 2 +- lib/plugin.js | 2 +- lib/temp_dir.js | 2 +- lib/web-server.js | 2 +- package.json | 1 + test/unit/file-list.spec.js | 24 ++++++++++++++---------- test/unit/helper.spec.js | 3 ++- test/unit/web-server.spec.js | 2 +- 13 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 335aabc51..520dd43d3 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,6 +1,6 @@ var path = require('path') var optimist = require('optimist') -var fs = require('fs') +var fs = require('graceful-fs') var Server = require('./server') var helper = require('./helper') diff --git a/lib/completion.js b/lib/completion.js index 4611c776b..4ffe3b7a8 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -130,7 +130,7 @@ var completion = function () { } // just print out the karma-completion.sh - var fs = require('fs') + var fs = require('graceful-fs') var path = require('path') fs.readFile(path.resolve(__dirname, '../scripts/karma-completion.sh'), 'utf8', function (err, data) { diff --git a/lib/constants.js b/lib/constants.js index 0bafe9e61..da974f0d2 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -1,4 +1,4 @@ -var fs = require('fs') +var fs = require('graceful-fs') var pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json').toString()) diff --git a/lib/file-list.js b/lib/file-list.js index f02f2f77e..c73b98ca5 100644 --- a/lib/file-list.js +++ b/lib/file-list.js @@ -12,7 +12,7 @@ var from = require('core-js/library/fn/array/from') var Promise = require('bluebird') var mm = require('minimatch') var Glob = require('glob').Glob -var fs = Promise.promisifyAll(require('fs')) +var fs = Promise.promisifyAll(require('graceful-fs')) var pathLib = require('path') var File = require('./file') diff --git a/lib/helper.js b/lib/helper.js index f414dceef..04bafa6fb 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -1,4 +1,4 @@ -var fs = require('fs') +var fs = require('graceful-fs') var path = require('path') var _ = require('lodash') var useragent = require('useragent') diff --git a/lib/init/formatters.js b/lib/init/formatters.js index 78cd6fe79..50251b16a 100644 --- a/lib/init/formatters.js +++ b/lib/init/formatters.js @@ -1,4 +1,4 @@ -var fs = require('fs') +var fs = require('graceful-fs') var util = require('util') var JS_TEMPLATE_PATH = __dirname + '/../../config.tpl.js' diff --git a/lib/plugin.js b/lib/plugin.js index e91e21e41..80e0b6d1b 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -1,4 +1,4 @@ -var fs = require('fs') +var fs = require('graceful-fs') var path = require('path') var helper = require('./helper') diff --git a/lib/temp_dir.js b/lib/temp_dir.js index 5d6ac3749..6543c2407 100644 --- a/lib/temp_dir.js +++ b/lib/temp_dir.js @@ -1,5 +1,5 @@ var path = require('path') -var fs = require('fs') +var fs = require('graceful-fs') var os = require('os') var rimraf = require('rimraf') var log = require('./logger').create('temp-dir') diff --git a/lib/web-server.js b/lib/web-server.js index 89b5165bd..4dfc248c7 100644 --- a/lib/web-server.js +++ b/lib/web-server.js @@ -1,4 +1,4 @@ -var fs = require('fs') +var fs = require('graceful-fs') var http = require('http') var https = require('https') var path = require('path') diff --git a/package.json b/package.json index c889fafca..bdb3e565c 100644 --- a/package.json +++ b/package.json @@ -324,6 +324,7 @@ "load-grunt-tasks": "^3.1.0", "mkdirp": "^0.5.0", "mocha": "^2.2.5", + "mock-fs": "^3.6.0", "mocks": "^0.0.15", "phantomjs": "^1.9.19", "proxyquire": "^1.5.0", diff --git a/test/unit/file-list.spec.js b/test/unit/file-list.spec.js index 69bb1589f..7e22c1652 100644 --- a/test/unit/file-list.spec.js +++ b/test/unit/file-list.spec.js @@ -36,11 +36,15 @@ var MG = { } } var mockFs = mocks.fs.create({ - some: {'0.js': mocks.fs.file('2012-04-04'), + some: { + '0.js': mocks.fs.file('2012-04-04'), 'a.js': mocks.fs.file('2012-04-04'), 'b.js': mocks.fs.file('2012-05-05'), - 'd.js': mocks.fs.file('2012-05-05')}, - folder: {'x.js': mocks.fs.file(0)}, + 'd.js': mocks.fs.file('2012-05-05') + }, + folder: { + 'x.js': mocks.fs.file(0) + }, 'a.txt': mocks.fs.file(0), 'b.txt': mocks.fs.file(0), 'c.txt': mocks.fs.file(0), @@ -77,7 +81,7 @@ describe('FileList', () => { helper: helper, glob: glob, path: pathLib.posix || pathLib/* for node 0.10 */, - fs: mockFs + 'graceful-fs': mockFs }) }) @@ -207,7 +211,7 @@ describe('FileList', () => { helper: helper, glob: glob, path: pathLib.posix || pathLib/* for node 0.10 */, - fs: mockFs + 'graceful-fs': mockFs }) list = new List(patterns('/some/*.js', '*.txt'), [], emitter, preprocess) @@ -244,7 +248,7 @@ describe('FileList', () => { helper: helper, glob: glob, path: pathLib.posix || pathLib/* for node 0.10 */, - fs: mockFs + 'graceful-fs': mockFs }) list = new List(patterns('/some/*.js', '*.txt'), [], emitter, preprocess, 100) @@ -414,7 +418,7 @@ describe('FileList', () => { helper: helper, glob: glob, path: pathLib.posix || pathLib/* for node 0.10 */, - fs: mockFs + 'graceful-fs': mockFs }) list = new List(patterns('/some/*.js', '*.txt'), ['/secret/*.txt'], emitter, preprocess) @@ -527,7 +531,7 @@ describe('FileList', () => { helper: helper, glob: glob, path: pathLib.posix || pathLib/* for node 0.10 */, - fs: mockFs + 'graceful-fs': mockFs }) mockFs._touchFile('/some/a.js', '2012-04-04') @@ -620,7 +624,7 @@ describe('FileList', () => { helper: helper, glob: glob, path: pathLib.posix || pathLib/* for node 0.10 */, - fs: mockFs + 'graceful-fs': mockFs }) modified = sinon.stub() @@ -687,7 +691,7 @@ describe('FileList', () => { List = proxyquire('../../lib/file-list', { helper: helper, glob: glob, - fs: mockFs, + 'graceful-fs': mockFs, path: pathLib.posix || pathLib/* for node 0.10 */, bluebird: Promise }) diff --git a/test/unit/helper.spec.js b/test/unit/helper.spec.js index 817ca7d6f..7a10a81e4 100644 --- a/test/unit/helper.spec.js +++ b/test/unit/helper.spec.js @@ -217,7 +217,8 @@ describe('helper', () => { }) // load file under test - var m = loadFile(__dirname + '/../../lib/helper.js', {fs: fs, lodash: require('lodash')}) + var m = loadFile(__dirname + '/../../lib/helper.js', {'graceful-fs': fs, lodash: require('lodash')}) + var mkdirIfNotExists = m.exports.mkdirIfNotExists it('should not do anything, if dir already exists', done => { diff --git a/test/unit/web-server.spec.js b/test/unit/web-server.spec.js index 7d311ba1e..17327c5de 100644 --- a/test/unit/web-server.spec.js +++ b/test/unit/web-server.spec.js @@ -14,7 +14,7 @@ describe('web-server', () => { var _mocks = {} var _globals = {__dirname: '/karma/lib'} - _mocks.fs = mocks.fs.create({ + _mocks['graceful-fs'] = mocks.fs.create({ karma: { static: { 'client.html': mocks.fs.file(0, 'CLIENT HTML')