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:
npm
installs dependencies in the following way: it see that themoment@2.17.1
is ok for both dependencies (2.17.1
and^2.10.3
) and install modules in the following dirs:But
yarn
installs the latestmoment
version (2.18.1) as a TestCafe dependency and the2.17.1
version as the project’s dependecy. It looks like:Then
testcafe
imports themoment-duration-format
module and it patches themoment
module from the rootnode_modules
directory (2.17.1
) and add additional API there. But TestCafe uses themoment
module from it’s ownnode_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
@andreyluiz, It possible you need to remove the
yarn.lock
file 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.1
version. I tried to addmoment
asyarn
dependency and nowtestcafe
works as expected.Do you think
bower
is responsible for this? NOTE: I also tried upgrading thebower
’smoment
to2.18.1
, but I had the same (not working) result.EDIT:
I have tried using
npm
instead ofyarn
to install a freshnode_modules
and now the problem is disappeared… So, isyarn
the problem? 😕Hello @LasaleFamine! Do you use
moment
package in your project? It’s very likely thatyarn
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’.