Giter Site home page Giter Site logo

karma-dart's Introduction

karma-dart

js-standard-style npm version npm downloads

Build Status Dependency Status devDependency Status

Adapter for the Dart unittest testing framework.

For more information on Karma-runner see the homepage.

Getting Started

You'll need node.js: http://nodejs.org/download/

Install karma and karma-dart adapter npms:

$ npm install karma-dart

Refer to npm install documentation for more details and install options.

and you'll need the following dependencies in your pubspec.yaml

unittest: any
browser: any

The following is an example of karma config.

module.exports = function(config) {
  config.set({
    basePath: '.',
    frameworks: ['dart-unittest'],

    // list of files / patterns to load in the browser
    // all tests must be 'included', but all other libraries must be 'served' and
    // optionally 'watched' only.
    files: [
      'test/*.dart',
      {pattern: '**/*.dart', watched: true, included: false, served: true},
      'packages/browser/dart.js',
      'packages/browser/interop.js'
    ],

    autoWatch: true,

    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 5000,

    plugins: [
      'karma-dart'
    ]
  });
};

You can run karma from the local folder:

$ node node_modules/karma/bin/karma start karma-dart.conf

or if you installed it with -g flag just

$ karma start karma-dart.conf

Then just open http://localhost:9876/ in Dartium.

Known Limitations/Issues

  • Missing Dartium launcher.
  • Each test file must be a library -- due to the nature of the test runner, this is required.

karma-dart's People

Contributors

cbracken avatar chirayuk avatar dignifiedquire avatar jbdeboer avatar pavelgj avatar vojtajina avatar zzo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

karma-dart's Issues

Internal error

I try to run karma-runner with a new Dart console application project with a simple unit test, but I don't anything else than below messages.
Any idea what I'm doing wrong?

Dartium shows:

Karma v0.10.9 - connected
Chrome 33.0.1750 (Linux) is idle

the console output

INFO [Chrome 33.0.1750 (Linux)]: Connected on socket 6SSlvirID46FLneErNyP
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/configuration.dart': error: line 5 pos 6: url expected
        part of unittest;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/core_matchers.dart': error: line 5 pos 6: url expected
        part of unittest.matcher;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/description.dart': error: line 5 pos 6: url expected
        part of unittest.matcher;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/expect.dart': error: line 5 pos 6: url expected
        part of unittest.matcher;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/future_matchers.dart': error: line 5 pos 6: url expected
        part of unittest.matcher;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/group_context.dart': error: line 1 pos 6: url expected
        part of unittest;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/interfaces.dart': error: line 5 pos 6: url expected
        part of unittest.matcher;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/iterable_matchers.dart': error: line 5 pos 6: url expected
        part of unittest.matcher;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/map_matchers.dart': error: line 5 pos 6: url expected
        part of unittest.matcher;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/numeric_matchers.dart': error: line 5 pos 6: url expected
        part of unittest.matcher;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/operator_matchers.dart': error: line 5 pos 6: url expected
        part of unittest.matcher;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/simple_configuration.dart': error: line 5 pos 6: url expected
        part of unittest;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/spread_args_helper.dart': error: line 1 pos 6: url expected
        part of unittest;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/string_matchers.dart': error: line 5 pos 6: url expected
        part of unittest.matcher;
             ^
Chrome 33.0.1750 (Linux) ERROR
        Internal error: '/home/zoechi/source/my/dart/karma_test/test/packages/unittest/src/test_case.dart': error: line 5 pos 6: url expected
        part of unittest;
             ^
Chrome 33.0.1750 (Linux): Executed 0 of 0 ERROR (0.827 secs / 0 secs)

More reporting

I ran the compiled Dart unit tests through vanilla jasmine, and it seemed to report each test out. Although it didn't really work, I could at least see logs of my unit tests executing. Using karma-dart, all I see is "DUMP: unittest-suite-wait-for-done" after the suite is complete. Is there anything I can do to help to make these logs come out like they do in JavaScript?

Feature request: dart2js mode

