summaryrefslogtreecommitdiffstats
path: root/spec/amd.html
blob: 1149dc7061e8334fc53bcc2fcd62987196646887 (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!doctype html>
<html>
  <head>
    <title>Mocha</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="/node_modules/mocha/mocha.css" />
    <style>
      .headless .suite > h1,
      .headless .test.pass {
        display: none;
      }
    </style>

    <script>
      // Show only errors in "headless", non-interactive mode.
      if (/headless=true/.test(location.href)) {
        document.documentElement.className = 'headless';
      }
    </script>
    <script src="/node_modules/mocha/mocha.js"></script>
    <script>
      mocha.setup('bdd');
    </script>

    <script src="/spec/env/json2.js"></script>
    <script src="/spec/env/require.js"></script>

    <script src="/spec/env/common.js"></script>
    <script>
      var requireFailure;

      requirejs.config({
        paths: {
          handlebars: '/dist/handlebars.amd',
          tests: '/tmp/tests'
        }
      });
      requirejs.onError = function (err) {
        requireFailure = err;
      };

      var CompilerContext = {
        compile: function(template, options) {
          var templateSpec = handlebarsEnv.precompile(template, options);
          return handlebarsEnv.template(safeEval(templateSpec));
        },
        compileWithPartial: function(template, options) {
          return handlebarsEnv.compile(template, options);
        }
      };

      function safeEval(templateSpec) {
        try {
          var ret;
          eval('ret = ' + templateSpec);
          return ret;
        } catch (err) {
          console.error(templateSpec);
          throw err;
        }
      }
    </script>
    <script>
      onload = function(){

        require(['handlebars'], function(Handlebars) {
          window.Handlebars = Handlebars['default'];

          require(['tests'], function(Handlebars) {
            mocha.globals(['mochaResults'])
            // The test harness leaks under FF. We should have decent global leak coverage from other tests
            if (!navigator.userAgent.match(/Firefox\/([\d.]+)/)) {
              mocha.checkLeaks();
            }
            var runner = mocha.run();

            //Reporting for saucelabs
            var failedTests = [];
            runner.on('end', function(){
              window.mochaResults = runner.stats;
              window.mochaResults.reports = failedTests;
            });

            runner.on('fail', logFailure);

            // Inject any require initilizer failures into the first test so they are properly
            // reported.
            if (requireFailure) {
              runner.on('hook end', function(hook){
                if (requireFailure) {
                  runner.uncaught(requireFailure);
                  requireFailure = undefined;
                }
              });
            }

            function logFailure(test, err){
              function flattenTitles(test){
                var titles = [];
                while (test.parent.title){
                  titles.push(test.parent.title);
                  test = test.parent;
                }
                return titles.reverse();
              }

              failedTests.push({
                name: test.title,
                result: false,
                message: err.message,
                stack: err.stack,
                titles: flattenTitles(test)
              });
            }
          });
        });
      };
    </script>
  </head>
  <body>
    <div id="mocha"></div>
  </body>
</html>