Add Headless Firefox test support, fix failing truncate test in Firefox
This commit is contained in:
parent
cc6e3f7edf
commit
395406609d
|
@ -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 &
|
||||
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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",
|
||||
|
|
10
package.json
10
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",
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue