Karma tests, PhantomJS error: Could not find module 'events'
Well, according to an answer to a similar question on SO it's not possible to do so on purpose.
Karma is a test runner for testing frontend code only. That's how it was designed. Therefore, you cannot require any node internal library without using weird workarounds.
If you'd like to test the backend code, go ahead and use e.g. Mocha and Chai instead of Karma and Jasmine. Moving to this libraries wasn't very painful and I can totally recommend doing so.
Moreover, this article provides good introduction on how to use Mocha with TypeScript so I suggest reading it first.
phantomjs: command not found
The PATH
really is the important part. You can skip it, however, if you specify the absolute path. Try something like this:
/path/to/phantomjs render_image.js
...but that can get tiring. For a quick way to add it to your PATH
, from the directory of the phantomjs
executable, symbolically link it into /usr/local/bin
:
sudo ln -s /path/to/phantomjs /usr/local/bin/
/usr/local/bin
is likely on your PATH
.
PhantomJS not found on Shiny Server
First, install the webshot
package from the terminal on the Ubuntu server:
sudo su - -c "R -e \"install.packages('webshot')\""
Next, follow the installation description of phantomJS
:
sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev -y
sudo apt-get install libfreetype6 libfreetype6-dev -y
sudo apt-get install libfontconfig1 libfontconfig1-dev -y
cd ~
export PHANTOM_JS="phantomjs-2.1.1-linux-x86_64"
wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2
sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
phantomjs --version
With this, you should be able use webshot
and phantomJS
with a Shiny App.
I have tested it with a small sample test app, which I added to /srv/shiny-server/
:
the ui.R
looks like this:
library(shiny)
ui <- fluidPage(
# App title ----
titlePanel("Test App to display webshot"),
# Sidebar layout
sidebarLayout(
sidebarPanel(
#actually useless part
),
# Main panel for displaying outputs ----
mainPanel(
# Output: screenshot ----
imageOutput("webshot_image")
)
)
)
the server.R
looks like this:
library(shiny)
server <- function(input, output) {
output$webshot_image <- renderImage({
# A temp file to save the output.
# This file will be removed later by renderImage
outfile <- tempfile(fileext = '.png')
# Generate the PNG
webshot::webshot(url = "https://github.com/rstudio/shiny",
file = outfile)
# Return a list containing the filename
list(src = outfile,
contentType = 'image/png',
width = 400,
height = 300,
alt = "This is alternate text")
}, deleteFile = TRUE)
}
The final result is this:
Github Actions - R package R-CMD-Check PhantomJS not found
The easy solution will be to go to the project where there is used PhantomJS and the Github Actions is turned on. We will go to shiny
project and precisely to:
https://github.com/rstudio/shiny/blob/master/.github/workflows/R-CMD-check.yaml
We could find out there that:
- name: Install system dependencies
if: runner.os == 'Linux'
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}
- name: Find PhantomJS path
id: phantomjs
run: |
echo "::set-output name=path::$(Rscript -e 'cat(shinytest:::phantom_paths()[[1]])')"
- name: Cache PhantomJS
uses: actions/cache@v1
with:
path: ${{ steps.phantomjs.outputs.path }}
key: ${{ runner.os }}-phantomjs
restore-keys: ${{ runner.os }}-phantomjs
- name: Install PhantomJS
run: >
Rscript
-e "if (!shinytest::dependenciesInstalled()) shinytest::installDependencies()"
We easily could check that there is separate chunk of code only to be sure that PhantomJS localization is known or if it should be installed.
You could paste this part of code to your yaml file. However the best way might to be follow the pipeline of shiny
project,
Related Topics
How to Use Activesupport::Configurable with Rails Engine
Rails Initializes Extremely Slow on Ruby 1.9.1
Ruby Conditional-Assignment and Private Methods
How to Update Rails Locale Yaml File Without Loosing Comments and Variables
Alter $Path in Vim/Macvim So as to Find the Right Ruby Binary
Rails Helper - How to Get a Helper to Give Me a '<Br/>' (Or Other Markup)
Undefined Method Respond_To in Rails 5 Controller
Is Subclassing a User Model Really Bad to Do in Rails
How to Run Rake with --Trace Within Capistrano
How to Use Mongodb Ruby Driver to Do a "Group" (Group By)
Sidekiq Worker Not Getting Triggered
Where to Put a Before_Filter Shared Between Multiple Controllers
Commonmarker Gem Cannot Be Installed (Needed for Jekyll) MACos
Get, or Calculate the Entropy of an Image with Ruby and Imagemagick