Change from pnpm to npm, add ./link.sh shortcut for npm style package linking
[html-minifier.git] / test.js
1 /* eslint-env phantomjs, qunit */
2 'use strict';
3
4 function load(path) {
5   var obj = require(path);
6   for (var key in obj) {
7     global[key] = obj[key];
8   }
9   return obj;
10 }
11
12 var alert = console.log;
13 var QUnit = load('qunit');
14
15 function hook() {
16   var failures = [];
17   QUnit.log(function(details) {
18     if (!details.result) {
19       failures.push(details);
20     }
21   });
22   QUnit.done(function(details) {
23     details.failures = failures;
24     alert(JSON.stringify(details));
25   });
26   QUnit.start();
27 }
28
29 if (typeof phantom === 'undefined') {
30   load('./src/htmlminifier');
31   require(process.argv[2]);
32   hook();
33 }
34 else {
35   var system = require('system');
36   setTimeout(function() {
37     system.stderr.write('timed out');
38     phantom.exit(1);
39   }, 15000);
40   var page = require('webpage').create();
41   page.onAlert = function(details) {
42     console.log(details);
43     phantom.exit();
44   };
45   page.open(system.args[1], function(status) {
46     if (status !== 'success') {
47       phantom.exit(1);
48     }
49     page.evaluate(hook);
50   });
51 }