How can I retry failed end to end tests in Detox using Mocha? - react-native

I have a flaky end-to-end test that uses Detox and Mocha.
The Mocha test runner allows for multiple retries. I tried using the recommended Mocha syntax:
// auth.spec.js
describe('App authentication', () => {
this.retries(2);
it('should have a login screen', async () => {
await expect(element(by.id('LoginScreenView'))).toBeVisible();
});
});
However, it appears this is an empty object ({}) and does not have a retries function when running Detox with Mocha as the test runner.
It generates the following error:
node_modules/.bin/mocha __e2e__ --opts __e2e__/config/mocha.opts --
configuration ios.sim.debug --grep :android: --invert --artifacts-location "__e2e__/artifacts/ios.sim.debug.2018-10-17 22-51-12Z"
/<path>/__e2e__/auth.spec.js:10
this.retries(2);
^
TypeError: this.retries is not a function
at Suite.describe (/<path>/__e2e__/auth.spec.js:4:8)
at Object.create (/<path>/node_modules/mocha/lib/interfaces/common.js:112:19)
at context.describe.context.context (/<path>/node_modules/mocha/lib/interfaces/bdd.js:40:27)
at Object.<anonymous> (/<path>/__e2e__/auth.spec.js:3:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at /<path>/node_modules/mocha/lib/mocha.js:250:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/<path>/node_modules/mocha/lib/mocha.js:247:14)
at Mocha.run (/<path>/node_modules/mocha/lib/mocha.js:576:10)
at Object.<anonymous> (/<path>/node_modules/mocha/bin/_mocha:637:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
child_process.js:644
throw err;
^
Is there a way to automatically retry failed tests in Detox?

this in mocha can't work with arrow function, so must change it into ordinary one
// auth.spec.js
describe('App authentication', function () { // change it
this.retries(2);
It is not recommended best practice to use in Mocha
Ref:
https://mochajs.org/#arrow-functions
Hope it helps

Related

react native android error after upgrade to 0.67.2 - SyntaxError: Unexpected token =

I have just upgraded from RN 0.63.3 to 0.67.2...and Im now receiving an error when I try to clean project in Android studio
....node_modules\#react-native-community\cli-plugin-metro\node_modules\metro\src\Server.js:350 processRequest = (req, res, next) => { ^SyntaxError: Unexpected token = at Module._compile (internal/modules/cjs/loader.js:721:23) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:690:17) at require (internal/modules/cjs/helpers.js:25:18) at Object.<anonymous> (....node_modules\#react-native-community\cli-plugin-metro\node_modules\metro\src\shared\output\bundle.js:12:16) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
If you look at the file path its referring to (node_modules\#react-native-community\cli-plugin-metro\node_modules\metro\src\Server.js:350)...this is the line of code where its unhappy
processRequest = (req, res, next) => {
this._processRequest(req, res, next).catch(next);
};
Upgrading node to latest version fixed the issue

While unit React-native test files with Mocha, it gives error unexpected tocken

In a React-native project, I want to setup unit testing, For this I am using Mocha and Chai. When I run command npm test it executes mocha __tests__/*.js internally. In test file my code is following:
import { expect } from 'chai';
import Adapter from 'enzyme-adapter-react-16';
import { RefundedEmd } from './RefundedEmd';
import React from 'react';
import renderer from 'react-test-renderer';
describe('App', () => {
it('renders correctly', () => {
renderer.create(<App />);
});
});
I get following error in console:
C:\Technical work\Lorex\slf-mobile-impl\__tests__\App-test.js:1
import { expect } from 'chai';
^
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\mocha.js:311:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\mocha.js:308:14)
at Mocha.run (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\mocha.js:849:10)
at Object.exports.singleRun (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\run-helpers.js:108:16)
at exports.runMocha (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\run-helpers.js:143:13)
at Object.exports.handler.argv [as handler] (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\run.js:305:3)
at Object.runCommand (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\node_modules\yargs\lib\command.js:242:26)
at Object.parseArgs [as _parseArgs] (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\node_modules\yargs\yargs.js:1087:28)
at Object.parse (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\node_modules\yargs\yargs.js:566:25)
at Object.exports.main (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\cli.js:68:6)
at Object.<anonymous> (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\bin\mocha:133:29)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! Test failed. See above for more details.

How to use ssr supported packages in vue with vue-server-renderer?

I tried to use vue2-google-maps and it worked well.
Suddenly my computer had stopped working and then I restarted my computer.
Then, strangely, 500-error comes out.
I reverted all codes associated with vue2-google-maps then my project works well.
Even though when I import vue2-google-maps then It occurs 500-error. :(
App.js
import * as VueGoogleMaps from 'vue2-google-maps';
It was working well but now cause of the unknown reason it has been broken...
Here is my console shows error.
webpack built 5410edae88d11b814c0b in 2690ms
error during render : /search
/media/bossminion/Work/WeMeet/frontend/node_modules/vue2-google-maps/dist/components/infoWindow.vue:3
<template>
^
SyntaxError: Unexpected token <
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (/media/bossminion/Work/WeMeet/frontend/node_modules/vue2-google-maps/dist/main.js:42:19)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at r (/media/bossminion/Work/WeMeet/frontend/node_modules/vue-server-renderer/build.dev.js:9295:16)
at Object.<anonymous> (webpack:/external "vue2-google-maps":1:0)
at __webpack_require__ (webpack:/webpack/bootstrap a442baf8af813fadc2a4:25:0)
error during render : /favicon.ico
/media/bossminion/Work/WeMeet/frontend/node_modules/vue2-google-maps/dist/components/infoWindow.vue:3
<template>
^
SyntaxError: Unexpected token <
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (/media/bossminion/Work/WeMeet/frontend/node_modules/vue2-google-maps/dist/main.js:42:19)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at r (/media/bossminion/Work/WeMeet/frontend/node_modules/vue-server-renderer/build.dev.js:9295:16)
at Object.<anonymous> (webpack:/external "vue2-google-maps":1:0)
at __webpack_require__ (webpack:/webpack/bootstrap a442baf8af813fadc2a4:25:0)
Is it possible that project that worked well could cause 500-error for no reason?
Environment: Ubuntu 18.04, npm v6.9.0, node v12.6.0
I have found how to handle ssr.
App.js
if (process.browser) {
const VueGoogleMaps = require('vue2-google-maps');
Vue.use(VueGoogleMaps, {
load: {
key: 'myKey',
libraries: 'places',
},
});
}
Instead of using import, I used require when it is client rendering.
I will be happy if it helped you. :D

Yarn run build SyntaxError

runing Electron Build result in a SyntaxError: Unexpected token function
$ build
...\node_modules\read-config-file\out\main.js:72
async function readConfig(configFile) {
^^^^^^^^
SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
Found a fix
This issue is realated to
https://github.com/electron-userland/electron-builder/issues/2986
Looks like the issue is not present in version or electron builder before 20.8.1
If you are using node version 7.x or lower, update your node installation.
Async is not supported until node version 8.

jest-haste-map: watch error complaining that it can't find a file in the jest-haste-map node_modules folder

I just upgraded to RN 0.56.0 and am using jest version: 22.4.3 (updating the jest version doesn't help)
When I try to run my test suite, I get the following error in the terminal:
jest-haste-map: watch error: Error: ENOENT: no such file or directory,
open '/Users/mobilepractice/builds/0bcf5ed0/0/cx-mobile/posting-
plus/PostingPlus/node_modules/jest-haste-map/build/worker.js' at Error
(native) at Object.fs.openSync (fs.js:640:18) at Object.fs.readFileSync
(fs.js:508:33) at Module._extensions..js (module.js:578:20) at
Object.require.extensions.(anonymous function) [as .js]
(/Users/mobilepractice/builds/0bcf5ed0/0/cx-mobile/posting-
plus/PostingPlus/node_modules/babel-register/lib/node.js:152:7) at
Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at
Function.Module._load (module.js:438:3) at Module.require
(module.js:497:17) at require (internal/module.js:20:19)
and this error as well:
/Users/mobilepractice/builds/0bcf5ed0/0/cx-mobile/posting-
plus/PostingPlus/node_modules/react-native/jest/hasteImpl.js:50 ) /*:
string | void */ { ^ SyntaxError: Unexpected token ) at
Object.exports.runInThisContext (vm.js:76:16) at Module._compile
(module.js:542:28) at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at
Function.Module._load (module.js:438:3) at Module.require
(module.js:497:17) at require (internal/module.js:20:19) at Object.
<anonymous> (/Users/mobilepractice/builds/0bcf5ed0/0/cx-mobile/posting-
plus/PostingPlus/node_modules/jest-runtime/node_modules/jest-haste-
map/build/worker.js:16:19) at next (native)
I can see the worker.js file in my node_modules folder, which is why the ENOENT error is confusing.
A solution is to make sure node 8 or higher is installed. This error occurs on node 6.9.1.