Merge pull request #9769 from Snuffleupagus/node-unittest-rm-console-errors

Reduce the amount of errors logged, primarily in Node.js/Travis, when running the unit-tests
This commit is contained in:
Tim van der Meij 2018-06-03 19:50:42 +02:00 committed by GitHub
commit 8ce24744f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 22 deletions

View File

@ -56,14 +56,8 @@ var pdfURL = '../../../web/compressed.tracemonkey-pldi-09.pdf';
// Read the PDF file into a typed array so PDF.js can load it. // Read the PDF file into a typed array so PDF.js can load it.
var rawData = new Uint8Array(fs.readFileSync(pdfURL)); var rawData = new Uint8Array(fs.readFileSync(pdfURL));
// Load the PDF file. The `disableFontFace` and `nativeImageDecoderSupport` // Load the PDF file.
// options must be passed because Node.js has no native `@font-face` and pdfjsLib.getDocument(rawData).then(function (pdfDocument) {
// `Image` support.
pdfjsLib.getDocument({
data: rawData,
disableFontFace: true,
nativeImageDecoderSupport: 'none',
}).then(function (pdfDocument) {
console.log('# PDF document loaded.'); console.log('# PDF document loaded.');
// Get the first page. // Get the first page.

View File

@ -574,9 +574,9 @@ var WorkerMessageHandler = {
finishWorkerTask(task); finishWorkerTask(task);
pdfManager.updatePassword(data.password); pdfManager.updatePassword(data.password);
pdfManagerReady(); pdfManagerReady();
}).catch(function (ex) { }).catch(function (boundException) {
finishWorkerTask(task); finishWorkerTask(task);
handler.send('PasswordException', ex); handler.send('PasswordException', boundException);
}.bind(null, e)); }.bind(null, e));
} else if (e instanceof InvalidPDFException) { } else if (e instanceof InvalidPDFException) {
handler.send('InvalidPDF', e); handler.send('InvalidPDF', e);

View File

@ -274,7 +274,9 @@ function getDocument(src) {
const NativeImageDecoderValues = Object.values(NativeImageDecoding); const NativeImageDecoderValues = Object.values(NativeImageDecoding);
if (params.nativeImageDecoderSupport === undefined || if (params.nativeImageDecoderSupport === undefined ||
!NativeImageDecoderValues.includes(params.nativeImageDecoderSupport)) { !NativeImageDecoderValues.includes(params.nativeImageDecoderSupport)) {
params.nativeImageDecoderSupport = NativeImageDecoding.DECODE; params.nativeImageDecoderSupport =
(apiCompatibilityParams.nativeImageDecoderSupport ||
NativeImageDecoding.DECODE);
} }
if (!Number.isInteger(params.maxImageSize)) { if (!Number.isInteger(params.maxImageSize)) {
params.maxImageSize = -1; params.maxImageSize = -1;
@ -283,7 +285,7 @@ function getDocument(src) {
params.isEvalSupported = true; params.isEvalSupported = true;
} }
if (typeof params.disableFontFace !== 'boolean') { if (typeof params.disableFontFace !== 'boolean') {
params.disableFontFace = false; params.disableFontFace = apiCompatibilityParams.disableFontFace || false;
} }
if (typeof params.disableRange !== 'boolean') { if (typeof params.disableRange !== 'boolean') {
@ -1786,7 +1788,11 @@ var WorkerTransport = (function WorkerTransportClosure() {
password, password,
}); });
}; };
loadingTask.onPassword(updatePassword, exception.code); try {
loadingTask.onPassword(updatePassword, exception.code);
} catch (ex) {
this._passwordCapability.reject(ex);
}
} else { } else {
this._passwordCapability.reject( this._passwordCapability.reject(
new PasswordException(exception.message, exception.code)); new PasswordException(exception.message, exception.code));
@ -2168,6 +2174,8 @@ var WorkerTransport = (function WorkerTransportClosure() {
disableStream: params.disableStream, disableStream: params.disableStream,
disableAutoFetch: params.disableAutoFetch, disableAutoFetch: params.disableAutoFetch,
disableCreateObjectURL: params.disableCreateObjectURL, disableCreateObjectURL: params.disableCreateObjectURL,
disableFontFace: params.disableFontFace,
nativeImageDecoderSupport: params.nativeImageDecoderSupport,
}); });
}, },
}; };

View File

@ -15,6 +15,8 @@
let compatibilityParams = Object.create(null); let compatibilityParams = Object.create(null);
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
const isNodeJS = require('../shared/is_node');
const userAgent = const userAgent =
(typeof navigator !== 'undefined' && navigator.userAgent) || ''; (typeof navigator !== 'undefined' && navigator.userAgent) || '';
const isIE = /Trident/.test(userAgent); const isIE = /Trident/.test(userAgent);
@ -42,9 +44,15 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
compatibilityParams.disableStream = true; compatibilityParams.disableStream = true;
} }
})(); })();
}
const apiCompatibilityParams = Object.freeze(compatibilityParams);
export { // Support: Node.js
apiCompatibilityParams, (function checkFontFaceAndImage() {
}; // Node.js is missing native support for `@font-face` and `Image`.
if (isNodeJS()) {
compatibilityParams.disableFontFace = true;
compatibilityParams.nativeImageDecoderSupport = 'none';
}
})();
}
exports.apiCompatibilityParams = Object.freeze(compatibilityParams);

View File

@ -13,6 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { setVerbosityLevel, VerbosityLevel } from '../../src/shared/util';
import isNodeJS from '../../src/shared/is_node'; import isNodeJS from '../../src/shared/is_node';
import { PDFNodeStream } from '../../src/display/node_stream'; import { PDFNodeStream } from '../../src/display/node_stream';
import { setPDFNetworkStreamFactory } from '../../src/display/api'; import { setPDFNetworkStreamFactory } from '../../src/display/api';
@ -23,6 +24,10 @@ if (!isNodeJS()) {
'Node.js environments.'); 'Node.js environments.');
} }
// Reduce the amount of console "spam", by ignoring `info`/`warn` calls,
// when running the unit-tests in Node.js/Travis.
setVerbosityLevel(VerbosityLevel.ERRORS);
// Set the network stream factory for the unit-tests. // Set the network stream factory for the unit-tests.
setPDFNetworkStreamFactory(function(params) { setPDFNetworkStreamFactory(function(params) {
return new PDFNodeStream(params); return new PDFNodeStream(params);

View File

@ -681,6 +681,13 @@ function waitOnEventOrTimeout({ target, name, delay = 0, }) {
* Promise that is resolved when DOM window becomes visible. * Promise that is resolved when DOM window becomes visible.
*/ */
let animationStarted = new Promise(function (resolve) { let animationStarted = new Promise(function (resolve) {
if ((typeof PDFJSDev !== 'undefined' && PDFJSDev.test('LIB')) &&
typeof window === 'undefined') {
// Prevent "ReferenceError: window is not defined" errors when running the
// unit-tests in Node.js/Travis.
setTimeout(resolve, 20);
return;
}
window.requestAnimationFrame(resolve); window.requestAnimationFrame(resolve);
}); });

View File

@ -37,8 +37,5 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
} }
})(); })();
} }
const viewerCompatibilityParams = Object.freeze(compatibilityParams);
export { exports.viewerCompatibilityParams = Object.freeze(compatibilityParams);
viewerCompatibilityParams,
};