testcafe: Running sample test thrown an UnhandledPromiseRejectionWarning: this.moment.duration(...).format is not a function
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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 8
- Comments: 15 (7 by maintainers)
Commits related to this issue
- update moment module from testcafe/node_modules/ (closes #1750) — committed to AlexKamaev/testcafe by AlexKamaev 6 years ago
- update moment module from testcafe/node_modules/ (closes #1750) (#2452) — committed to kirovboris/testcafe-phoenix by AlexKamaev 6 years ago
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:
TestCafe has the following deps:
npminstalls dependencies in the following way: it see that themoment@2.17.1is ok for both dependencies (2.17.1and^2.10.3) and install modules in the following dirs:But
yarninstalls the latestmomentversion (2.18.1) as a TestCafe dependency and the2.17.1version as the project’s dependecy. It looks like:Then
testcafeimports themoment-duration-formatmodule and it patches themomentmodule from the rootnode_modulesdirectory (2.17.1) and add additional API there. But TestCafe uses themomentmodule from it’s ownnode_modulesdirectory (2.18.1) that is not patched.So to make it workable with yarn it necessary to update the
momentversion 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
@andreyluiz, It possible you need to remove the
yarn.lockfile to refresh dependencies.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 the2.17.1version. I tried to addmomentasyarndependency and nowtestcafeworks as expected.Do you think
boweris responsible for this? NOTE: I also tried upgrading thebower’smomentto2.18.1, but I had the same (not working) result.EDIT:
I have tried using
npminstead ofyarnto install a freshnode_modulesand now the problem is disappeared… So, isyarnthe problem? 😕Hello @LasaleFamine! Do you use
momentpackage in your project? It’s very likely thatyarnhasn’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’.