Skip to content
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

Merged
merged 1 commit into from
Jan 9, 2017
Merged

Unit test files as modules #7934

merged 1 commit into from
Jan 9, 2017

Conversation

porlan1
Copy link
Contributor

@porlan1 porlan1 commented Jan 6, 2017

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

Copy link
Contributor

@yurydelendik yurydelendik left a 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
Copy link
Contributor

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'));
Copy link
Contributor

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'}});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'pdfjs-test':'..'

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a 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) {
Copy link
Collaborator

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) {
Copy link
Collaborator

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) {
Copy link
Collaborator

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) {

Copy link
Contributor

@timvandermeij timvandermeij left a 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>

Copy link
Contributor

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

@timvandermeij
Copy link
Contributor

/botio unittest

@pdfjsbot
Copy link

pdfjsbot commented Jan 8, 2017

From: Bot.io (Linux)


Received

Command cmd_unittest from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/dff49b765a152db/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 8, 2017

From: Bot.io (Windows)


Received

Command cmd_unittest from @timvandermeij received. Current queue size: 0

Live output at: http://107.22.172.223:8877/7df89dba73fafcd/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 8, 2017

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/dff49b765a152db/output.txt

Total script time: 2.06 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Jan 8, 2017

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/7df89dba73fafcd/output.txt

Total script time: 2.53 mins

  • Unit Tests: Passed

@yurydelendik
Copy link
Contributor

yurydelendik commented Jan 9, 2017

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'),
Copy link
Contributor

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'),

@yurydelendik
Copy link
Contributor

/botio-linux unittest

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Linux)


Received

Command cmd_unittest from @yurydelendik received. Current queue size: 0

Live output at: http://107.21.233.14:8877/8287dfd24cb9418/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/8287dfd24cb9418/output.txt

Total script time: 2.00 mins

  • Unit Tests: Passed

@porlan1
Copy link
Contributor Author

porlan1 commented Jan 9, 2017

Hi Yury, thanks for the help. Should I squash those commits?

@yurydelendik
Copy link
Contributor

Should I squash those commits?

Yes, please

@yurydelendik
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Linux)


Received

Command cmd_test from @yurydelendik received. Current queue size: 0

Live output at: http://107.21.233.14:8877/281588546298918/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Windows)


Received

Command cmd_test from @yurydelendik received. Current queue size: 0

Live output at: http://107.22.172.223:8877/6960a0640e47609/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/6960a0640e47609/output.txt

Total script time: 25.52 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Jan 9, 2017

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/281588546298918/output.txt

Total script time: 26.11 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@yurydelendik
Copy link
Contributor

Thank you for the patch.

@yurydelendik yurydelendik merged commit 049d7fa into mozilla:master Jan 9, 2017
@timvandermeij
Copy link
Contributor

Nice contribution, thanks!

movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants