l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

readAllImports-test.js (5144B)


      1 var vows = require("vows"),
      2     assert = require("assert"),
      3     smash = require("../");
      4 
      5 var suite = vows.describe("smash.readAllImports");
      6 
      7 suite.addBatch({
      8   "readAllImports": {
      9     "on a file with no imports": {
     10       topic: function() {
     11         smash.readAllImports(["test/data/foo.js"], this.callback);
     12       },
     13       "returns only the input file": function(imports) {
     14         assert.deepEqual(imports, ["test/data/foo.js"]);
     15       }
     16     },
     17     "on a file with imports with trailing comments": {
     18       topic: function() {
     19         smash.readAllImports(["test/data/trailing-comment-import.js"], this.callback);
     20       },
     21       "returns the empty array": function(imports) {
     22         assert.deepEqual(imports, ["test/data/foo.js", "test/data/bar.js", "test/data/trailing-comment-import.js"]);
     23       }
     24     },
     25     "on a file with invalid import syntax": {
     26       topic: function() {
     27         var callback = this.callback;
     28         smash.readAllImports(["test/data/invalid-import-syntax.js"], function(error) {
     29           callback(null, error);
     30         });
     31       },
     32       "throws an error with the expected message": function(error) {
     33         assert.deepEqual(error.message, "invalid import: test/data/invalid-import-syntax.js:0: import foo;");
     34       }
     35     },
     36     "on a file with that imports a file that does not exist": {
     37       topic: function() {
     38         var callback = this.callback;
     39         smash.readAllImports(["test/data/imports-not-found.js"], function(error) {
     40           callback(null, error);
     41         });
     42       },
     43       "throws an error with the expected message": function(error) {
     44         assert.deepEqual(error.message, "ENOENT, open 'test/data/not-found.js'");
     45       }
     46     },
     47     "on a file with that imports a file that does not exist with --ignore-missing": {
     48       topic: function() {
     49         smash.readAllImports(["test/data/imports-not-found.js"], {"ignore-missing": true}, this.callback);
     50       },
     51       "returns the expected imports": function(imports) {
     52         assert.deepEqual(imports, ["test/data/not-found.js", "test/data/imports-not-found.js"]);
     53       }
     54     },
     55     "on a file with a commented-out import": {
     56       topic: function() {
     57         smash.readAllImports(["test/data/commented-import.js"], this.callback);
     58       },
     59       "ignores the commented-out input": function(imports) {
     60         assert.deepEqual(imports, ["test/data/commented-import.js"]);
     61       }
     62     },
     63     "on a file with a not-commented-out import": {
     64       topic: function() {
     65         smash.readAllImports(["test/data/not-commented-import.js"], this.callback);
     66       },
     67       "does not ignore the not-commented-out import": function(imports) {
     68         assert.deepEqual(imports, ["test/data/foo.js", "test/data/not-commented-import.js"]);
     69       }
     70     },
     71     "on a file with one import": {
     72       topic: function() {
     73         smash.readAllImports(["test/data/imports-foo.js"], this.callback);
     74       },
     75       "returns the expected import followed by the input file": function(imports) {
     76         assert.deepEqual(imports, ["test/data/foo.js", "test/data/imports-foo.js"]);
     77       }
     78     },
     79     "on a file with multiple imports": {
     80       topic: function() {
     81         smash.readAllImports(["test/data/imports-foo-bar-baz.js"], this.callback);
     82       },
     83       "returns the imports in order of declaration": function(imports) {
     84         assert.deepEqual(imports, ["test/data/foo.js", "test/data/bar.js", "test/data/baz.js", "test/data/imports-foo-bar-baz.js"]);
     85       }
     86     },
     87     "on a file with nested imports": {
     88       topic: function() {
     89         smash.readAllImports(["test/data/imports-imports-foo.js"], this.callback);
     90       },
     91       "returns the imports in order of dependency": function(imports) {
     92         assert.deepEqual(imports, ["test/data/foo.js", "test/data/imports-foo.js", "test/data/imports-imports-foo.js"]);
     93       }
     94     },
     95     "on multiple input files": {
     96       topic: function() {
     97         smash.readAllImports(["test/data/foo.js", "test/data/bar.js", "test/data/baz.js"], this.callback);
     98       },
     99       "returns the expected imports, in order": function(imports) {
    100         assert.deepEqual(imports, ["test/data/foo.js", "test/data/bar.js", "test/data/baz.js"]);
    101       }
    102     },
    103     "with redundant input files": {
    104       topic: function() {
    105         smash.readAllImports(["test/data/foo.js", "test/data/foo.js"], this.callback);
    106       },
    107       "ignores the redundant imports": function(imports) {
    108         assert.deepEqual(imports, ["test/data/foo.js"]);
    109       }
    110     },
    111     "when a file that imports itself": {
    112       topic: function() {
    113         smash.readAllImports(["test/data/imports-self.js"], this.callback);
    114       },
    115       "the self-import has no effect": function(imports) {
    116         assert.deepEqual(imports, ["test/data/imports-self.js"]);
    117       }
    118     },
    119     "when circular imports are encountered": {
    120       topic: function() {
    121         smash.readAllImports(["test/data/imports-circular-foo.js"], this.callback);
    122       },
    123       "imports are returned in arbtirary order": function(imports) {
    124         assert.deepEqual(imports, ["test/data/imports-circular-bar.js", "test/data/imports-circular-foo.js"]);
    125       }
    126     }
    127   }
    128 });
    129 
    130 suite.export(module);