-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit test files as modules #7934
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please squash into single commit
AnnotationBorderStyleType, StringStream, Lexer, Parser, | ||
stringToUTF8String, AnnotationFieldFlag, PDFJS, stringToBytes */ | ||
|
||
/* Copyright 2012 Mozilla Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2017
year.
if (typeof define === 'function' && define.amd) { | ||
define('pdfjs-test/unit/annotation_layer_spec', ['exports', 'pdfjs/core/primitives','pdfjs/core/annotation','pdfjs/core/stream','pdfjs/core/parser','pdfjs/shared/util','pdfjs/display/global'], factory); | ||
} else if (typeof exports !== 'undefined') { | ||
factory(exports, require('../core/primitives.js'),require('../core/anotation.js'),require('../core/stream.js'),require('../core/parser.js'),require('../shared/util.js'),require('../display/global.js')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CommonJS modules are located at "../../src/core" and "../../src/display" also break down long lines at 80 chars
window[name] = lib[name]; | ||
}); | ||
}); | ||
require.config({paths: {'pdfjs': '../../src', 'pdfjs-web': '../../web','pdfjs-test':'../../test'}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'pdfjs-test':'..'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the commit message to something a bit more descriptive than just "modularized", such that it's possible to understand what the patch does when looking at it e.g. from the Git command line.
root.pdfjsSharedUtil, root.pdfjsDisplayGlobal); | ||
} | ||
}(this, function (exports, corePrimitives, coreAnnotation, coreStream, | ||
coreParser, sharedUtil, displayGlobal) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Please change the indentation of this line so that the parameter names line up, compare with e.g. this file; it should look like this:
}(this, function (exports, corePrimitives, coreAnnotation, coreStream,
coreParser, sharedUtil, displayGlobal) {
root.pdfjsSharedUtil); | ||
} | ||
}(this, function (exports, coreEvaluator, corePrimitives, coreStream, | ||
coreWorker, sharedUtil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Please change the indentation of this line so that the parameter names line up, compare with e.g. this file; it should look like this:
}(this, function (exports, coreEvaluator, corePrimitives, coreStream,
coreWorker, sharedUtil) {
testUnitFunctionSpec, testUnitMetadataSpec, testUnitMurmurHash3Spec, | ||
testUnitNetworkSpec, testUnitParserSpec, testUnitPrimitivesSpec, | ||
testUnitStreamSpec, testUnitType1ParserSpec, testUnitUiUtilsSpec, | ||
testUnitUnicodeSpec, testUnitUtilSpec) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Please change the indentation of this line so that the parameter names line up, compare with e.g. this file; it should look like this:
function (displayGlobal, testUnitAnnotationLayerSpec, testUnitApiSpec,
testUnitCFFParserSpec, testUnitCMapSpec, testUnitCryptoSpec,
testUnitDOMUtilsSpec, testUnitEvaluatorSpec, testUnitFontsSpec,
testUnitFunctionSpec, testUnitMetadataSpec, testUnitMurmurHash3Spec,
testUnitNetworkSpec, testUnitParserSpec, testUnitPrimitivesSpec,
testUnitStreamSpec, testUnitType1ParserSpec, testUnitUiUtilsSpec,
testUnitUnicodeSpec, testUnitUtilSpec) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
@@ -11,26 +11,6 @@ | |||
<script src="testreporter.js"></script> | |||
<script src="jasmine-boot.js"></script> | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove this empty line as well
/botio unittest |
From: Bot.io (Linux)ReceivedCommand cmd_unittest from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/dff49b765a152db/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_unittest from @timvandermeij received. Current queue size: 0 Live output at: http://107.22.172.223:8877/7df89dba73fafcd/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/dff49b765a152db/output.txt Total script time: 2.06 mins
|
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/7df89dba73fafcd/output.txt Total script time: 2.53 mins
|
Looks really good so far. Could you add the following changes to your patch and fix rest of the lint issues? diff --git a/external/umdutils/verifier.js b/external/umdutils/verifier.js
index f5678fd..d763508 100644
--- a/external/umdutils/verifier.js
+++ b/external/umdutils/verifier.js
@@ -305,9 +305,30 @@ function validateFile(path, name, context) {
parts.shift();
}
while (parts[0] === '..') {
+ if (base.length === 0) {
+ error('Invalid relative CommonJS path');
+ }
parts.shift();
base.pop();
}
+ if (base.length === 0) {
+ // Reached the project root -- finding prefix matching subpath.
+ for (var prefix in context.paths) {
+ if (!context.paths.hasOwnProperty(prefix)) {
+ continue;
+ }
+ var prefixPath = context.paths[prefix];
+ if (!('./' + parts.join('/') + '/').startsWith(prefixPath + '/')) {
+ continue;
+ }
+ parts.splice(0, prefixPath.split('/').length - 1);
+ base.push(prefix);
+ break;
+ }
+ if (base.length === 0) {
+ error('Invalid relative CommonJS path prefix');
+ }
+ }
if (j !== base.concat(parts).join('/')) {
error('CommonJS path does not point to right AMD module: ' +
i + ' vs ' + j);
@@ -473,6 +494,7 @@ function validateFiles(paths, options) {
exports: Object.create(null),
imports: Object.create(null),
dependencies: Object.create(null),
+ paths: paths,
errorCallback: errorCallback,
warnCallback: warnCallback,
infoCallback: infoCallback
diff --git a/gulpfile.js b/gulpfile.js
index 1cdc1c1..21367d7 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -541,7 +541,12 @@ gulp.task('lint', function (done) {
console.log();
console.log('### Checking UMD dependencies');
var umd = require('./external/umdutils/verifier.js');
- if (!umd.validateFiles({'pdfjs': './src', 'pdfjs-web': './web'})) {
+ var paths = {
+ 'pdfjs': './src',
+ 'pdfjs-web': './web',
+ 'pdfjs-test': './test'
+ };
+ if (!umd.validateFiles(paths)) {
done(new Error('UMD check failed.'));
return;
}
diff --git a/test/unit/crypto_spec.js b/test/unit/crypto_spec.js
index c07c754..7234689 100644
--- a/test/unit/crypto_spec.js
+++ b/test/unit/crypto_spec.js
@@ -23,7 +23,7 @@
require('../../src/core/primitives.js'),
require('../../src/shared/util.js'));
} else {
- factory((root.pdfjsTestCryptoSpec = {}), root.pdfjsCoreCrypto,
+ factory((root.pdfjsTestUnitCryptoSpec = {}), root.pdfjsCoreCrypto,
root.pdfjsCorePrimitives, root.pdfjsSharedUtil);
}
}(this, function (exports, coreCrypto, corePrimitives, sharedUtil) { |
require('../../src/core/parser.js'), | ||
require('../../src/shared/util.js'), | ||
require('../../src/display/global.js')); | ||
require('pdfjs/core/anotation.js'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it needs to be require('../../src/core/annotation.js'),
/botio-linux unittest |
From: Bot.io (Linux)ReceivedCommand cmd_unittest from @yurydelendik received. Current queue size: 0 Live output at: http://107.21.233.14:8877/8287dfd24cb9418/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/8287dfd24cb9418/output.txt Total script time: 2.00 mins
|
Hi Yury, thanks for the help. Should I squash those commits? |
Yes, please |
/botio test |
From: Bot.io (Linux)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://107.21.233.14:8877/281588546298918/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://107.22.172.223:8877/6960a0640e47609/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/6960a0640e47609/output.txt Total script time: 25.52 mins
|
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/281588546298918/output.txt Total script time: 26.11 mins
|
Thank you for the patch. |
Nice contribution, thanks! |
Unit test files as modules
I changed the unit test files to UMD modules. I also changed the jasmine-boot.js file to load up the unit test modules and got rid of the lines that load up global variables. I also changed the unit_test.html file by removing the script tags for the unit test files, since they are now loaded in jasmine-boot.js
Fixes #7179