diff --git a/packages/js-analyze-tests/.gitignore b/packages/js-analyze-tests/.gitignore new file mode 100644 index 0000000000..677a6fc263 --- /dev/null +++ b/packages/js-analyze-tests/.gitignore @@ -0,0 +1 @@ +.build* diff --git a/packages/js-analyze/js_analyze_tests.js b/packages/js-analyze-tests/js_analyze_tests.js similarity index 100% rename from packages/js-analyze/js_analyze_tests.js rename to packages/js-analyze-tests/js_analyze_tests.js diff --git a/packages/js-analyze-tests/package.js b/packages/js-analyze-tests/package.js new file mode 100644 index 0000000000..a56fdb21d6 --- /dev/null +++ b/packages/js-analyze-tests/package.js @@ -0,0 +1,12 @@ +Package.describe({ + summary: "Tests for JavaScript code analysis for Meteor" +}); + +// The tests are in a separate package so that it is possible to compile +// 'js-analyze' as a unipackage and then load it via `unipackage.load` without +// any dependencies. +Package.on_test(function (api) { + api.use('tinytest'); + api.use('js-analyze'); + api.add_files('js_analyze_tests.js', 'server'); +}); diff --git a/packages/js-analyze/esprima_tests.js b/packages/js-analyze/esprima_tests.js deleted file mode 100644 index a640a6af11..0000000000 --- a/packages/js-analyze/esprima_tests.js +++ /dev/null @@ -1,40 +0,0 @@ -var esprima = Npm.require('esprima'); -var escope = Npm.require('escope'); -var estraverse = Npm.require('estraverse'); - -Tinytest.add("estools - parser", function (test) { - var tree = esprima.parse('1+1'); - test.equal(tree, { - "type": "Program", - "body": [{ - "type": "ExpressionStatement", - "expression": { - "type": "BinaryExpression", - "operator": "+", - "left": { - "type": "Literal", - "value": 1, - "raw": "1" - }, - "right": { - "type": "Literal", - "value": 1, - "raw": "1"}}}] - }); -}); - -Tinytest.add("estools - scoper", function (test) { - var tree = esprima.parse('var x = 1'); - var scoper = escope.analyze(tree); - scoper.attach(); - - var getScope = function (node) { - return node[escope.Scope.mangledName]; - }; - var Syntax = estraverse.Syntax; - - var refs = getScope(tree).references; - test.equal(refs.length, 1); - test.equal(refs[0].flag, escope.Reference.WRITE); - test.equal(refs[0].identifier, { type: Syntax.Identifier, name: "x" }); -}); diff --git a/packages/js-analyze/package.js b/packages/js-analyze/package.js index 859439b115..175e910251 100644 --- a/packages/js-analyze/package.js +++ b/packages/js-analyze/package.js @@ -13,20 +13,13 @@ Npm.depends({ escope: "0.0.14" }); -// This package may not depend on ANY other Meteor packages. This is because it -// is used by the linker; the linker is smart enough not to try to apply it to -// itself, but it cannot depend on any other packages or else it would be -// impossible to load at link time (or all transitive dependencies packages -// would need to function without the analysis provided by this package). +// This package may not depend on ANY other Meteor packages, even in the test +// slice. (Tests for this package are in the js-analyze-tests package.) This is +// because it is used by the linker; the linker is smart enough not to try to +// apply it to itself, but it cannot depend on any other packages or else it +// would be impossible to load at link time (or all transitive dependencies +// packages would need to function without the analysis provided by this +// package). Package.on_use(function (api, where) { api.add_files('js_analyze.js', 'server'); }); - -// It's OK to have dependencies here, though, because unipackage.load doesn't -// need to load dependencies of test slices. -Package.on_test(function (api) { - api.use('tinytest'); - api.use('js-analyze'); - api.add_files('esprima_tests.js', 'server'); - api.add_files('js_analyze_tests.js', 'server'); -});