Add a TESTING build option, to enable using non-production/test-only code-paths
Since the tests (currently) run with the `pdf.worker.js` file built, i.e. with `PRODUCTION = true` set, there's no simple way to add e.g. `assert` calls for both non-production *and* test-only builds without also affecting PRODUCTION builds.
This commit is contained in:
parent
f01e54eae1
commit
4b69bb7fe9
24
gulpfile.js
24
gulpfile.js
@ -86,6 +86,7 @@ var AUTOPREFIXER_CONFIG = {
|
||||
|
||||
var DEFINES = {
|
||||
PRODUCTION: true,
|
||||
TESTING: false,
|
||||
// The main build targets:
|
||||
GENERIC: false,
|
||||
FIREFOX: false,
|
||||
@ -137,6 +138,7 @@ function createWebpackConfig(defines, output) {
|
||||
var bundleDefines = builder.merge(defines, {
|
||||
BUNDLE_VERSION: versionInfo.version,
|
||||
BUNDLE_BUILD: versionInfo.commit,
|
||||
TESTING: (defines.TESTING || process.env['TESTING'] === 'true'),
|
||||
});
|
||||
var licenseHeaderLibre =
|
||||
fs.readFileSync('./src/license_header_libre.js').toString();
|
||||
@ -875,6 +877,7 @@ gulp.task('lib', ['buildnumber'], function () {
|
||||
LIB: true,
|
||||
BUNDLE_VERSION: versionInfo.version,
|
||||
BUNDLE_BUILD: versionInfo.commit,
|
||||
TESTING: process.env['TESTING'] === 'true',
|
||||
}),
|
||||
map: {
|
||||
'pdfjs-lib': '../pdf',
|
||||
@ -927,34 +930,39 @@ gulp.task('publish', ['generic'], function (done) {
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('test', ['generic', 'components'], function () {
|
||||
gulp.task('testing-pre', function() {
|
||||
process.env['TESTING'] = 'true';
|
||||
});
|
||||
|
||||
gulp.task('test', ['testing-pre', 'generic', 'components'], function() {
|
||||
return streamqueue({ objectMode: true, },
|
||||
createTestSource('unit'), createTestSource('browser'));
|
||||
});
|
||||
|
||||
gulp.task('bottest', ['generic', 'components'], function () {
|
||||
gulp.task('bottest', ['testing-pre', 'generic', 'components'], function() {
|
||||
return streamqueue({ objectMode: true, },
|
||||
createTestSource('unit'), createTestSource('font'),
|
||||
createTestSource('browser (no reftest)'));
|
||||
});
|
||||
|
||||
gulp.task('browsertest', ['generic', 'components'], function () {
|
||||
gulp.task('browsertest', ['testing-pre', 'generic', 'components'], function() {
|
||||
return createTestSource('browser');
|
||||
});
|
||||
|
||||
gulp.task('unittest', ['generic', 'components'], function () {
|
||||
gulp.task('unittest', ['testing-pre', 'generic', 'components'], function() {
|
||||
return createTestSource('unit');
|
||||
});
|
||||
|
||||
gulp.task('fonttest', function () {
|
||||
gulp.task('fonttest', ['testing-pre'], function() {
|
||||
return createTestSource('font');
|
||||
});
|
||||
|
||||
gulp.task('makeref', ['generic', 'components'], function (done) {
|
||||
gulp.task('makeref', ['testing-pre', 'generic', 'components'], function(done) {
|
||||
makeRef(done);
|
||||
});
|
||||
|
||||
gulp.task('botmakeref', ['generic', 'components'], function (done) {
|
||||
gulp.task('botmakeref', ['testing-pre', 'generic', 'components'],
|
||||
function(done) {
|
||||
makeRef(done, true);
|
||||
});
|
||||
|
||||
@ -994,7 +1002,7 @@ gulp.task('baseline', function (done) {
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('unittestcli', ['lib'], function (done) {
|
||||
gulp.task('unittestcli', ['testing-pre', 'lib'], function(done) {
|
||||
var args = ['JASMINE_CONFIG_PATH=test/unit/clitests.json'];
|
||||
var testProcess = spawn('node_modules/.bin/jasmine', args,
|
||||
{ stdio: 'inherit', });
|
||||
|
@ -34,8 +34,10 @@ const MAX_ADLER32_LENGTH = 5552;
|
||||
|
||||
function computeAdler32(bytes) {
|
||||
let bytesLength = bytes.length;
|
||||
if (bytesLength >= MAX_ADLER32_LENGTH) {
|
||||
throw new Error('computeAdler32: The input is too large.');
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
PDFJSDev.test('!PRODUCTION || TESTING')) {
|
||||
assert(bytesLength < MAX_ADLER32_LENGTH,
|
||||
'computeAdler32: Unsupported "bytes" length.');
|
||||
}
|
||||
let a = 1, b = 0;
|
||||
for (let i = 0; i < bytesLength; ++i) {
|
||||
|
@ -379,8 +379,10 @@ var WorkerMessageHandler = {
|
||||
let apiVersion = docParams.apiVersion;
|
||||
let workerVersion =
|
||||
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : null;
|
||||
// The `apiVersion !== null` check is needed to avoid errors during testing.
|
||||
if (apiVersion !== null && apiVersion !== workerVersion) {
|
||||
if ((typeof PDFJSDev !== 'undefined' && PDFJSDev.test('TESTING')) &&
|
||||
apiVersion === null) {
|
||||
warn('Ignoring apiVersion/workerVersion check in TESTING builds.');
|
||||
} else if (apiVersion !== workerVersion) {
|
||||
throw new Error(`The API version "${apiVersion}" does not match ` +
|
||||
`the Worker version "${workerVersion}".`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user