LayerCI is a continuous integration platform that creates new virtual machines after every code change, allowing you to easily run your tests against a change without having to deploy it to a staging environment or manually trigger your tests.
We’ll walk through a basic example of how you can run your app in LayerCI and then trigger a Ghost Inspector suite to run against the app.
Table of Contents
Run your app
If you’re currently using LayerCI you probably already have a Layerfile, but if not, this is a simple example of what running a Node.js app might look like.
FROM vm/ubuntu:18.04 # Install Node.js 14.x RUN curl -sL https://deb.nodesource.com/setup_14.x | bash RUN apt install nodejs # Copy files from your repository to the LayerCI runner COPY . . # Start your app on port 3000 RUN BACKGROUND npm start --port 3000 EXPOSE WEBSITE http://localhost:3000
Note that the last line is using LayerCI’s
EXPOSE WEBSITE command. This command creates a persistent URL for the local instance of your web app and stores it in the
$EXPOSE_WEBSITE_URL environment variable. We’ll use variable below as the "Start URL" for our Ghost Inspector test suite.
Store your Ghost Inspector API key
Use LayerCI’s secrets manager in their web app to store your Ghost Inspector API key and make it available in the virtual machine.
Trigger a suite
npx command that comes with Node.js you can run a command using the Ghost Inspector CLI without having to install it first.
By default the Ghost Inspector CLI will exit successfully even if a suite or test fails, but you can use the
--errorOnFail flag to exit unsuccessfully and fail the build.
# Expose the API key as an environment variable to the LayerCI runner SECRET ENV GHOST_INSPECTOR_API_KEY # Run your Ghost Inspector suite # Replace <suite ID> with the appropriate Ghost Inspector suite ID RUN npx ghost-inspector suite execute <suite-id> \ --apiKey=$GHOST_INSPECTOR_API_KEY \ --startUrl=$EXPOSE_WEBSITE_URL \ --errorOnFail
If the suite run fails it will fail the whole build and LayerCI will send you a notification via email letting you know.
Ghost Inspector will also send you notifications with specific details about what went wrong if you have them configured.
If you’d rather not receive Ghost Inspector notifications when running tests via LayerCI you can disable them for that run using the
RUN npx ghost-inspector suite execute <suite-id> \ --apiKey=$GHOST_INSPECTOR_API_KEY \ --startUrl=$EXPOSE_WEBSITE_URL \ --errorOnFail \ --disableNotifications