summaryrefslogtreecommitdiff
path: root/test/load.js
blob: 97bee6942fb926cc3141187413570ccf49918f08 (plain) (blame)
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
"use strict";
process.env.TZ = "UTC";

var smash = require("smash"),
    jsdom = require("jsdom");

module.exports = function() {
    var files = [].slice.call(arguments).map(function(d) { return "public/js/" + d; }),
        expression = "mp",
        sandbox = {},
        domString = "<html><head></head><body></body></html>";

    function topic() {
        smash.load(files, expression, sandbox, this.callback);
    }

    topic.expression = function(_) {
        expression = _;
        return topic;
    };

    topic.dom = function(_) {
        if (!arguments.length) return domString;
        domString = _;
        return topic;
    };

    topic.body = function(_) {
        topic.dom("<html><head></head><body>" + _ + "</body></html>");
        return topic;
    };

    topic.document = function(_) {
        var document = arguments.length ? _ : jsdom.jsdom(domString);

        document.createRange = function() {
            return {
                selectNode: function() {},
                createContextualFragment: jsdom.jsdom
            };
        };

        sandbox = {
            console: console,
            document: document,
            window: document.createWindow(),
        };

        return topic;
    };

    return topic;
};

process.on("uncaughtException", function(e) {
    console.trace(e.stack);
});