---
format_version: '3'
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: other
workflows:
  fructose-tests:
    steps:
    - script@1.1.4:
        title: build app
        inputs:
        - content: |-
            #!/bin/bash
            NODE_VERSION=stable
            curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
            export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
            export NVM_DIR=~/.nvm
            nvm install stable
            nvm use stable
            npm install --global yarn@1.1.0
            # debug log
            set -x
            rm -rf ios/build
            brew install fontforge
            yarn
            yarn ios -- --simulator "iPhone 7"
            kill -9 $(lsof -ti :8081)
            echo 'should exit with 0'
    - script@1.1.4:
        title: run fructose tests
        inputs:
        - content: |-
            #!/bin/bash
            # fail if any commands fails
            set -e
            
            # set up nvm 
            export NVM_DIR="$HOME/.nvm" && [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
            export NVM_DIR=~/.nvm
            nvm use stable

            # debug log
            set -x
            #iOS setup
            # install fbsimctl
            export CODE_SIGNING_REQUIRED=NO
            git clone https://github.com/facebook/FBSimulatorControl.git
            cd FBSimulatorControl
            git checkout 4a3a339ca325ae2ac0b34fef92605204b79e0c09
            ./build.sh fbsimctl build output
            PATH=$PATH:$(pwd)/output/bin
            cd ..
            # install applesmutils
            brew tap wix/brew
            brew install applesimutils --HEAD
            # set device scale
            defaults write ~/Library/Preferences/com.apple.iphonesimulator SimulatorWindowLastScale-com.apple.CoreSimulator.SimDeviceType.iPhone-7 "0.55" 
            #web setup
            brew tap caskroom/cask
            brew cask install google-chrome
            # tests
            yarn functional-test:ios
            yarn functional-test:web
    - script@1.1.4:
        title: screenshot of desktop
        inputs:
        - content: |-
            #!/bin/bash
            # fail if any commands fails
            set -e
            # debug log
            set -x
            screencapture -P $BITRISE_DEPLOY_DIR/bitrise_screen.png
        is_always_run: true
    - deploy-to-bitrise-io@1.3.6: {}

