Merge pull request #4515 from yurydelendik/nodetest
Replaces test.py with test.js
This commit is contained in:
commit
19a548ef0d
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "test/ttx/fonttools-code"]
|
||||||
|
path = test/ttx/fonttools-code
|
||||||
|
url = git://git.code.sf.net/p/fonttools/code
|
||||||
18
make.js
18
make.js
@ -40,7 +40,6 @@ var ROOT_DIR = __dirname + '/', // absolute path to project's root
|
|||||||
GENERIC_DIR = BUILD_DIR + 'generic/',
|
GENERIC_DIR = BUILD_DIR + 'generic/',
|
||||||
MINIFIED_DIR = BUILD_DIR + 'minified/',
|
MINIFIED_DIR = BUILD_DIR + 'minified/',
|
||||||
REPO = 'git@github.com:mozilla/pdf.js.git',
|
REPO = 'git@github.com:mozilla/pdf.js.git',
|
||||||
PYTHON_BIN = 'python2.7',
|
|
||||||
MOZCENTRAL_PREF_PREFIX = 'pdfjs',
|
MOZCENTRAL_PREF_PREFIX = 'pdfjs',
|
||||||
FIREFOX_PREF_PREFIX = 'extensions.uriloader@pdf.js',
|
FIREFOX_PREF_PREFIX = 'extensions.uriloader@pdf.js',
|
||||||
MOZCENTRAL_STREAM_CONVERTER_ID = 'd0c5195d-e798-49d4-b1d3-9324328b2291',
|
MOZCENTRAL_STREAM_CONVERTER_ID = 'd0c5195d-e798-49d4-b1d3-9324328b2291',
|
||||||
@ -1005,7 +1004,7 @@ target.browsertest = function(options) {
|
|||||||
var reftest = (options && options.noreftest) ? '' : '--reftest';
|
var reftest = (options && options.noreftest) ? '' : '--reftest';
|
||||||
|
|
||||||
cd('test');
|
cd('test');
|
||||||
exec(PYTHON_BIN + ' -u test.py ' + reftest + ' --browserManifestFile=' +
|
exec('node test.js ' + reftest + ' --browserManifestFile=' +
|
||||||
PDF_BROWSERS + ' --manifestFile=' + PDF_TEST, {async: true});
|
PDF_BROWSERS + ' --manifestFile=' + PDF_TEST, {async: true});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1027,7 +1026,7 @@ target.unittest = function(options, callback) {
|
|||||||
}
|
}
|
||||||
callback = callback || function() {};
|
callback = callback || function() {};
|
||||||
cd('test');
|
cd('test');
|
||||||
exec(PYTHON_BIN + ' -u test.py --unitTest --browserManifestFile=' +
|
exec('node test.js --unitTest --browserManifestFile=' +
|
||||||
PDF_BROWSERS, {async: true}, callback);
|
PDF_BROWSERS, {async: true}, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1049,7 +1048,7 @@ target.fonttest = function(options, callback) {
|
|||||||
}
|
}
|
||||||
callback = callback || function() {};
|
callback = callback || function() {};
|
||||||
cd('test');
|
cd('test');
|
||||||
exec(PYTHON_BIN + ' -u test.py --fontTest --browserManifestFile=' +
|
exec('node test.js --fontTest --browserManifestFile=' +
|
||||||
PDF_BROWSERS, {async: true}, callback);
|
PDF_BROWSERS, {async: true}, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1072,7 +1071,7 @@ target.botmakeref = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cd('test');
|
cd('test');
|
||||||
exec(PYTHON_BIN + ' -u test.py --masterMode --noPrompts ' +
|
exec('node test.js --masterMode --noPrompts ' +
|
||||||
'--browserManifestFile=' + PDF_BROWSERS, {async: true});
|
'--browserManifestFile=' + PDF_BROWSERS, {async: true});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1251,8 +1250,10 @@ target.server = function() {
|
|||||||
echo();
|
echo();
|
||||||
echo('### Starting local server');
|
echo('### Starting local server');
|
||||||
|
|
||||||
cd('test');
|
var WebServer = require('./test/webserver.js').WebServer;
|
||||||
exec(PYTHON_BIN + ' -u test.py --port=8888 --noDownload', {async: true});
|
var server = new WebServer();
|
||||||
|
server.port = 8888;
|
||||||
|
server.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -1268,8 +1269,7 @@ target.lint = function() {
|
|||||||
'external/crlfchecker/',
|
'external/crlfchecker/',
|
||||||
'src/',
|
'src/',
|
||||||
'web/',
|
'web/',
|
||||||
'test/driver.js',
|
'test/*.js',
|
||||||
'test/reporter.js',
|
|
||||||
'test/unit/',
|
'test/unit/',
|
||||||
'extensions/firefox/',
|
'extensions/firefox/',
|
||||||
'extensions/chromium/'
|
'extensions/chromium/'
|
||||||
|
|||||||
@ -2,7 +2,8 @@
|
|||||||
"name": "pdf.js",
|
"name": "pdf.js",
|
||||||
"version": "0.8.0",
|
"version": "0.8.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"jshint": "2.4.x"
|
"jshint": "2.4.x",
|
||||||
|
"yargs": "~1.2.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node make lint"
|
"test": "node make lint"
|
||||||
|
|||||||
173
test/downloadutils.js
Normal file
173
test/downloadutils.js
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil; tab-width: 2 -*- */
|
||||||
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||||
|
/*
|
||||||
|
* Copyright 2014 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.
|
||||||
|
*/
|
||||||
|
/*jslint node: true */
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var fs = require('fs');
|
||||||
|
var crypto = require('crypto');
|
||||||
|
var http = require('http');
|
||||||
|
var https = require('https');
|
||||||
|
|
||||||
|
function downloadFile(file, url, callback, redirects) {
|
||||||
|
var completed = false;
|
||||||
|
var protocol = /^https:\/\//.test(url) ? https : http;
|
||||||
|
protocol.get(url, function (response) {
|
||||||
|
if (response.statusCode === 301 || response.statusCode === 302 ||
|
||||||
|
response.statusCode === 307 || response.statusCode === 308) {
|
||||||
|
if (redirects > 10) {
|
||||||
|
callback('Too many redirects');
|
||||||
|
}
|
||||||
|
var redirectTo = response.headers.location;
|
||||||
|
redirectTo = require('url').resolve(url, redirectTo);
|
||||||
|
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (response.statusCode === 404 && url.indexOf('web.archive.org') < 0) {
|
||||||
|
// trying waybackmachine
|
||||||
|
var redirectTo = 'http://web.archive.org/web/' + url;
|
||||||
|
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.statusCode !== 200) {
|
||||||
|
if (!completed) {
|
||||||
|
completed = true;
|
||||||
|
callback('HTTP ' + response.statusCode);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var stream = fs.createWriteStream(file);
|
||||||
|
stream.on('error', function (err) {
|
||||||
|
if (!completed) {
|
||||||
|
completed = true;
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
response.pipe(stream);
|
||||||
|
stream.on('finish', function() {
|
||||||
|
stream.close();
|
||||||
|
if (!completed) {
|
||||||
|
completed = true;
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).on('error', function (err) {
|
||||||
|
if (!completed) {
|
||||||
|
if (typeof err === 'object' && err.errno === 'ENOTFOUND' &&
|
||||||
|
url.indexOf('web.archive.org') < 0) {
|
||||||
|
// trying waybackmachine
|
||||||
|
var redirectTo = 'http://web.archive.org/web/' + url;
|
||||||
|
downloadFile(file, redirectTo, callback, (redirects || 0) + 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
completed = true;
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadManifestFiles(manifest, callback) {
|
||||||
|
function downloadNext() {
|
||||||
|
if (i >= links.length) {
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var file = links[i].file;
|
||||||
|
var url = links[i].url;
|
||||||
|
console.log('Downloading ' + url + ' to ' + file + '...');
|
||||||
|
downloadFile(file, url, function (err) {
|
||||||
|
if (err) {
|
||||||
|
console.error('Error during downloading of ' + url + ': ' + err);
|
||||||
|
fs.writeFileSync(file, ''); // making it empty file
|
||||||
|
fs.writeFileSync(file + '.error', err);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
downloadNext();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var links = manifest.filter(function (item) {
|
||||||
|
return item.link && !fs.existsSync(item.file);
|
||||||
|
}).map(function (item) {
|
||||||
|
var file = item.file;
|
||||||
|
var linkfile = file + '.link';
|
||||||
|
var url = fs.readFileSync(linkfile).toString();
|
||||||
|
url = url.replace(/\s+$/, '');
|
||||||
|
return {file: file, url: url};
|
||||||
|
});
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
downloadNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateMD5(file, callback) {
|
||||||
|
var hash = crypto.createHash('md5');
|
||||||
|
var stream = fs.createReadStream(file);
|
||||||
|
stream.on('data', function (data) {
|
||||||
|
hash.update(data);
|
||||||
|
});
|
||||||
|
stream.on('error', function (err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
stream.on('end', function() {
|
||||||
|
var result = hash.digest('hex');
|
||||||
|
callback(null, result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function verifyManifestFiles(manifest, callback) {
|
||||||
|
function verifyNext() {
|
||||||
|
if (i >= manifest.length) {
|
||||||
|
callback(error);
|
||||||
|
return;
|
||||||