Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running asynchronous tests #129

Closed
gmiano opened this issue Jun 19, 2016 · 10 comments
Closed

Error running asynchronous tests #129

gmiano opened this issue Jun 19, 2016 · 10 comments

Comments

@gmiano
Copy link

gmiano commented Jun 19, 2016

Hi there,
I am having some problems in running a qunit file which contains many asynchrounous tests.

For instance I have a test structured like this:
QUnit.test("Test asynchfunction.", function(assert){ var done = assert.async(); this.MODULE.myFunction() .then(function(result){ assert.ok(true, "Complete workflow execution ended correctly."); done(); }) .catch(function(err){ assert.ok(false, "A server error occurred."); done(); }) });

The same file executes all the tests correctly when opened within a browser. On the contrary by using grunt-contrib-qunit to run it, it always go within the catch statement.
There is a possible solution to that? I really would like to automatize everything and it is a big issue.

Thanks,
G.

@Arkni
Copy link
Member

Arkni commented Jun 21, 2016

As far as I know, PhantomJS 2 doesn't support promises at all. So you have to use a pollyfill (es6-promise for example) to make your test work.

I created a repository with minimal code (roughly the same as the code you provided) to prove that everything works as expected, clone it and run npm install && npm test

@Arkni
Copy link
Member

Arkni commented Jul 8, 2016

@gmiano have you fixed your issues ? if so, can you share your workaround ?

@gmiano
Copy link
Author

gmiano commented Jul 8, 2016

Hi @Arkni, sorry but I have had not enough time to work on that problem. I have made a test using your workaround but it seems not to work. Every time I esecutivo the test it enters the catch statement and the test return an error.

G.

@Arkni
Copy link
Member

Arkni commented Jul 8, 2016

Can you create a repository that I can check and test. I'll take a look at it when time allows.

@gmiano
Copy link
Author

gmiano commented Jul 8, 2016

Yep, when I have time enough I'la do it!

Thanks for you help @Arkni!

@matzetronic matzetronic mentioned this issue Jul 14, 2016
5 tasks
@matzetronic
Copy link

Hi @Arkni please see https://github.com/matzetronic/grunt-contrib-qunit-promise for a demonstration of the error. Thanks!

@matzetronic
Copy link

But I dont know if that is the same issue since I use requirejs to load the tests and that could also be another issue. But they also time out. If you open the same tests in the browser they run successfully (as you can see in my repo).

@Arkni
Copy link
Member

Arkni commented Jul 15, 2016

@matzetronic
This should fix it for you:

 test/index.html | 11 ++++++++---
 test/test.js    |  8 +++++---
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/test/index.html b/test/index.html
index f36d119..2ffa305 100644
--- a/test/index.html
+++ b/test/index.html
@@ -14,17 +14,22 @@
    <body id="body">
    <div id="qunit"></div>

-   <script src="../../node_modules/requirejs/require.js"></script>
+   <script src="../node_modules/requirejs/require.js"></script>
    <script>

    require.config({
        paths: {
-           qunitjs: "../../node_modules/qunitjs/qunit/qunit",
+           // The bridge file injected by grunt-contrib-qunit use the name `qunit`
+           // see note in README:
+           //   https://github.com/gruntjs/grunt-contrib-qunit#loading-qunit-with-amd
+
+           // Also, you were using a wrong path to `QUnit`
+           qunit: "../node_modules/qunitjs/qunit/qunit",
            tests: "./test"
        }
    });

-   require( [ "qunitjs", "tests" ], function( QUnit, tests ) {
+   require( [ "qunit", "tests" ], function( QUnit, tests ) {
        tests();
        QUnit.start();
    } );
diff --git a/test/test.js b/test/test.js
index 554692d..5140763 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,7 +1,9 @@
-
-define(["qunitjs"], function(QUnit) {
+// The bridge file used by grunt-contrib-qunit uses the name `qunit`
+// see note in README:
+//   https://github.com/gruntjs/grunt-contrib-qunit#loading-qunit-with-amd
+define(["qunit"], function(QUnit) {
    "use strict";
-   
+
    return function() {
        function fn(i) {
            return new Promise(function(resolve, reject) {

@matzetronic
Copy link

Great thanks! I copied the paths from another project, sorry! But that qunit has to be defined was probably the real error..

@Arkni
Copy link
Member

Arkni commented Feb 12, 2017

I'm closing this issue since the original poster hasn't yet responded to the request made to them. I therefore assume that the user has lost interest or resolved the problem on their own.

Don't worry though; if you have followup question, let us know with a comment and I'll be happy to reopen the issue.

Thanks!

@Arkni Arkni closed this as completed Feb 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants