File: test.js

package info (click to toggle)
node-browserify-lite 0.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 124 kB
  • ctags: 27
  • sloc: makefile: 14
file content (81 lines) | stat: -rw-r--r-- 2,024 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var assert = require('assert');
var browserifyLite = require('./');

var extractRequiresTests = [
  {
    name: "basic",
    source: "require('./code')",
    output: [
      "./code"
    ],
  },
  {
    name: "multiple",
    source:
"var EventEmitter = require('./event_emitter');\n" +
"var inherits = require('./inherits');\n" +
"var uuid = require('./uuid');\n" +
"var MusicLibraryIndex = require('music-library-index');\n" +
"var keese = require(\"keese\");\n" +
"var curlydiff = require('curlydiff');\n",
    output: [
      "./event_emitter",
      "./inherits",
      "./uuid",
      "music-library-index",
      "keese",
      "curlydiff",
    ],
  },
  {
    name: "trick",
    source: "require('./code');\nvar a = \"require('foo');\";\nrequire(\"../morecode\");",
    output: [
      "./code",
      "../morecode",
    ],
  },
  {
    name: "unescape",
    source: "require('./code');\nvar a = \"require(\\\"foo\\\");\";\nrequire(\"../morecode\");",
    output: [
      "./code",
      "../morecode",
    ],
  },
  {
    name: "spaces",
    source: "var foo = require ( 'derp ' ) ;\n",
    output: [
      "derp ",
    ],
  },
  {
    name: "ignore braces",
    source: "var foo = require('derp'); { require('dont-ignore-this'); } require('this-ok')\n",
    output: [
      "derp",
      "dont-ignore-this",
      "this-ok",
    ],
  },
  {
    name: "ignore comments",
    source: "/* var foo = require('derp');*/ { require('dont-ignore-this'); } require('this-ok') // require('also-ignore-this'); \n require('this-also-ok')",
    output: [
      "dont-ignore-this",
      "this-ok",
      "this-also-ok",
    ],
  }
];

process.stderr.write("extract requires tests:\n");
extractRequiresTests.forEach(function(extractRequiresTest) {
  process.stderr.write(extractRequiresTest.name + "...");
  browserifyLite.extractRequires(extractRequiresTest.source, function(err, requiresList) {
    if (err) throw err;
    assert.deepEqual(extractRequiresTest.output, requiresList);
    process.stderr.write("OK\n");
  });
});