Skip to content

Commit ae04cf1

Browse files
committed
Enable running the ui_utils unit-tests on Travis
With the exception of just one test-case, all the current `ui_utils` unit-tests can run successfully on Node.js (since most of them doesn't rely on the DOM). To get this working, I had to first of all add a new `LIB` build flag such that `gulp lib` produces a `web/pdfjs.js` file that is able to load `pdf.js` successfully. Second of all, since neither `document` nor `navigator` is available in Node.js, `web/ui_utils.js` was adjusted slightly to avoid errors.
1 parent 5fe26bb commit ae04cf1

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

gulpfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ var DEFINES = {
7777
MINIFIED: false,
7878
SINGLE_FILE: false,
7979
COMPONENTS: false,
80+
LIB: false,
8081
PDFJS_NEXT: false,
8182
};
8283

@@ -998,6 +999,7 @@ gulp.task('lib', ['buildnumber'], function () {
998999
saveComments: false,
9991000
defines: builder.merge(DEFINES, {
10001001
GENERIC: true,
1002+
LIB: true,
10011003
BUNDLE_VERSION: versionInfo.version,
10021004
BUNDLE_BUILD: versionInfo.commit
10031005
})

test/unit/clitests.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"primitives_spec.js",
1717
"stream_spec.js",
1818
"type1_parser_spec.js",
19+
"ui_utils_spec.js",
1920
"unicode_spec.js",
2021
"util_spec.js"
2122
]

test/unit/ui_utils_spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var binarySearchFirstItem = webUiUtils.binarySearchFirstItem;
3131
var getPDFFileNameFromURL = webUiUtils.getPDFFileNameFromURL;
3232
var EventBus = webUiUtils.EventBus;
3333
var createObjectURL = sharedUtil.createObjectURL;
34+
var isNodeJS = sharedUtil.isNodeJS;
3435

3536
describe('ui_utils', function() {
3637
describe('binary search', function() {
@@ -160,6 +161,9 @@ describe('ui_utils', function() {
160161

161162
it('gets PDF filename from query string appended to "blob:" URL',
162163
function() {
164+
if (isNodeJS()) {
165+
pending('Blob in not supported in Node.js.');
166+
}
163167
var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
164168
var blobUrl = createObjectURL(typedArray, 'application/pdf');
165169
// Sanity check to ensure that a "blob:" URL was returned.

web/pdfjs.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
2323
if (typeof window !== 'undefined' && window['pdfjs-dist/build/pdf']) {
2424
pdfjsLib = window['pdfjs-dist/build/pdf'];
2525
} else if (typeof require === 'function') {
26-
pdfjsLib = require('../build/pdf.js');
26+
if (PDFJSDev.test('LIB')) {
27+
pdfjsLib = require('../pdf.js');
28+
} else {
29+
pdfjsLib = require('../build/pdf.js');
30+
}
2731
} else {
2832
throw new Error('Neither `require` nor `window` found');
2933
}

web/ui_utils.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ var RendererType = {
3030
SVG: 'svg',
3131
};
3232

33-
var mozL10n = document.mozL10n || document.webL10n;
33+
var mozL10n = typeof document !== 'undefined' ?
34+
(document.mozL10n || document.webL10n) : undefined;
3435

3536
/**
3637
* Disables fullscreen support, and by extension Presentation Mode,
@@ -81,8 +82,9 @@ if (typeof PDFJSDev === 'undefined' ||
8182
* Interface locale settings.
8283
* @var {string}
8384
*/
84-
PDFJS.locale = (PDFJS.locale === undefined ? navigator.language :
85-
PDFJS.locale);
85+
PDFJS.locale =
86+
(PDFJS.locale === undefined && typeof navigator !== 'undefined' ?
87+
navigator.language : PDFJS.locale);
8688
}
8789

8890
/**

0 commit comments

Comments
 (0)