Skip to content

Commit

Permalink
devops: added buildbot to test Lambda on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Mar 31, 2021
1 parent d93ee40 commit 913e66f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 12.x
- name: Install dependencies
run: npm install
- name: Build project
run: npm run build
- name: Test lambda function
run: bash buildbots/stub.sh
27 changes: 27 additions & 0 deletions buildbots/puppeteer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const chromium = require('../build/');

exports.handler = async (event, context) => {
let browser = null;

try {
const browser = await chromium.puppeteer.launch({
executablePath: await chromium.executablePath,
defaultViewport: chromium.defaultViewport,
args: chromium.args,
});

const page = await browser.newPage();
await page.goto(event.url);
const data = await page.screenshot();
if (data.length === 0) {
throw new Error(`Screenshot is empty`);
}
console.log('Page title: ', await page.title());
} catch (error) {
throw error;
} finally {
if (browser !== null) {
await browser.close();
}
}
};
12 changes: 12 additions & 0 deletions buildbots/stub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#/bin/bash

set -e

LOG_FILE="log.txt"

echo "Running Puppeteer lambda function"
docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:nodejs12.x buildbots/puppeteer.handler '{"url": "https://example.com"}' &> "$LOG_FILE"
grep -Fq "Example Domain" "$LOG_FILE"
echo "Sucessfully passed Puppeteer test"

rm "$LOG_FILE"

0 comments on commit 913e66f

Please sign in to comment.