Move js-analyze tests to a separate package to simplify loading

This commit is contained in:
David Glasser
2013-07-01 19:00:15 -07:00
parent 0652b2180e
commit 717372168f
5 changed files with 20 additions and 54 deletions

1
packages/js-analyze-tests/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.build*

View File

@@ -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');
});

View File

@@ -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" });
});

View File

@@ -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');
});