diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 0000000..238ed1f --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,65 @@ +# This workflow installs saltcorn from npm and runs the plugin tests. + +name: Node.js CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 25 + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + POSTGRES_DB: saltcorn_test + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: "22.x" + - run: npm install -g @saltcorn/cli@1.3.1-beta.11 + env: + CI: true + PGHOST: localhost + PGUSER: postgres + PGDATABASE: saltcorn_test + PGPASSWORD: postgres + - run: saltcorn info + env: + CI: true + PGHOST: localhost + PGUSER: postgres + PGDATABASE: saltcorn_test + PGPASSWORD: postgres + - run: saltcorn add-schema -f + env: + CI: true + PGHOST: localhost + PGUSER: postgres + PGDATABASE: saltcorn_test + PGPASSWORD: postgres + - run: saltcorn dev:plugin-test -d $PWD -f backup.zip + env: + CI: true + PGHOST: localhost + PGUSER: postgres + PGDATABASE: saltcorn_test + PGPASSWORD: postgres diff --git a/package.json b/package.json index fc56be6..d8da964 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build_view_dev": "webpack --mode development --config user-code/webpack.config.js", "build_main": "webpack --mode production --config main-code/webpack.config.js", "build_main_dev": "webpack --mode development --config main-code/webpack.config.js", - "eslint": "eslint ./app-code" + "eslint": "eslint ./app-code", + "test": "jest tests --runInBand" }, "dependencies": { "@saltcorn/markup": "^0.2.0", @@ -29,6 +30,9 @@ "style-loader": "4.0.0", "css-loader": "7.1.2" }, + "devDependencies": { + "jest": "^29.7.0" + }, "author": "Christian Hugo", "license": "MIT", "repository": "github:saltcorn/react", diff --git a/tests/backup.zip b/tests/backup.zip new file mode 100644 index 0000000..b9df466 Binary files /dev/null and b/tests/backup.zip differ diff --git a/tests/build.test.js b/tests/build.test.js new file mode 100644 index 0000000..38adc59 --- /dev/null +++ b/tests/build.test.js @@ -0,0 +1,37 @@ +const { getState } = require("@saltcorn/data/db/state"); +const View = require("@saltcorn/data/models/view"); +const { mockReqRes } = require("@saltcorn/data/tests/mocks"); +const { afterAll, beforeAll, describe, it, expect } = require("@jest/globals"); + +getState().registerPlugin("base", require("@saltcorn/data/base-plugin")); +getState().registerPlugin("@saltcorn/react", require("..")); + +afterAll(require("@saltcorn/data/db").close); +beforeAll(async () => { + await getState().refresh(true); +}); + +describe("react view build tests", () => { + it("run tableless view", async () => { + const view = View.findOne({ name: "empty_react_view" }); + const body = { + user_code: ` +import React from "react"; +export default function App({ viewName, query }) { + return