Merge pull request #9415 from Snuffleupagus/clitests-PDFNodeStream
Utilize `PDFNodeStream` to run more API unit-tests on Node.js/Travis
This commit is contained in:
commit
55e3f97aa9
@ -61,9 +61,6 @@ describe('api', function() {
|
||||
describe('PDFJS', function() {
|
||||
describe('getDocument', function() {
|
||||
it('creates pdf doc from URL', function(done) {
|
||||
if (isNodeJS()) {
|
||||
pending('XMLHttpRequest is not supported in Node.js.');
|
||||
}
|
||||
var loadingTask = getDocument(basicApiGetDocumentParams);
|
||||
|
||||
var isProgressReportedResolved = false;
|
||||
@ -93,9 +90,6 @@ describe('api', function() {
|
||||
});
|
||||
it('creates pdf doc from URL and aborts before worker initialized',
|
||||
function(done) {
|
||||
if (isNodeJS()) {
|
||||
pending('XMLHttpRequest is not supported in Node.js.');
|
||||
}
|
||||
var loadingTask = getDocument(basicApiGetDocumentParams);
|
||||
let destroyed = loadingTask.destroy();
|
||||
|
||||
@ -108,9 +102,6 @@ describe('api', function() {
|
||||
});
|
||||
it('creates pdf doc from URL and aborts loading after worker initialized',
|
||||
function(done) {
|
||||
if (isNodeJS()) {
|
||||
pending('XMLHttpRequest is not supported in Node.js.');
|
||||
}
|
||||
var loadingTask = getDocument(basicApiGetDocumentParams);
|
||||
// This can be somewhat random -- we cannot guarantee perfect
|
||||
// 'Terminate' message to the worker before/after setting up pdfManager.
|
||||
|
@ -1,5 +1,10 @@
|
||||
{
|
||||
"spec_dir": "build/lib/test/unit",
|
||||
|
||||
"helpers": [
|
||||
"clitests_helper.js"
|
||||
],
|
||||
|
||||
"spec_files": [
|
||||
"annotation_spec.js",
|
||||
"api_spec.js",
|
||||
|
29
test/unit/clitests_helper.js
Normal file
29
test/unit/clitests_helper.js
Normal file
@ -0,0 +1,29 @@
|
||||
/* Copyright 2018 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import isNodeJS from '../../src/shared/is_node';
|
||||
import { PDFNodeStream } from '../../src/display/node_stream';
|
||||
import { setPDFNetworkStreamFactory } from '../../src/display/api';
|
||||
|
||||
// Ensure that this script only runs in Node.js environments.
|
||||
if (!isNodeJS()) {
|
||||
throw new Error('The `gulp unittestcli` command can only be used in ' +
|
||||
'Node.js environments.');
|
||||
}
|
||||
|
||||
// Set the network stream factory for the unit-tests.
|
||||
setPDFNetworkStreamFactory(function(params) {
|
||||
return new PDFNodeStream(params);
|
||||
});
|
@ -46,6 +46,7 @@ function initializePDFJS(callback) {
|
||||
'pdfjs/display/api',
|
||||
'pdfjs/display/network',
|
||||
'pdfjs/display/fetch_stream',
|
||||
'pdfjs/shared/is_node',
|
||||
'pdfjs-test/unit/annotation_spec',
|
||||
'pdfjs-test/unit/api_spec',
|
||||
'pdfjs-test/unit/bidi_spec',
|
||||
@ -81,8 +82,13 @@ function initializePDFJS(callback) {
|
||||
var displayApi = modules[1];
|
||||
var PDFNetworkStream = modules[2].PDFNetworkStream;
|
||||
var PDFFetchStream = modules[3].PDFFetchStream;
|
||||
const isNodeJS = modules[4];
|
||||
|
||||
// Set network stream class for unit tests.
|
||||
if (isNodeJS()) {
|
||||
throw new Error('The `gulp unittest` command cannot be used in ' +
|
||||
'Node.js environments.');
|
||||
}
|
||||
// Set the network stream factory for unit-tests.
|
||||
if (typeof Response !== 'undefined' && 'body' in Response.prototype &&
|
||||
typeof ReadableStream !== 'undefined') {
|
||||
displayApi.setPDFNetworkStreamFactory(function(params) {
|
||||
|
@ -33,9 +33,7 @@ const TEST_PDFS_PATH = {
|
||||
function buildGetDocumentParams(filename, options) {
|
||||
let params = Object.create(null);
|
||||
if (isNodeJS()) {
|
||||
params.data = NodeFileReaderFactory.fetch({
|
||||
path: TEST_PDFS_PATH.node + filename,
|
||||
});
|
||||
params.url = TEST_PDFS_PATH.node + filename;
|
||||
} else {
|
||||
params.url = new URL(TEST_PDFS_PATH.dom + filename, window.location).href;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user