Skip to content

Commit 6fb9161

Browse files
authored
ci: added buildbot for basic testing (#17)
1 parent 537234f commit 6fb9161

File tree

9 files changed

+2612
-1951
lines changed

9 files changed

+2612
-1951
lines changed

.github/workflows/tests.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [ master ]
5+
pull_request:
6+
branches: [ master ]
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Use Node.js
13+
uses: actions/setup-node@v1
14+
with:
15+
node-version: 10.x
16+
- name: Install dependencies
17+
run: yarn install --frozen-lockfile
18+
- name: Lint
19+
run: yarn run lint
20+
- name: Build project
21+
run: yarn run build
22+
- name: Test lambda function
23+
run: bash buildbots/stub.sh

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
node_modules
22
coverage
33
dist
4-
yarn-error.log
4+
yarn-error.log
5+
log.txt
6+
package-lock.json

.lintstagedrc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
{
2-
"linters": {
3-
"*.ts": [
2+
"*.{md,js,ts,json}": [
43
"prettier --write",
5-
"git add"
6-
],
7-
"*.{md,js,json}": [
8-
"prettier --write",
9-
"git add"
104
]
11-
},
12-
"ignore": []
135
}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Lambda runtimes out of the box.
1919
const playwright = require('playwright-aws-lambda');
2020

2121
exports.handler = async (event, context) => {
22-
let result = null;
2322
let browser = null;
2423

2524
try {
@@ -33,7 +32,7 @@ exports.handler = async (event, context) => {
3332
} catch (error) {
3433
throw error;
3534
} finally {
36-
if (browser !== null) {
35+
if (browser) {
3736
await browser.close();
3837
}
3938
}

buildbots/stub.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#/bin/bash
2+
3+
set -ex
4+
5+
LOG_FILE="log.txt"
6+
7+
echo "Running lambda function"
8+
docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:nodejs12.x examples/stub.handler '{"url": "https://google.com"}' &> "$LOG_FILE"
9+
grep -Fq "Google" "$LOG_FILE"
10+
echo "Sucessfully passed test"
11+
rm "$LOG_FILE"

examples/stub.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const playwright = require('../dist/src/');
2+
3+
exports.handler = async (event, context) => {
4+
let browser = null;
5+
6+
try {
7+
const browser = await playwright.launchChromium();
8+
const context = await browser.newContext();
9+
10+
const page = await context.newPage();
11+
await page.goto(event.url || 'https://example.com');
12+
const data = await page.screenshot();
13+
if (data.length === 0) {
14+
throw new Error(`Screenshot is empty`);
15+
}
16+
console.log('Page title: ', await page.title());
17+
} catch (error) {
18+
throw error;
19+
} finally {
20+
if (browser !== null) {
21+
await browser.close();
22+
}
23+
}
24+
};

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
},
3030
"devDependencies": {
3131
"@types/debug": "^4.1.5",
32-
"@types/jest": "^24.0.18",
33-
"@types/node": "~10",
34-
"husky": "^3.0.5",
35-
"jest": "^24.9.0",
36-
"lint-staged": "8.2.1",
37-
"nodemon": "^1.19.4",
38-
"playwright-core": "^1.0.2",
39-
"prettier": "^1.18.2",
40-
"ts-jest": "^24.0.2",
41-
"tslint": "^5.20.1",
32+
"@types/jest": "^26.0.9",
33+
"@types/node": "~14",
34+
"husky": "^4.2.5",
35+
"jest": "^26.3.0",
36+
"lint-staged": "10.2.11",
37+
"nodemon": "^2.0.4",
38+
"playwright-core": "^1.3.0",
39+
"prettier": "^2.0.5",
40+
"ts-jest": "^26.2.0",
41+
"tslint": "^6.1.3",
4242
"tslint-config-prettier": "^1.18.0",
43-
"typescript": "^3.6.3"
43+
"typescript": "^3.9.7"
4444
}
4545
}

tslint.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"interface-name": false,
55
"object-literal-sort-keys": false,
66
"ordered-imports": false,
7-
"no-unused-variable": true,
87
"quotemark": [true, "single", "avoid-escape"]
98
}
109
}

0 commit comments

Comments
 (0)