From 6c2ade4b57d6bd1101736eeaf55c4a63ae6c1aab Mon Sep 17 00:00:00 2001 From: Nick Pleatsikas Date: Sat, 6 Jul 2024 19:03:01 -0700 Subject: [PATCH] Added automatic test workflow. - Added actions workflow to run unit tests, rebuild and run the action. - Added example flyscrape script for testing. --- .github/workflows/test.yml | 33 +++++++++++++++++++++++++++++++++ examples/script.js | 18 ++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 examples/script.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c20995b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: tests +on: + push: + paths: + - .github/workflows/test.yml + - __tests__/*.ts + - src/*.ts + - package.json + - package-lock.json +jobs: + unit-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: "20" + - run: npm ci + - run: npm test + build-and-run-action: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: "20" + - run: npm ci + - run: npm run build + - uses: ./ + id: run-action + with: + script: examples/script.js + - run: 'echo "${{ steps.run-action.outputs.output }}" | jq' diff --git a/examples/script.js b/examples/script.js new file mode 100644 index 0000000..b7dd1b2 --- /dev/null +++ b/examples/script.js @@ -0,0 +1,18 @@ +// A sample flyscrape script. + +export const config = { + url: "https://example.com", +}; + +export default function ({ doc, _ }) { + const links = doc.find("a"); + + return { + urls: links.map((link) => { + return { + name: link.text(), + url: link.attr("href"), + }; + }), + }; +}