Giter Site home page Giter Site logo

Comments (4)

caolan avatar caolan commented on May 27, 2024

Kind of surprised it works in windows at all ;)

For now you could use a custom reporter, just copy lib/reporters/default.js and specify your new file as the reporter once you have updated the success and error characters. You can specify a reporter by using the reporter option:

nodeunit --reporter path/to/reporter.js

If you can work out a way to change the output depending on the environment I'll happily accept a patch.

from nodeunit.

diversario avatar diversario commented on May 27, 2024

Why wouldn't it work in Windows?

I'm using PuTTY from Windows and SSH into Ubuntu 10.10 server where I run nodeunit. I experience the same issue, except I get "รข" in place of both error and success marks. I'm not quite sure how to fix that, even in custom reporter. Maybe you know?

from nodeunit.

Wizek avatar Wizek commented on May 27, 2024

I also had the same issue with the default Command Prompt (cmd.exe), I (and still am) using Nodeunit through my cygwin Node installation. It really bothered me as well, and I looked into the issue. Even if I change the font for cmd to something more UTF8 capable, like Consolas, I could only improve those signs from question marks to weird symbols. I found out that the cause of the problem was that cmd uses "codepage" (chcp) number 437.

Since then, I switched my Cygwin CMD console to Mintty, which handles UTF8 wonderfully, and well integrated to windows (even better than cmd...). Now I have other set of issues with it (vim works terribly, cannot use backspace inside, have to use gvim). But this is the best I could find so far.

Maybe you could go along the chcp line. Keep me posted if there is advancement! :)

from nodeunit.

jjoschyy avatar jjoschyy commented on May 27, 2024

Created a new reporter, almost like the default reporter, ready for windows.

  • Is using text instead of signs
  • Shows current test name before test starts.

Installation:

  1. copy the code below to lib/reporters/windows.js
  2. add 'windows': require('./windows') to lib/reporters/index.js
  3. use nodeunit with option: "--reporter windows"
/*!
 * Nodeunit
 * Copyright (c) 2010 Caolan McMahon
 * MIT Licensed
 */

/**
 * Module dependencies
 */

var nodeunit = require('../nodeunit'),
    utils = require('../utils'),
    sys = require('sys'),
    fs = require('fs'),
    track = require('../track'),
    path = require('path'),
    AssertionError = require('../assert').AssertionError;

/**
 * Reporter info string
 */

exports.info = "Default tests reporter";


/**
 * Run all tests within each module, reporting the results to the command-line.
 *
 * @param {Array} files
 * @api public
 */

exports.run = function (files, options) {

    if (!options) {
        // load default options
        var content = fs.readFileSync(
            __dirname + '/../../bin/nodeunit.json', 'utf8'
        );
        options = JSON.parse(content);
    }

    var error = function (str) {
        return options.error_prefix + str + options.error_suffix;
    };
    var ok    = function (str) {
        return options.ok_prefix + str + options.ok_suffix;
    };
    var bold  = function (str) {
        return options.bold_prefix + str + options.bold_suffix;
    };
    var assertion_message = function (str) {
        return options.assertion_prefix + str + options.assertion_suffix;
    };

    var start = new Date().getTime();
    var paths = files.map(function (p) {
        return path.join(process.cwd(), p);
    });
    var tracker = track.createTracker(function (tracker) {
        if (tracker.unfinished()) {
            console.log('');
            console.log(error(bold(
                'FAILURES: Undone tests (or their setups/teardowns): '
            )));
            var names = tracker.names();
            for (var i = 0; i < names.length; i += 1) {
                console.log('- ' + names[i]);
            }
            console.log('');
            console.log('To fix this, make sure all tests call test.done()');
            process.reallyExit(tracker.unfinished());
        }
    });

    nodeunit.runFiles(paths, {
        testspec: options.testspec,
        moduleStart: function (name) {
            console.log('\n   ' + bold(name));
        },
        testStart: function(name) {
            var line = ' @ ' + name.toString() + ' ';

            for (var i=name.toString().length; i<65;i++)
              line += '.';

            sys.print(line);
            tracker.put(name);
        },

        testDone: function (name, assertions) {
            tracker.remove(name);

             if (!assertions.failures()) {
               console.log(ok(' SUCCESS'));
            }
            else {
                console.log(error(' FAILED'));
                assertions.forEach(function (a) {
                    if (a.failed()) {
                        a = utils.betterErrors(a);

                        if (a.error instanceof AssertionError && a.message)
                            console.log(assertion_message('   -> Message:' + a.message))


                        console.log('\n' + a.error.stack + '\n');
                    }
                });

                console.log('')
            }
        },

        done: function (assertions, end) {
            var end = end || new Date().getTime();
            var duration = end - start;
            if (assertions.failures()) {
                console.log(
                    '\n\n' + bold(error('FAILURES: ')) + assertions.failures() +
                    '/' + assertions.length + ' assertions failed (' +
                    assertions.duration + 'ms)'
                );
            }
            else {
                console.log(
                   '\n\n' + bold(ok('OK: ')) + assertions.length +
                   ' assertions (' + assertions.duration + 'ms)'
                );
            }
        }
    });
};

from nodeunit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.