I would like a switch that allows me to easily run my tests in dart2js mode. Instead of running the Dart script directly, it compiles the Dart to JS and then runs the resulting JS.

Support for the test package

I tried to used karma-dart but the old unittest package is now deprecated and renamed to test and it seems that karma-dart does not support yet this new package. What are the plan to switch to the test package?

Throwing error in group gets ignored

main() {
  group('x', () {
    //TODO(karma): throwing error here gets ignored
    throw new Error();

    setup(() {
      //TODO(karma): throwing error here gets ignored
      throw new Error();
    }); 

    teardown(() {
      //TODO(karma): throwing error here gets ignored
      throw new Error();
    }); 

    test('x', () {
      // This test does not run, but no error is reported.
    }):
  });
}

Missing stacktraces when excpectations are run by a Future

Hi

I have been trying to test a service in our Angular.dart project and this service starts by initializing asynchronous data.

When I write my expectations in a anonymous callback in a then() function, I don't get any stacktrace when the expectation fails.

Here is our test :
https://github.com/WebPuzzle/webpuzzle/blob/e6f7a5fe47f747d21c4dccad4517c0671c08a84c/test/services/webcomponent_service_spec.dart

As you can see I am doing

webComponentService.dataInitialized().then((d){
        expect(webComponentService.webcomponents.first["name"], equals("a wc name"));
      });

I don't know if I should code another way, if it is a dart issue or a karma issue, but do you have any clue how to test asynchronously and still get the stacktraces ?

When karma.conf.js is missing the main test file, then karma fails

module.exports = function(config) {
  config.set({
    basePath: '.',
    frameworks: ['dart-unittest'],

    // list of files / patterns to load in the browser
    files: [
      'main_test.dart',  // <<<<<<<<< REMOVING THIS LINE CAUSES ERROR
      {pattern: '**/*.dart', watched: false, included: false, served: true},
      {pattern: 'packages/browser/dart.js', watched: false, included: true, served: true},
      {pattern: 'packages/browser/interop.js', watched: false, included: true, served: true},
    ],

    autoWatch: true,

    plugins: [
      'karma-dart',
      'karma-chrome-launcher'
    ]
  });
};

karma-dart 0.1.3 crashes with checked mode

