Giter Site home page Giter Site logo

co-mocha's Introduction

Co Mocha

NPM version NPM downloads Build status Test coverage Greenkeeper badge

Enable support for generators in Mocha tests using co.

Use the --harmony-generators flag when running node 0.11.x to access generator functions, or transpile your tests using traceur or regenerator.

Installation

npm install co-mocha --save-dev

Usage

Just require the module in your tests and start writing generators in your tests.

it('should do something', function * () {
  yield users.load(123)
})

Node

Install the module using npm install co-mocha --save-dev. Now just require the module to automatically monkey patch any available mocha instances. With mocha, you have multiple ways of requiring the module - add --require co-mocha to your mocha.opts or add require('co-mocha') inside your main test file.

If you need to monkey patch a different mocha instance you can use the library directly:

var mocha = require('mocha')
var coMocha = require('co-mocha')

coMocha(mocha)

<script> Tag

<script src="co-mocha.js"></script>

Including the browserified script will automatically patch window.Mocha. Just make sure you include it after mocha.js. If that is not possible the library exposes window.coMocha, which can be used (window.coMocha(window.Mocha)).

AMD

Same details as the script, but using AMD requires instead.

How It Works

The module monkey patches the Runnable.prototype.run method of mocha to enable generators. In contrast to other npm packages, co-mocha extends mocha at runtime - allowing you to use any compatible mocha version.

License

MIT

co-mocha's People

Contributors

blakeembrey avatar greenkeeper[bot] avatar hiddentao avatar magicdawn avatar markherhold avatar peterkc avatar popomore avatar wagyu298 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

co-mocha's Issues

A failing test in a co context is not propagated to mocha

I've made an example repository here to demonstrate the issue: https://github.com/TMiguelT/co-mocha-test

To run it, use:

git clone https://github.com/TMiguelT/co-mocha-test\
&& cd co-mocha-test\
&& npm install\
&& npm test

The code in question is this:

require('co-mocha');
require('assert');

describe("describe", () => {
  it("it", function *(done){
      assert(1 + 1 == 2);
      done();
  });
});

Basically, this causes a timeout error because done() is never called because the assert() fails. However ideally co-mocha would catch this error and pass it back to mocha to indicate a failed test.

co-mocha doesn't work with npminstall

npminstall is an insanely fast npm module installer: https://github.com/cnpm/npminstall

However, npminstall uses an alternative module management mechanism that co-mocha fails to understand.

A typical mocha path from require.cache looks like: /Users/adam/Projects/some-project/node_modules/mocha/index.js

While an npminstalled mocha path from require.cache looks like: /Users/adam/Projects/some-project/node_modules/.2.2.5@mocha/index.js

This prevents co-mocha from finding the cached mocha module object.

generators always passing

Hi,

I can't seem to make a generator based test fail. Even changing your supplied tests to add up to a different value than expected always seems to pass. I've tried this from node 0.11.8 to 0.11.12.

EG
it('should work with generators', function* () {
assert.equal(1 + 5, 3);
yield wait(100);
});
or
it('should work with generators', function* () {
assert.equal(yield(1 + 5), 3);
});

I followed this approach with the same results
https://labnotes.org/yield-to-the-test-using-mocha-with-es6-generators/

Do you have any idea on what I'm doing wrong here.?

This is my mocha.opts
--reporter spec
--require co-mocha

command line

mocha --harmony

Thanks

An in-range update of mocha is breaking the build 🚨

Version 3.4.2 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.4.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details
  • βœ… coverage/coveralls First build on greenkeeper/mocha-3.4.2 at 94.643% Details

Release Notes fake-success

3.4.2 / 2017-05-24

πŸ› Fixes

πŸ”© Other

Commits

