From 395406609d419620a843a40289eae85ca14e58b6 Mon Sep 17 00:00:00 2001 From: David Humphrey Date: Sat, 1 Dec 2018 12:33:32 -0500 Subject: [PATCH] Add Headless Firefox test support, fix failing truncate test in Firefox --- .travis.yml | 7 +++++-- karma.conf.js | 2 -- package-lock.json | 6 ++++++ package.json | 10 ++++++++-- src/filesystem/implementation.js | 21 +++++++++++++-------- src/shared.js | 19 +------------------ 6 files changed, 33 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9e346a..8c3a12d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,16 @@ -sudo: true - language: node_js node_js: - "lts/*" +env: + - MOZ_HEADLESS=1 + # Setup headless Chrome support # https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-the-Chrome-addon-in-the-headless-mode addons: chrome: stable + firefox: latest + before_install: - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost & diff --git a/karma.conf.js b/karma.conf.js index f6a8abd..b09f102 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,10 +1,8 @@ module.exports = function(config) { config.set({ - browsers: ['ChromeHeadless'], singleRun: true, basePath: '', files: ['tests/dist/index.js'], - frameworks: ['mocha', 'chai'], reporters: ['mocha'], client: { diff --git a/package-lock.json b/package-lock.json index a643c21..58a7327 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5227,6 +5227,12 @@ "which": "^1.2.1" } }, + "karma-firefox-launcher": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/karma-firefox-launcher/-/karma-firefox-launcher-1.1.0.tgz", + "integrity": "sha512-LbZ5/XlIXLeQ3cqnCbYLn+rOVhuMIK9aZwlP6eOLGzWdo1UVp7t6CN3DP4SafiRLjexKwHeKHDm0c38Mtd3VxA==", + "dev": true + }, "karma-mocha": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/karma-mocha/-/karma-mocha-1.3.0.tgz", diff --git a/package.json b/package.json index bc3a1a9..e2da68d 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,13 @@ "test": "npm run karma-mocha", "prebuild": "parcel build --global Filer src/index.js --no-minify --out-file filer.js", "build": "parcel build --global Filer src/index.js --out-file filer.min.js --detailed-report", - "prekarma-mocha": "parcel build tests/index.js --no-source-maps --out-dir tests/dist", - "karma-mocha": "karma start karma.conf.js", + "build-tests": "parcel build tests/index.js --no-source-maps --out-dir tests/dist", + "prekarma-mocha-firefox": "npm run build-tests", + "karma-mocha-firefox": "karma start karma.conf.js --browsers FirefoxHeadless", + "prekarma-mocha-chrome": "npm run build-tests", + "karma-mocha-chrome": "karma start karma.conf.js --browsers ChromeHeadless", + "prekarma-mocha": "npm run build-tests", + "karma-mocha": "karma start karma.conf.js --browsers ChromeHeadless,FirefoxHeadless", "coverage": "nyc mocha tests/index.js" }, "repository": { @@ -45,6 +50,7 @@ "karma": "^3.0.0", "karma-chai": "^0.1.0", "karma-chrome-launcher": "^2.2.0", + "karma-firefox-launcher": "^1.1.0", "karma-mocha": "^1.3.0", "karma-mocha-reporter": "^2.2.5", "mocha": "^5.2.0", diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index 7d53205..87b095d 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -37,7 +37,6 @@ var SuperNode = require('../super-node.js'); var Node = require('../node.js'); var Stats = require('../stats.js'); var Buffer = require('../buffer.js'); -const { validateInteger } = require('../shared.js'); /** * Update node times. Only passed times are modified (undefined times are ignored) @@ -1269,12 +1268,6 @@ function truncate_file(context, path, length, callback) { if(!fileData) { return callback(new Errors.EIO('Expected Buffer')); } - try { - validateInteger(length, 'len'); - } - catch (error) { - return callback(error); - } var data = new Buffer(length); data.fill(0); if(fileData) { @@ -1842,7 +1835,7 @@ function write(fs, context, fd, buffer, offset, length, position, callback) { } else if(!ofd.flags.includes(O_WRITE)) { callback(new Errors.EBADF('descriptor does not permit writing')); } else if(buffer.length - offset < length) { - callback(new Errors.EIO('intput buffer is too small')); + callback(new Errors.EIO('input buffer is too small')); } else { write_data(context, ofd, buffer, offset, length, position, callback); } @@ -1930,6 +1923,15 @@ function exists(fs, context, path, callback) { stat(fs, context, path, cb); } +function validateInteger(value, callback) { + if (typeof value !== 'number') { + callback(new Errors.EINVAL('Expected integer', value)); + return; + } + + return value; +} + // Based on https://github.com/nodejs/node/blob/c700cc42da9cf73af9fec2098520a6c0a631d901/lib/internal/validators.js#L21 var octalReg = /^[0-7]+$/; function isUint32(value) { @@ -2380,6 +2382,8 @@ function truncate(fs, context, path, length, callback) { length = length || 0; if(!pathCheck(path, callback)) return; + if(validateInteger(length, callback) !== length) return; + truncate_file(context, path, length, callback); } @@ -2394,6 +2398,7 @@ function ftruncate(fs, context, fd, length, callback) { } else if(!ofd.flags.includes(O_WRITE)) { callback(new Errors.EBADF('descriptor does not permit writing')); } else { + if(validateInteger(length, callback) !== length) return; ftruncate_file(context, ofd, length, callback); } } diff --git a/src/shared.js b/src/shared.js index 4da76cc..5c3337b 100644 --- a/src/shared.js +++ b/src/shared.js @@ -1,5 +1,3 @@ -var Errors = require('./errors.js'); - function guid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); @@ -9,22 +7,7 @@ function guid() { function nop() {} -function validateInteger(value, name) { - let err; - - if (typeof value !== 'number') - err = new Errors.EINVAL(name, 'number', value); - - if (err) { - Error.captureStackTrace(err, validateInteger); - throw err; - } - - return value; -} - module.exports = { guid: guid, - nop: nop, - validateInteger: validateInteger, + nop: nop };