/usr/local/google/gits/nvm/v0.8.11/bin/node node_modules/karma/bin/karma run --runner-port=8766
Chrome 28.0 (Linux) ERROR
Internal error: Dart_FunctionParameterType: malformed type encountered: '/home/deboer/gits/angular-dart/__adapter_dart_unittest.dart': Error: line 50 pos 21: cannot resolve class name 'TestCase' from 'AdapterConfigutation'
void onLogMessage(TestCase testCase, String message) {
^
.
at undefined:undefined
Chrome 28.0 (Linux): Executed 0 of 21 ERROR (1.201 secs / 0 secs)

Chromium 28.0.1478.0 (Developer Build 194114)
OS Linux
Blink 537.36 (Source/WebCore/Configurations@1197)
JavaScript V8 3.17.16.2
DartVM 0.5.0.1_r21823
Flash 11.2 r202
User Agent Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1478.0 (Dart) Safari/537.36
Command Line ./chrome --flag-switches-begin --flag-switches-end
Executable Path /usr/local/google/dart_versions/apr27/chromium/chrome
Profile Path /home/deboer/.config/chromium/Default
Variations b03ddc1f-2d9ef0cc
f9b252d0-fd526c81
ca6785ad-766fa2d
ff3fc1a6-766fa2d
75f7fb7e-611a9f49
262f996f-eeefeb17
24dca50e-7ffa59d
ca65a9fe-91ac3782
3028188e-d60b5a5f
5e29d81-f23d1dea
246fb659-7158671e
f296190c-71ff9dce
4442aae2-6e597ede
75f0f0a0-a5822863
e2b18481-5c63917a
e7e71889-e1cc0f14

Including a utility file in test folder thrown error

Create a utility file in test like so:

import 'package:unittest/unittest.dart';

it(name, fn) => test(name, fn);
iit(name, fn) => solo_test(name, fn);
xit(name, fn) {}

describe(name, fn) => group(name, fn);

beforeEach(fn) => setUp(fn);
afterEach(fn) => tearDown(fn);

// TODO: uncommenting this makes it work. But main() should be optional.
//main(){}
Internal error: '/Users/misko/work/angular.dart/__adapter_dart_unittest.dart': Error: line 54 pos 10: identifier 'test_3.main' cannot be resolved
  test_3.main();
             ^
at undefined:undefined

TypeError: promise.then is not a function

I'm trying to upgrade angular/angular to [email protected] and I'm getting:

 TypeError: promise.then is not a function
<     at [object Object].PromiseContainer.then (/Users/iminar/Dev/angular/node_modules/karma/lib/middleware/common.js:14:29)
<     at Object.handler (/Users/iminar/Dev/angular/karma-dart-evalcache.js:35:27)
<     at createCustomHandler (/Users/iminar/Dev/angular/node_modules/karma/lib/web-server.js:21:38)
<     at call (/Users/iminar/Dev/angular/node_modules/karma/node_modules/connect/index.js:239:7)
<     at next (/Users/iminar/Dev/angular/node_modules/karma/node_modules/connect/index.js:183:5)
<     at createProxy (/Users/iminar/Dev/angular/node_modules/karma/lib/middleware/proxy.js:94:14)
<     at call (/Users/iminar/Dev/angular/node_modules/karma/node_modules/connect/index.js:239:7)
<     at next (/Users/iminar/Dev/angular/node_modules/karma/node_modules/connect/index.js:183:5)
<     at /Users/iminar/Dev/angular/node_modules/karma/lib/middleware/source_files.js:44:9
<     at tryCatcher (/Users/iminar/Dev/angular/node_modules/karma/node_modules/bluebird/js/main/util.js:26:23)
<     at Promise.module.exports.Promise._settlePromiseFromHandler (/Users/iminar/Dev/angular/node_modules/karma/node_modules/bluebird/js/main/promise.js:507:31)
<     at Promise.module.exports.Promise._settlePromiseAt (/Users/iminar/Dev/angular/node_modules/karma/node_modules/bluebird/js/main/promise.js:581:18)
<     at Promise.module.exports.Promise._settlePromiseAtPostResolution (/Users/iminar/Dev/angular/node_modules/karma/node_modules/bluebird/js/main/promise.js:245:10)
<     at Async._drainQueue (/Users/iminar/Dev/angular/node_modules/karma/node_modules/bluebird/js/main/async.js:128:12)
<     at Async._drainQueues (/Users/iminar/Dev/angular/node_modules/karma/node_modules/bluebird/js/main/async.js:133:10)
<     at Immediate.__dirname.drainQueues [as _onImmediate] (/Users/iminar/Dev/angular/node_modules/karma/node_modules/bluebird/js/main/async.js:15:14)

when I debugged the code, I noticed that the promise reference points to an object with two properties:

> Object.keys(promise)
[ 'served', 'included' ]

Both of these properties point to arrays.

I don't know karma-dart code well, but it looks like something passes a non-promise object into PromiseContainer#set, which then causes this error.

Better error message for missing main()

If I forget a main(), I get the error:
It should tell me what file this is in.

Or better yet, don't try to execute main() on files that don't have a main().

Chrome 29.0 (Linux) ERROR
Internal error: '/home/deboer/github/angular-dart/__adapter_dart_unittest.dart': Error: line 87 pos 10: identifier 'test_0.main' cannot be resolved
test_0.main();
^

Use config.port

When given port is already being used, Karma tries another one and mutates config.port.

Karma dart needs to use config.port instead of just port, because it can't see this change.
This is pretty terrible design in Karma, I know;-)

High CPU load when running

When I run karma test runner it executes my tests correctly and responds to file changes, however I have to terminate the batch job after I run the tests because the node.js process keeps using full cpu load. This beats the purpose of having automated tests run because it slows down the rest of my pc significantly.

Is this a known problem? Any suggestions on how to debug would be welcome.

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.