Bitrise + Detox + React-native - Hello World Example hangs on detox.init - react-native

I'm trying to get the react-native "Hello World" app setup with Detox and running on Bitrise.io. I went through the react-native-cli getting started guide and am trying to run the simplest detox test using Detox + Jest on Bitrise with it.
The specific error I'm encountering is the device and element globals not being defined (see log or in the link below). From what I've researched so far, this is caused by detox.init not ever finishing.
Is there some basic config with Bitrise that I'm missing? The detox test command runs locally for me just fine.
I'm using a free Bitrise account, and the project is public. You can see a failed build here: https://app.bitrise.io/build/e7926ddfc759288f#?tab=log
The repo is also public: https://github.com/jamesopti/react-native-test/blob/add_detox/AwesomeProject/e2e/firstTest.spec.js
Thanks in advance!
Bitrise Error Log
Example: should have welcome screen
Example: should have welcome screen [FAIL]
FAIL e2e/firstTest.spec.js (122.008s)
Example
✕ should have welcome screen (8ms)
● Example › should have welcome screen
Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 120000ms timeout specified by jest.setTimeout.
at mapper (../node_modules/jest-jasmine2/build/queueRunner.js:25:45)
● Example › should have welcome screen
ReferenceError: device is not defined
1 | describe('Example', () => {
2 | beforeEach(async () => {
> 3 | await device.reloadReactNative();
| ^
4 | });
5 |
6 | it('should have welcome screen', async () => {
bitrise.yml
---
format_version: '8'
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: react-native
trigger_map:
- push_branch: "*"
workflow: primary
- pull_request_source_branch: "*"
workflow: primary
workflows:
deploy:
description: "## ..."
steps:
- activate-ssh-key#4.0.3:
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
- git-clone#4.0.17: {}
- script#1.1.5:
title: Do anything with Script step
- yarn#0.1.0:
inputs:
- workdir: AwesomeProject
- command: install
- install-missing-android-tools#2.3.7:
inputs:
- gradlew_path: "$PROJECT_LOCATION/gradlew"
- android-build#0.10.0:
inputs:
- project_location: "$PROJECT_LOCATION"
- certificate-and-profile-installer#1.10.1: {}
- xcode-archive#2.7.0:
inputs:
- project_path: "$BITRISE_PROJECT_PATH"
- scheme: "$BITRISE_SCHEME"
- export_method: "$BITRISE_EXPORT_METHOD"
- configuration: Release
- deploy-to-bitrise-io#1.9.2: {}
primary:
steps:
- activate-ssh-key#4.0.3:
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
- git-clone#4.0.17: {}
- yarn#0.1.0:
inputs:
- workdir: AwesomeProject
- command: install
title: Yarn Install
- yarn#0.1.0:
inputs:
- workdir: AwesomeProject
- command: test
title: Unit tests
after_run:
- detox
detox:
steps:
- cocoapods-install#1.9.1:
inputs:
- source_root_path: "$BITRISE_SOURCE_DIR/AwesomeProject/ios"
- npm#1.1.0:
title: Install Global
inputs:
- workdir: "$BITRISE_SOURCE_DIR/AwesomeProject"
- command: install -g detox-cli react-native-cli
- script#1.1.5:
inputs:
- working_dir: "$BITRISE_SOURCE_DIR/AwesomeProject"
- content: |-
#!/usr/bin/env bash
brew tap facebook/fb
export CODE_SIGNING_REQUIRED=NO
brew install fbsimctl
brew tap wix/brew
brew install applesimutils --HEAD
title: Install detox utils
- script#1.1.5:
inputs:
- working_dir: "$BITRISE_SOURCE_DIR/AwesomeProject"
- content: |-
#!/usr/bin/env bash
detox build --configuration ios.sim.debug
title: Detox Build
- script#1.1.5:
inputs:
- working_dir: "$BITRISE_SOURCE_DIR/AwesomeProject"
- content: |-
#!/usr/bin/env bash
detox test --configuration ios.sim.debug --cleanup
title: Detox Test
app:
envs:
- opts:
is_expand: false
PROJECT_LOCATION: AwesomeProject/android
- opts:
is_expand: false
MODULE: app
- opts:
is_expand: false
VARIANT: ''
- opts:
is_expand: false
BITRISE_PROJECT_PATH: AwesomeProject/ios/AwesomeProject.xcworkspace
- opts:
is_expand: false
BITRISE_SCHEME: AwesomeProject
- opts:
is_expand: false
BITRISE_EXPORT_METHOD: ad-hoc
meta:
bitrise.io:
machine_type: elite

Unfortunately, this is a very generic bug and can be caused by multiple things (incompatible OS/jest + detox versions/node + detox versions, etc).
If you're using MacOS, an option you can take in able to check what's going wrong in Bitrise's VM is connecting via Screen Sharing: I'd suggest adding a while someFileDoesntExist (to stop iteration naturally without the abort button) in your current workflow after the packages installation steps (node, detox, jest etc) and then checking if its the same one you're running locally.
If that's not the case, check if the VM is running the same simulator -- phone model && OS version; if its not, then you can specify the simulator & OS version in your detox configuration.
If that also didn't work, I'm not sure what it could be :(

Related

GitLab CI: Unable to test socketIO endpoints when FF_NETWORK_PER_BUILD is 1

I use GitLab CI to perform the E2E tests on socket IO endpoints and it used to be working correctly until I set FF_NETWORK_PER_BUILD to 1 in the .gitlab-ci.yml file.
No specific error is thrown, what is the problem?
This is how I connect to socket server in Jest test:
const address = app.listen().address(); // returns { address: '::', family: 'IPv6', port: 42073 }
const baseAddress = `http://${address.host}:${address.port}`;
socket = io(baseAddress, {
transports: ['websocket'],
auth: { token: response.body.token },
forceNew: true,
});
.gitlab-ci.yml
image: node:16
stages:
- dependencies
- e2e
- build
cache:
paths:
- node_modules
dependency_job:
stage: dependencies
script:
- npm ci
test_e2e:
stage: test
variables:
NODE_ENV: test
PORT: 3000
THROTTLE_TTL: 60000
THROTTLE_LIMIT: 1
SESSION_SECRET: somesecret
DOMAIN: console.okhtapos.com
POSTGRES_PASSWORD: password
DATABASE_URL: "postgresql://postgres:password#postgres:5432/postgres?schema=public"
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_VOLATILE_HOST: redis
REDIS_VOLATILE_PORT: 6379
SESSIONS_REDIS_PREFIX: "sess:"
SESSIONS_SECRET: somesecret
SESSIONS_NAME: omni-session
GRPC_URL: localhost:5004
OCTO_CENTRAL_GRPC_URL: localhost:5005
CUSTOMERS_ATTRIBUTES_DATABASE_NAME: omnichannel-customer-attributes
CUSTOMERS_ATTRIBUTES_MAX: 100
CUSTOMERS_ATTRIBUTES_MAX_TOTAL_SIZE_IN_BYTES: 5000
MONGODB_URL: mongodb://mongo:27017
CUSTOMERS_ATTRIBUTES_MAX_QUARANTINE_DAYS: 7
KAFKA_BROKERS: kafka:9092
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka:9092,INTERNAL://localhost:9093"
KAFKA_BROKER_ID: "1"
KAFKA_INTER_BROKER_LISTENER_NAME: "INTERNAL"
KAFKA_LISTENERS: "PLAINTEXT://0.0.0.0:9092,INTERNAL://0.0.0.0:9093"
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "PLAINTEXT:PLAINTEXT,INTERNAL:PLAINTEXT"
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
LABELS_MAX_QUARANTINE_DAYS: 7
LABELS_MAX: 100
DEPARTMENTS_MAX: 100
AUTHENTICATION_GATEWAY_SECRET: someGatewaySecret
CASSANDRA_CONTACT_POINTS: cassandra:9042
CASSANDRA_LOCAL_DATA_CENTER: datacenter1
CASSANDRA_KEYSPACE: omnichannel
FF_NETWORK_PER_BUILD: 1
ZOOKEEPER_CONNECT: zookeeper:2181
BROKER_ID: 1
services:
- redis:latest
- postgres:15beta3
- mongo:latest
- cassandra:latest
- name: debezium/zookeeper:2.0.0.Beta1
alias: zookeeper
- name: debezium/kafka:2.0.0.Beta1
alias: kafka
script:
- npx prisma generate
- npx prisma migrate deploy
- npm run test:e2e
build_job:
stage: build
script:
- npm run build

How to configure Cypress for e2e in Github Actions?

I am trying to do an e2e test on my VueJS app that uses axios for API calls. In my vue component, in the mounted, i do an API call. My idea would be to mock this call with cy.intercept and cy.wait, however i can't make it work. On my local environment when i launch my frontend and backend servers, my test passes as the API call is made. However, the call is not silenced and the cy.wait('#apiCall') does not work.
Also my test does not work in Github Actions, i have this error : AxiosError: The following error originated from your application code, not from Cypress. It was caused by an unhandled promise rejection.. I have the impression that github actions need a special ci environment file but i don't know where to tell cypress to look into those env variables when in continous integration.
Anyone had the same issue or knows about cypress X axios X github actions combined ?
Some of my code :
test.cy.js
cy.intercept('GET', '/coaches/coach-informations/30283', {
data: {
email: 'hello#hello.com',
},
}).as('getCoach')
cy.visit('/hello?coach=30283')
cy.wait('#getCoach')
component.vue
async mounted() {
await axios.get(`/coaches/coach-informations/30283/`)
}
.env
API_URL=http://127.0.0.1:8000/api
test-frontend.yml
name: GitHub Actions Demo
on: [pull_request, push]
jobs:
cypress-run:
runs-on: ubuntu-latest
env:
working-directory: front
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Install node
uses: actions/setup-node#v3
with:
node:version: 'node-version'
- name: Get yarn cache directory path 🛠
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
working-directory: ${{env.working-directory}}
- name: Cache node_modules 📦
uses: actions/cache#v2.1.7
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-${{ hashFiles('front/yarn.lock') }}
restore-keys: |
yarn-
- name: Install dependencies 👨🏻‍💻
working-directory: ${{env.working-directory}}
run: yarn
- name: Cypress run
uses: cypress-io/github-action#v2
with:
working-directory: ${{env.working-directory}}
build: yarn build
start: yarn vite
wait-on: 'http://localhost:3000'
wait-on-timeout: 120
config-file: cypress.config.js
record: true
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
I would say the URL used in the intercept is not catching the request from the app.
Locally you have a server running, so axios is ok but on Github the server is absent and the axios call fails.
It looks like you just need to add wildcard characters before the URL fragment
cy.intercept('GET', '**/coaches/coach-informations/30283', {
data: {
email: 'hello#hello.com',
},
}).as('getCoach')

How to get env variables from env in github action .yaml in Vite project

I want to set an environment variable in github action .yaml. And I can access that variable inside my Vite project run time.
Exp:
# staging.yaml - my github action file
...
env: VITE_INTERNAL = true
...
// index.vue - my Vite project
function myTest(){
console.log(process.env.VITE_INTERNAL) // I hope to get "true" instead of "undefined"
}
Anyone can help me, please. Thanks a lot!
To set an environment variable in a GitHub Action YAML, you can use env, jobs.<job_id>.env, or jobs.<job_id>.steps[*].env:
name: Build
permissions:
contents: read
issues: read
checks: write
pull-requests: write
on: push
# 👇 global env
env:
VITE_INTERNAL: true
jobs:
build:
runs-on: ubuntu-latest
# 👇 or job-level env
env:
VITE_INTERNAL: true
steps:
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: 18.x
cache: 'npm'
- name: Install dependencies
run: npm i
- name: Build
run: npm run build
# 👇 or step-level env
env:
VITE_INTERNAL: true
To access the environment variable from JavaScript, use import.meta.env.VITE_INTERNAL (not process.env.VITE_INTERNAL).
GitHub demo
You can read the docs here, but to expose env variables, you can do it like the following.
.env
VITE_INTERNAL = true
.yaml
console.log(import.meta.env.VITE_INTERNAL)

Serverless deploy fails - Error: Write EPIPE

I have used Serverless Framework previously but lately I am having an error I cannot resolve. Serverless Framework version 3.8.0. was installed using npm. Node version 17.7.1. Running on Linux(Manjaro)
Running sls deploy
✔ Service deployed to stack test-api-dev (0s)
But nothing actually changes on AWS, nothing is actually deployed.
Running sls deploy | echo outputs
Running "serverless" from node_modules
✖ Uncaught exception
/home/mascs/api/node_modules/serverless/scripts/serverless.js:49
throw error;
^
Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:817:11)
at Socket._write (node:net:829:8)
at writeOrBuffer (node:internal/streams/writable:390:12)
at _write (node:internal/streams/writable:331:10)
at Socket.Writable.write (node:internal/streams/writable:335:10)
at Object.<anonymous> (/home/mascs/node_modules/#serverless/utils/log-reporters/node.js:50:39)
at Object.emit (/home/mascs/api/node_modules/event-emitter/index.js:97:9)
at /home/mascs/api/node_modules/#serverless/utils/lib/log/get-output-reporter.js:17:27
at module.exports (/home/mascs/api/node_modules/serverless/lib/cli/handle-error.js:81:3)
at finalize (/home/mascs/api/node_modules/serverless/scripts/serverless.js:57:41)
at /home/mascs/api/node_modules/serverless/scripts/serverless.js:772:11
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:164:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}
Node.js v17.7.1
Running as sudo doesn't change things, so it doesn't seem to be a permissions issue.
Here is the serverless.yml I am using. Can't see any syntax errors.
service: test-api
frameworkVersion: ">=3.0.0 <4.0.0"
provider:
name: aws
runtime: python3.7
region: eu-west-1
stage: dev
environment:
DYN_TABLE: ${self:provider.stage}-test
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:BatchGetItem
- dynamodb:UpdateItem
- dynamodb:PutItem
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYN_TABLE}"
plugins:
- serverless-python-requirements
- serverless-ignore
package:
individually: false
custom:
pythonRequirements:
dockerizePip: true
slim: true
functions:
lambda-test:
handler: api/main.get
memorySize: 256
timeout: 6
events:
- http:
path: v1/
method: get
cors: true
I am at a bit of a loss here, would appreciate if anyone has any ideas.
Have tried uninstalling and then reinstalling Serverless Framework also but it has made no difference.

How to use github actions bot for testing gradle java

I am trying to implement Github-actions(bot), which runs gradle test when PR has been created.
To assure that my workflow file works as I expected, I explicitly wrote a test method which should cause failure.
#Test
fun thisShouldFail() {
assertEquals(1, 2)
}
When I try testing on my local machine, I get the log below.
> Task :test FAILED
FAILURE: Build failed with an exception.
# More
Above log indicates that there was something wrong in the test codes as I expected it to be.
But then Github actions bot runs this command, the test code result is SUCCESS.
Below is my github workflow yaml file for this action.
name: PullRequestGradleTest
on:
pull_request_target:
types: [labeled]
jobs:
test:
name: GradleTest
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'STAGING')
steps:
- name: checkout
uses: actions/checkout#v2
- name: Setup JDK 1.8
uses: actions/setup-java#v2
with:
java-version: '8'
distribution: 'adopt'
- name: Grant Permissions to gradlew
run: chmod +x gradlew
- name: Test
run: gradle test --tests "*"
- name: Test Success
if: success()
uses: actions/github-script#0.2.0
with:
github-token: ${{ github.token }}
script: |
const pull_number = "${{github.event.number}}"
await github.pulls.createReview({
...context.repo,
pull_number,
body: "All tests passed.",
event: "APPROVE"
})
- name: Test Fail
if: failure()
uses: actions/github-script#0.2.0
with:
github-token: ${{ github.token }}
script: |
const pull_number = "${{github.event.number}}"
await github.pulls.createReview({
...context.repo,
pull_number,
body: "There is something wrong with test codes.",
event: "REQUEST_CHANGES"
})
await github.pulls.update({
...context.repo,
pull_number,
state: "closed"
})
I found that you are using gradle, not gradlew.
name: PullRequestGradleTest
on:
pull_request_target:
types: [labeled]
jobs:
test:
name: GradleTest
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'STAGING')
steps:
- name: checkout
uses: actions/checkout#v2
- name: Setup JDK 1.8
uses: actions/setup-java#v2
with:
java-version: '8'
distribution: 'adopt'
- name: Grant Permissions to gradlew
run: chmod +x gradlew
- name: Test
run: ./gradlew test --tests "*"
- name: Test Success
if: success()
uses: actions/github-script#0.2.0
with:
github-token: ${{ github.token }}
script: |
const pull_number = "${{github.event.number}}"
await github.pulls.createReview({
...context.repo,
pull_number,
body: "All tests passed.",
event: "APPROVE"
})
- name: Test Fail
if: failure()
uses: actions/github-script#0.2.0
with:
github-token: ${{ github.token }}
script: |
const pull_number = "${{github.event.number}}"
await github.pulls.createReview({
...context.repo,
pull_number,
body: "There is something wrong with test codes.",
event: "REQUEST_CHANGES"
})
await github.pulls.update({
...context.repo,
pull_number,
state: "closed"
})
If you use gradle in the command, it will depend on the machine's environment. In this case, there is a possibility that occurs error because of Gradle version. Therefore, you need to use the project's Gradle which is included with your repo. The way to use is using gradlew scripts.
I also recommend following these three steps to test the branch for the pull request.
Clean -> Assemble(or build) -> Test
Base problem was that if we use pull_request_target event, the action runs on the target branch, which would be the base branch that the PR will be merged into. To solve this problem, I had to explicitly set where this action will run on.
On job => steps
steps:
- name: checkout
uses: actions/checkout#v2
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{github.event.pull_request.head.repo.full_name }}