The new version differs by 7 commits.

  • a15b20a :ship: Release v3.4.2
  • fc802a9 :memo: Add Changelog for v3.4.2
  • 10ff0ec Eagerly set process.exitCode (#2820)
  • fc35691 Merge pull request #2818 from makepanic/issue/2802
  • 3e7152f Remove call to deprecated os.tmpDir (#2802)
  • e249434 Merge pull request #2807 from mochajs/npm-script-lint
  • 17a1770 Move linting into an npm script. Relates to #2805

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of mocha is breaking the build 🚨

Version 4.1.0 of mocha was just published.

Branch Build failing 🚨
Dependency mocha
Current Version 4.0.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

mocha is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
  • βœ… coverage/coveralls First build on greenkeeper/mocha-4.1.0 at 94.643% Details

Release Notes v4.1.0

4.1.0 / 2017-12-28

This is mainly a "housekeeping" release.

Welcome @Bamieh and @xxczaki to the team!

πŸ›: Fixes

  • #2661: progress reporter now accepts reporter options (@canoztokmak)
  • #3142: xit in bdd interface now properly returns its Test object (@Bamieh)
  • #3075: Diffs now computed eagerly to avoid misinformation when reported (@abrady0)
  • #2745: --help will now help you even if you have a mocha.opts (@Zarel)

πŸŽ‰ Enhancements

  • #2514: The --no-diff flag will completely disable diff output (@CapacitorSet)
  • #3058: All "setters" in Mocha's API are now also "getters" if called without arguments (@makepanic)

πŸ“– Documentation

πŸ”© Other

Commits

The new version differs by 409 commits.

  • 6b9ddc6 Release v4.1.0
  • 3c4b116 update CHANGELOG for v4.1.0
  • 5be22b2 options.reporterOptions are used for progress reporter
  • ea96b18 add .fossaignore [ci skip]
  • adc67fd Revert "[ImgBot] optimizes images (#3175)"
  • ae3712c [ImgBot] optimizes images (#3175)
  • 33db6b1 Use x64 node on appveyor
  • 4a6e095 Run appveyor tests on x64 platform. Might enable sharp installation
  • 3abed9b Lint netlify-headers script
  • 119543e Add preconnect for doubleclick domain that google analytics results in contacting
  • bd5109e Remove crossorigin='anonymous' from preconnect hints. Only needed for fonts, xhr and es module loads
  • 123ee4f Handle the case where all avatars are already loaded at the time when the script exexecutes
  • 64deadc Specific value for inlining htmlimages to guarantee logo is inlined
  • 8f1ded4 https urls where possible
  • d5a5125 Be explicit about styling of screenshot images

There are 250 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of mocha is breaking the build 🚨

Version 3.4.0 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.3.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details,- βœ… coverage/coveralls First build on greenkeeper/mocha-3.4.0 at 94.737% Details

Release Notes v3.4.0

Mocha is now moving to a quicker release schedule: when non-breaking changes are merged, a release should happen that week.

This week's highlights:

  • allowUncaught added to commandline as --allow-uncaught (and bugfixed)
  • warning-related Node flags

πŸŽ‰ Enhancements

πŸ› Fixes

πŸ”© Other

Commits

The new version differs by 9 commits0.

  • 7554b31 Add Changelog for v3.4.0
  • 9f7f7ed Add --trace-warnings flag
  • 92561c8 Add --no-warnings flag
  • ceee976 lint test/integration/fixtures/simple-reporter.js
  • dcfc094 Revert "use semistandard directly"
  • 93392dd no special case for macOS running Karma locally
  • 4d1d91d --allow-uncaught cli option
  • fb1e083 fix allowUncaught in browser
  • 4ed3fc5 Add license report and scan status

false

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Simple test fails with 'TypeError: You may only yield a function...'

I'm hitting a problem in my tests and I can get the same thing with the simplest of tests. Using the file simple.js containing:

it('should do something', function* () {
  yield;
});

When I run:

node node_modules/mocha/bin/mocha --require co-mocha simple.js

I get

  1)  should do something:
     TypeError: You may only yield a function, promise, generator, array, or object, but the following object was passed: "undefined"
      at next (/Users/p14n/dev/tools/moch/node_modules/co-mocha/node_modules/co/index.js:100:25)

co-mocha 1.1.0
mocha 2.0.1
node 1.6.4

I can't see why that wouldn't work?

Cheers

The co mocha is a bit incompiatble with browser.

    Initialization
        should initialize the main object β€£

        "use strict";
                let contestData = {
                    question1: 'How Are you?',
                    answer1: 'Fine, thanks.',
                    question2: 'Status',
                    answer2: 'Great',
                    question3: 'Who is the greatest painter?',
                    answer3: 'Raphael'
                };
                expect(contestData.question1).to.equal('How Are you?');
                expect(GetSystemThemeName()).to.equal('aero');
                expect(testSystemInformation()).to.be.true;

        should do something β€£

        return co.call(this, fn.apply(this, arguments));

The result content of should do something β€£ exposeed co.call`
We may need more specific function content.

An in-range update of mocha is breaking the build 🚨

Version 4.0.0 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.5.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v4.0.0

4.0.0 / 2017-10-02

You might want to read this before filing a new bug! 😝

πŸ’₯ Breaking Changes

For more info, please read this article.

Compatibility

  • #3016: Drop support for unmaintained versions of Node.js (@boneskull):
    • 0.10.x
    • 0.11.x
    • 0.12.x
    • iojs (any)
    • 5.x.x
  • #2979: Drop support for non-ES5-compliant browsers (@boneskull):
    • IE7
    • IE8
    • PhantomJS 1.x
  • #2615: Drop Bower support; old versions (3.x, etc.) will remain available (@ScottFreeCode, @boneskull)

Default Behavior

  • #2879: By default, Mocha will no longer force the process to exit once all tests complete. This means any test code (or code under test) which would normally prevent node from exiting will do so when run in Mocha. Supply the --exit flag to revert to pre-v4.0.0 behavior (@ScottFreeCode, @boneskull)

Reporter Output

πŸ‘Ž Deprecations

  • #2493: The --compilers command-line option is now soft-deprecated and will emit a warning on STDERR. Read this for more info and workarounds (@ScottFreeCode, @boneskull)

πŸŽ‰ Enhancements

  • #2628: Allow override of default test suite name in XUnit reporter (@ngeor)

πŸ“– Documentation

πŸ”© Other

Commits

The new version differs by 48 commits.

  • d69bf14 Release v4.0.0
  • 171b9f9 pfix "prepublishOnly" potential portability problem
  • 60e39d9 Update link to wiki (GitHub at the leading --)
  • 804f9d5 Update link because GitHub ate the leading --
  • 3326c23 update CHANGELOG for v4.0.0 [ci skip]
  • 6dd9252 add link to wiki on --compilers deprecation
  • 96318e1 Deprecate --compilers
  • 92beda9 drop bower support
  • 58a4c6a remove unused .npmignore
  • 7af6611 kill Date#toISOString shim
  • 43501a2 reduce noise about slow tests; make a few tests faster, etc.
  • fa228e9 update --exit / --no-exit integration test for new default behavior
  • 3fdd3ff Switch default from forced exit to no-exit
  • c5d69e0 add integration tests for --exit/--no-exit
  • 3a7f8dc enhance runMochaJSON() helper by returning the subprocess instance

There are 48 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Support for "should.throw()"

Right now, I am testing .should.throw() with some ugly hacks. It would be nice to have this support with co-mocha.

Something like

(yield function * () { /* async code */ }).should.throw();

An in-range update of mocha is breaking the build 🚨

Version 3.2.0 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.1.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • βœ… coverage/coveralls Coverage increased (+0.9%) to 94.958% Details

  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes testing-coma

3.2.0 / 2016-11-24

πŸ“° News

Mocha is now a JS Foundation Project!

Mocha is proud to have joined the JS Foundation. For more information, read the announcement.

Contributor License Agreement

Under the foundation, all contributors to Mocha must sign the JS Foundation CLA before their code can be merged. When sending a PR--if you have not already signed the CLA--a friendly bot will ask you to do so.

Mocha remains licensed under the MIT license.

πŸ› Bug Fix

  • #2535: Fix crash when --watch encounters broken symlinks (@villesau)
  • #2593: Fix (old) regression; incorrect symbol shown in list reporter (@Aldaviva)
  • #2584: Fix potential error when running XUnit reporter (@vobujs)

πŸŽ‰ Enhancement

πŸ”© Other

Thanks to all our contributors, sponsors and backers! Keep on the lookout for a public roadmap and new contribution guide coming soon.

Commits

The new version differs by 21 commits .

  • b51e360 Release v3.2.0
  • 5badf0b rebuild mocha.js for release v3.2.0 [ci skip]
  • b1d6b49 update CHANGELOG.md for v3.2.0 [ci skip]
  • 7a05a6c use spec reporter in tests by default; closes #2594
  • 004389f tweak timeout messaging; see #2294
  • 12afaf7 cleanup .gitignore [ci skip]
  • edde033 fix XUnit reporter output. Closes #2584
  • f5bef7c Revert test pass symbol in List reporter
  • 4a2e85a ignore files files which are not found by files() (#2538)
  • 79d7414 Add Browser Support Matrix to README.md (#2590) [ci skip]
  • 1d52fd3 use karma-mocha; closes #2570
  • 8941442 adds info about --inspect flag to options in --help
  • 71e7a1e rename some fixture files that had the wrong extension
  • 1a45929 typo in comment
  • b5a424a Link license from current branch

There are 21 commits in total. See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of mocha is breaking the build 🚨

Version 3.3.0 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.2.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details - ❌ **continuous-integration/travis-ci/push** The Travis CI build could not complete due to an error [Details](https://travis-ci.org/blakeembrey/co-mocha/builds/225162246),- βœ… **coverage/coveralls** First build on greenkeeper/mocha-3.3.0 at 94.737% [Details](https://coveralls.io/builds/11210197)

Release Notes coverave

Thanks to all our contributors, maintainers, sponsors, and users! ❀️

As highlights:

  • We've got coverage now!
  • Testing is looking less flaky \o/.
  • No more nitpicking about "mocha.js" build on PRs.

πŸŽ‰ Enhancements

  • #2659: Adds support for loading reporter from an absolute or relative path (@sul4bh)
  • #2769: Support --inspect-brk on command-line (@igwejk)

πŸ› Fixes

  • #2662: Replace unicode chars w/ hex codes in HTML reporter (@rotemdan)

πŸ” Coverage

πŸ”© Other

Commits

The new version differs by 89 commits0.

  • fb1687e :ship: Release v3.3.0
  • 1943e02 Add Changelog for v3.3.0
  • 861e968 Refactor literal play-icon hex code to a var
  • 1d3c5bc Fix typo in karma.conf.js
  • 9bd9389 Fix spec paths in test HTML files
  • 0a93024 Adds tests for loading reporters w/ relative/absolute paths (#2773)
  • 73929ad Comment special treatment of '+' in URL query parsing
  • e2c9514 Merge pull request #2769 from igwejk/support_inspect_break_in_opts
  • 038c636 Support --inspect-brk on command-line
  • b4ebabd Merge pull request #2727 from lamby/reproducible-build
  • 882347b Please make the build reproducible.
  • a2fc76c Merge pull request #2703 from seppevs/cover_utils_some_fn_with_tests
  • ed61cd0 cover .some() function in utils.js with tests
  • f42cbf4 Merge pull request #2701 from craigtaub/landingSpec
  • 6065242 use stubbed symbol

There are 89 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Upgrade to co 4.x

Hi, I am using co-mocha, and could you upgrade the dependence co to version 4.x ? thanks!

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.