electron-lite (2019.1.8)

Code coverage report for node-electron-lite/example.js

Ignored Statements Branches Functions Lines
branches: 1
statements: 2
100%
(34 / 34)
100%
(8 / 8)
100%
(2 / 2)
100%
(34 / 34)
All files » node-electron-lite/ » example.js
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170                                                                                                                                                                                                     2   2 2 2 2 5 5     2 1     1 1   1   1     1               1 1   1   1     1 1   1     1       1     1 1       1 1   1   1 1   1 1     2 2    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/*
example.js
 
this electron script will screenshot the webpage https://electron.atom.io
 
instruction
    1. save this script as example.js
    2. run the shell command:
        $ npm install electron-lite && \
            printf '{"main":"example.js","name":"undefined","version":"0.0.1"}' > \
            package.json && \
            ./node_modules/.bin/electron . --disable-overlay-scrollbar --enable-logging
    3. view screenshot /tmp/screenshot.testExampleJs.browser..png
*/
 
 
 
/* istanbul instrument in package electron */
/* jslint utility2:true */
(function () {
    "use strict";
    var modeNext;
    var onNext;
    var options;
    onNext = function (data) {
        modeNext += 1;
        switch (modeNext) {
        case 1:
            /* istanbul ignore next */
            Iif (process.env.npm_config_mode_auto_restart) {
                return;
            }
            // wait for electron to init
            try {
                require("app").on("ready", onNext);
            } catch (ignore) {
                require("electron").app.once("ready", onNext);
            }
            break;
        case 2:
            // init options
            options = {
                frame: false,
                height: 768,
                width: 1024,
                x: 0,
                y: 0
            };
            // init browserWindow;
            try {
                options.BrowserWindow = require("browser-window");
            } catch (ignore) {
                options.BrowserWindow = require("electron").BrowserWindow;
            }
            options.browserWindow = new options.BrowserWindow(options);
            // goto next step when webpage is loaded
            /* istanbul ignore next */
            try {
                options.browserWindow.webContents.once("did-stop-loading", onNext);
            } catch (ignore) {
                setTimeout(onNext, 10000);
            }
            // open url
            (options.browserWindow.loadUrl || options.browserWindow.loadURL).call(
                options.browserWindow,
                "https://electron.atom.io"
            );
            break;
        case 3:
            // screenshot webpage
            options.browserWindow.capturePage(options, onNext);
            break;
        case 4:
            // screenshot
            /* istanbul ignore next */
            try {
                data = data.toPng();
            } catch (ignore) {
                data = data.toPNG();
            }
            require("fs").writeFileSync("/tmp/screenshot.testExampleJs.browser..png", data);
            console.log("created screenshot file /tmp/screenshot.testExampleJs.browser..png");
            // exit
            process.exit(0);
            break;
        }
    };
    modeNext = 0;
    onNext();
}());