"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/test.js" (7 Feb 2017, 3263 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var Command, Test, fs, path, temp, yargs,
    3     extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    4     hasProp = {}.hasOwnProperty;
    5 
    6   path = require('path');
    7 
    8   yargs = require('yargs');
    9 
   10   temp = require('temp');
   11 
   12   Command = require('./command');
   13 
   14   fs = require('./fs');
   15 
   16   module.exports = Test = (function(superClass) {
   17     extend(Test, superClass);
   18 
   19     function Test() {
   20       return Test.__super__.constructor.apply(this, arguments);
   21     }
   22 
   23     Test.commandNames = ['test'];
   24 
   25     Test.prototype.parseOptions = function(argv) {
   26       var options;
   27       options = yargs(argv).wrap(100);
   28       options.usage("Usage:\n  apm test\n\nRuns the package's tests contained within the spec directory (relative\nto the current working directory).");
   29       options.alias('h', 'help').describe('help', 'Print this usage message');
   30       return options.alias('p', 'path').string('path').describe('path', 'Path to atom command');
   31     };
   32 
   33     Test.prototype.run = function(options) {
   34       var atomCommand, callback, env, logFile, logFilePath, packagePath, testArgs;
   35       callback = options.callback;
   36       options = this.parseOptions(options.commandArgs);
   37       env = process.env;
   38       if (options.argv.path) {
   39         atomCommand = options.argv.path;
   40       }
   41       if (!fs.existsSync(atomCommand)) {
   42         atomCommand = 'atom';
   43         if (process.platform === 'win32') {
   44           atomCommand += '.cmd';
   45         }
   46       }
   47       packagePath = process.cwd();
   48       testArgs = ['--dev', '--test', path.join(packagePath, 'spec')];
   49       if (process.platform === 'win32') {
   50         logFile = temp.openSync({
   51           suffix: '.log',
   52           prefix: (path.basename(packagePath)) + "-"
   53         });
   54         fs.closeSync(logFile.fd);
   55         logFilePath = logFile.path;
   56         testArgs.push("--log-file=" + logFilePath);
   57         return this.spawn(atomCommand, testArgs, function(code) {
   58           var loggedOutput;
   59           try {
   60             loggedOutput = fs.readFileSync(logFilePath, 'utf8');
   61             if (loggedOutput) {
   62               process.stdout.write(loggedOutput + "\n");
   63             }
   64           } catch (undefined) {}
   65           if (code === 0) {
   66             process.stdout.write('Tests passed\n'.green);
   67             return callback();
   68           } else if (code != null ? code.message : void 0) {
   69             return callback("Error spawning Atom: " + code.message);
   70           } else {
   71             return callback('Tests failed');
   72           }
   73         });
   74       } else {
   75         return this.spawn(atomCommand, testArgs, {
   76           env: env,
   77           streaming: true
   78         }, function(code) {
   79           if (code === 0) {
   80             process.stdout.write('Tests passed\n'.green);
   81             return callback();
   82           } else if (code != null ? code.message : void 0) {
   83             return callback("Error spawning " + atomCommand + ": " + code.message);
   84           } else {
   85             return callback('Tests failed');
   86           }
   87         });
   88       }
   89     };
   90 
   91     return Test;
   92 
   93   })(Command);
   94 
   95 }).call(this);