Add Headless Firefox test support, fix failing truncate test in Firefox

This commit is contained in:
David Humphrey 2018-12-01 12:33:32 -05:00
parent cc6e3f7edf
commit 395406609d
6 changed files with 33 additions and 32 deletions

View File

@ -1,13 +1,16 @@
sudo: true
language: node_js language: node_js
node_js: node_js:
- "lts/*" - "lts/*"
env:
- MOZ_HEADLESS=1
# Setup headless Chrome support # Setup headless Chrome support
# https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-the-Chrome-addon-in-the-headless-mode # https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-the-Chrome-addon-in-the-headless-mode
addons: addons:
chrome: stable chrome: stable
firefox: latest
before_install: before_install:
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost & - google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &

View File

@ -1,10 +1,8 @@
module.exports = function(config) { module.exports = function(config) {
config.set({ config.set({
browsers: ['ChromeHeadless'],
singleRun: true, singleRun: true,
basePath: '', basePath: '',
files: ['tests/dist/index.js'], files: ['tests/dist/index.js'],
frameworks: ['mocha', 'chai'], frameworks: ['mocha', 'chai'],
reporters: ['mocha'], reporters: ['mocha'],
client: { client: {

6
package-lock.json generated
View File

@ -5227,6 +5227,12 @@
"which": "^1.2.1" "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": { "karma-mocha": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/karma-mocha/-/karma-mocha-1.3.0.tgz", "resolved": "https://registry.npmjs.org/karma-mocha/-/karma-mocha-1.3.0.tgz",

View File

@ -26,8 +26,13 @@
"test": "npm run karma-mocha", "test": "npm run karma-mocha",
"prebuild": "parcel build --global Filer src/index.js --no-minify --out-file filer.js", "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", "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", "build-tests": "parcel build tests/index.js --no-source-maps --out-dir tests/dist",
"karma-mocha": "karma start karma.conf.js", "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" "coverage": "nyc mocha tests/index.js"
}, },
"repository": { "repository": {
@ -45,6 +50,7 @@
"karma": "^3.0.0", "karma": "^3.0.0",
"karma-chai": "^0.1.0", "karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0", "karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^1.1.0",
"karma-mocha": "^1.3.0", "karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5", "karma-mocha-reporter": "^2.2.5",
"mocha": "^5.2.0", "mocha": "^5.2.0",

View File

@ -37,7 +37,6 @@ var SuperNode = require('../super-node.js');
var Node = require('../node.js'); var Node = require('../node.js');
var Stats = require('../stats.js'); var Stats = require('../stats.js');
var Buffer = require('../buffer.js'); var Buffer = require('../buffer.js');
const { validateInteger } = require('../shared.js');
/** /**
* Update node times. Only passed times are modified (undefined times are ignored) * 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) { if(!fileData) {
return callback(new Errors.EIO('Expected Buffer')); return callback(new Errors.EIO('Expected Buffer'));
} }
try {
validateInteger(length, 'len');
}
catch (error) {
return callback(error);
}
var data = new Buffer(length); var data = new Buffer(length);
data.fill(0); data.fill(0);
if(fileData) { if(fileData) {
@ -1842,7 +1835,7 @@ function write(fs, context, fd, buffer, offset, length, position, callback) {
} else if(!ofd.flags.includes(O_WRITE)) { } else if(!ofd.flags.includes(O_WRITE)) {
callback(new Errors.EBADF('descriptor does not permit writing')); callback(new Errors.EBADF('descriptor does not permit writing'));
} else if(buffer.length - offset < length) { } 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 { } else {
write_data(context, ofd, buffer, offset, length, position, callback); write_data(context, ofd, buffer, offset, length, position, callback);
} }
@ -1930,6 +1923,15 @@ function exists(fs, context, path, callback) {
stat(fs, context, path, cb); 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 // Based on https://github.com/nodejs/node/blob/c700cc42da9cf73af9fec2098520a6c0a631d901/lib/internal/validators.js#L21
var octalReg = /^[0-7]+$/; var octalReg = /^[0-7]+$/;
function isUint32(value) { function isUint32(value) {
@ -2380,6 +2382,8 @@ function truncate(fs, context, path, length, callback) {
length = length || 0; length = length || 0;
if(!pathCheck(path, callback)) return; if(!pathCheck(path, callback)) return;
if(validateInteger(length, callback) !== length) return;
truncate_file(context, path, length, callback); truncate_file(context, path, length, callback);
} }
@ -2394,6 +2398,7 @@ function ftruncate(fs, context, fd, length, callback) {
} else if(!ofd.flags.includes(O_WRITE)) { } else if(!ofd.flags.includes(O_WRITE)) {
callback(new Errors.EBADF('descriptor does not permit writing')); callback(new Errors.EBADF('descriptor does not permit writing'));
} else { } else {
if(validateInteger(length, callback) !== length) return;
ftruncate_file(context, ofd, length, callback); ftruncate_file(context, ofd, length, callback);
} }
} }

View File

@ -1,5 +1,3 @@
var Errors = require('./errors.js');
function guid() { function guid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
@ -9,22 +7,7 @@ function guid() {
function nop() {} 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 = { module.exports = {
guid: guid, guid: guid,
nop: nop, nop: nop
validateInteger: validateInteger,
}; };