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

Running sample test thrown an UnhandledPromiseRejectionWarning: this.moment.duration(...).format is not a function #1750

Closed
LasaleFamine opened this issue Sep 1, 2017 · 15 comments
Assignees
Labels
AREA: build STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: bug The described behavior is considered as wrong (bug).
Milestone

Comments

@LasaleFamine
Copy link

Are you requesting a feature or reporting a bug?

  • Could be a bug.

What is the current behavior?

After a fresh installation within my project directory I followed the main example of the Getting Started doc's paragraph.
The test example runs correctly, but at the end of the test the browser hangs on a Testcafe page that said Connected with a loading spinner and an error is shown on the terminal:

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: this.moment.duration(...).format is not a function

What is the expected behavior?

Finished tests and close the browser without errors (?).

How would you reproduce the current behavior (if this is a bug)?

Installed within my Ubuntu:

VERSION="16.04.2 LTS (Xenial Xerus)"
PRETTY_NAME="Ubuntu 16.04.2 LTS"
VERSION_ID="16.04"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

Inside a project with the command:

yarn add --dev testcafe

Running with a yarn script yarn test:testcafe that runs testcafe:

testcafe chrome test/testcafe

Within the testcafe folder I have a main.js file for my test.

Provide the test code and the tested page URL (if applicable)

main.js
import { Selector } from 'testcafe';

fixture `Getting Started`
    .page `https://devexpress.github.io/testcafe/example`;

test('My first test', async t => {
    await t
        .typeText('#developer-name', 'John Smith')
        .click('#submit-button');
});

Specify your

  • operating system: Ubuntu (as stated)
  • testcafe version: 0.17.1
  • node.js version: 8.1.0
@AndreyBelym
Copy link
Contributor

AndreyBelym commented Sep 1, 2017

Hello @LasaleFamine! Do you use moment package in your project? It's very likely that yarn hasn't installed dependencies correctly, we had a similar issue before: https://testcafe-discuss.devexpress.com/t/promise-rejection-warning-on-test-completion/184/16. If you use it, try to change the package version to `^2.10.3'.

@LasaleFamine
Copy link
Author

LasaleFamine commented Sep 1, 2017

Hi @AndreyBelym and thank you for your fast response.

Actually I have moment , but as Bower dependency (don't blame me for this, legacy app 💀) and it is at the 2.17.1 version.
I tried to add moment as yarn dependency and now testcafe works as expected.

Do you think bower is responsible for this?
NOTE: I also tried upgrading the bower's moment to 2.18.1, but I had the same (not working) result.

EDIT:

I have tried using npm instead of yarn to install a fresh node_modules and now the problem is disappeared... So, is yarn the problem? 😕

@AlexanderMoskovkin
Copy link
Contributor

Yes, it seems it relates to a package manager issue

@LasaleFamine
Copy link
Author

So I must assume that testcafe is not supporting yarn?

@AlexanderMoskovkin
Copy link
Contributor

AlexanderMoskovkin commented Sep 12, 2017

I've investigated the issue in more details and found the exact reason why does it fail.

For example your project has the following dependencies:

"dependencies": {
  "moment": "2.17.1",
  "testcafe": "^0.17.2"
}

TestCafe has the following deps:

"moment": "^2.10.3",
"moment-duration-format": "^1.3.0",

npm installs dependencies in the following way: it see that the [email protected] is ok for both dependencies (2.17.1 and ^2.10.3) and install modules in the following dirs:

/your-project-dir
-- /node_modules
-- -- /testcafe 
-- -- /moment (2.17.1)
-- -- /moment-duration-format (1.3.0)

But yarn installs the latest moment version (2.18.1) as a TestCafe dependency and the 2.17.1 version as the project's dependecy. It looks like:

/your-project-dir
-- /node_modules
-- -- /testcafe 
-- -- -- /node_modules
-- -- -- -- /moment (2.18.1)
-- -- /moment (2.17.1)
-- -- /moment-duration-format (1.3.0)

Then testcafe imports the moment-duration-format module and it patches the moment module from the root node_modules directory (2.17.1) and add additional API there. But TestCafe uses the moment module from it's own node_modules directory (2.18.1) that is not patched.

So to make it workable with yarn it necessary to update the moment version in your project to the latest (it possible it's necessary to clean yarn cache).

Meanwhile, we'll see how we can avoid this collision

@AlexanderMoskovkin AlexanderMoskovkin added AREA: build TYPE: bug The described behavior is considered as wrong (bug). labels Sep 12, 2017
@AlexanderMoskovkin AlexanderMoskovkin added this to the Sprint #9 milestone Sep 12, 2017
@inikulin
Copy link
Contributor

It's definitely yarn's bug and should be reported there.

@damianbaar
Copy link

Hey,

I resolved this issue by providing resolutions to package.json according to this yarnpkg/yarn#2763, but it also works if will specify dummy dependency which is not fulfilling semver for moment-duration-format in testcafe package.json file, like moment-duration-format: 1.2.0

It make sense to me what yarn is doing, but personally I believe that moment-duration-format requires too much. I would really like to avoid such things in package.json so is there any chance to drop this dependency in near future?

@AlexanderMoskovkin
Copy link
Contributor

Hi @damianbaar,

Thanks for the workaround with resolutions. We will check how we can avoid this.

@justrhysism
Copy link

It make sense to me what yarn is doing, but personally I believe that moment-duration-format requires too much. I would really like to avoid such things in package.json so is there any chance to drop this dependency in near future?

Yeah if it's just for formatting dates, https://github.com/date-fns/date-fns might be a better option.

@andreyluiz
Copy link

@damianbaar, the resolutions workaround did not work for me.

@AlexanderMoskovkin
Copy link
Contributor

@andreyluiz, It possible you need to remove the yarn.lock file to refresh dependencies.

@ghost
Copy link

ghost commented Apr 5, 2018

confirmed this works for me now

@s-robertson
Copy link

I just ran into this issue as well, even though my project had a newer version of moment as a dependency. I ended up having to delete an entry for the older version of moment from my yarn.lock file so that only 1 version of moment was installed.

After having looked at the documentation for moment-duration-format, I think this issue can be avoided entirely by using the package as a module in plugin-host.js, rather than letting it patch the global moment instance. Here's an example from the docs:

var moment = require("moment-timezone");
var momentDurationFormatSetup = require("moment-duration-format");

momentDurationFormatSetup(moment);

In plugin-host.js, moment-duration-format could be imported as a module and the ReporterPluginHost class constructor could set up its moment property like so:

this.moment = momentDurationFormatSetup(moment);

If it looks like this would work, and is an acceptable solution, I'd be happy to open a PR.

@AndreyBelym
Copy link
Contributor

Hi @s-robertson! Thanks for pointing on it. It's a very important issue, I'll try your solution and provide a fix for TestCafe ASAP.

@miherlosev miherlosev modified the milestones: Planned, Sprint #12 May 8, 2018
AlexKamaev added a commit to AlexKamaev/testcafe that referenced this issue May 23, 2018
@lock
Copy link

lock bot commented Mar 28, 2019

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

@lock lock bot added the STATE: Auto-locked An issue has been automatically locked by the Lock bot. label Mar 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 28, 2019
kirovboris pushed a commit to kirovboris/testcafe-phoenix that referenced this issue Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
AREA: build STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

No branches or pull requests

10 participants