diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml new file mode 100644 index 000000000..a222df854 --- /dev/null +++ b/.github/workflows/github-actions.yml @@ -0,0 +1,87 @@ +name: Frames.js Actions + +on: + push: + branches: + - main + - dev + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + initialize: + timeout-minutes: 5 + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "yarn" + + - name: Install dependencies + run: yarn --frozen-lockfile + + lint: + needs: [initialize] + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "yarn" + + - name: Install dependencies + run: yarn --frozen-lockfile + + - name: Lint + run: yarn lint + + typecheck: + needs: [initialize] + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "yarn" + + - name: Install dependencies + run: yarn --frozen-lockfile + + - name: Typecheck + run: yarn build:ci + + test: + needs: [lint, typecheck] + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "yarn" + + - name: Install dependencies + run: yarn --frozen-lockfile + + - name: Unit Tests + run: yarn test:ci diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 000000000..47413007a --- /dev/null +++ b/jest.config.js @@ -0,0 +1,4 @@ +/** @type {import('jest').Config} */ +module.exports = { + projects: ["/packages/frames.js/jest.config.js"], +}; diff --git a/package.json b/package.json index 0509b1517..bb93324a6 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,13 @@ "private": true, "scripts": { "build": "turbo build", + "build:ci": "turbo build --filter=!debugger --filter=!framesjs-starter --filter=!utils-starter --filter=!docs", "dev": "FJS_MONOREPO=true turbo dev --filter=framesjs-starter... --filter=debugger...", "dev:custom-redirects": "turbo dev --filter=custom-redirects...", "dev:utils-starter": "turbo dev --filter=utils-starter...", "dev:all": "turbo dev", "lint": "turbo lint", + "test:ci": "jest --ci", "test": "cd ./packages/frames.js && npm run test:watch", "publish-packages": "turbo run build lint && changeset version && changeset publish && git push --follow-tags origin main", "publish-canary": "turbo run build lint && cd ./packages/frames.js && yarn publish --tag canary && git push --follow-tags origin main", @@ -36,4 +38,4 @@ "packages/*" ], "version": "0.3.0-canary.0" -} \ No newline at end of file +} diff --git a/packages/frames.js/package.json b/packages/frames.js/package.json index d7dbd53c7..a7a5b1ff5 100644 --- a/packages/frames.js/package.json +++ b/packages/frames.js/package.json @@ -212,6 +212,7 @@ "devDependencies": { "@open-frames/types": "^0.0.6", "@remix-run/node": "^2.8.1", + "@types/supertest": "^6.0.2", "@types/express": "^4.17.21", "@xmtp/frames-client": "^0.4.3", "@xmtp/frames-validator": "^0.5.2", diff --git a/packages/frames.js/src/next/getCurrentUrl.test.ts b/packages/frames.js/src/next/getCurrentUrl.test.ts index a91f125ac..dd1008692 100644 --- a/packages/frames.js/src/next/getCurrentUrl.test.ts +++ b/packages/frames.js/src/next/getCurrentUrl.test.ts @@ -1,6 +1,17 @@ +/* eslint-disable turbo/no-undeclared-env-vars */ import { getCurrentUrl } from "./getCurrentUrl"; describe("getCurrentUrl", () => { + beforeEach(() => { + // @ts-expect-error + process.env.NODE_ENV = "test"; + }); + + afterEach(() => { + delete process.env.VERCEL_URL; + delete process.env.APP_URL; + }); + it("works with relative url property", () => { expect( getCurrentUrl({ @@ -8,8 +19,8 @@ describe("getCurrentUrl", () => { headers: { host: "localhost", }, - } as unknown as Request) - ).toEqual(new URL("http://localhost/test")); + } as unknown as Request)?.toString() + ).toEqual("http://localhost/test"); }); it("takes value from process.env.VERCEL_URL if available", () => { @@ -21,13 +32,56 @@ describe("getCurrentUrl", () => { headers: { host: "localhost", }, - } as unknown as Request) - ).toEqual(new URL("http://test.com/")); + } as unknown as Request)?.toString() + ).toEqual("http://test.com/test"); + }); + + it("takes value from process.env.VERCEL_URL and uses https if NODE_ENV=production if available", () => { + process.env.VERCEL_URL = "test.com"; + // @ts-expect-error + process.env.NODE_ENV = "production"; + + expect( + getCurrentUrl({ + url: "/test", + headers: { + host: "localhost", + }, + } as unknown as Request)?.toString() + ).toEqual("https://test.com/test"); + }); + + it("takes value from process.env.APP_URL if available", () => { + process.env.APP_URL = "app.com"; + + expect( + getCurrentUrl({ + url: "/test", + headers: { + host: "localhost", + }, + } as unknown as Request)?.toString() + ).toEqual("http://app.com/test"); + }); + + it("takes value from process.env.APP_URL and uses https if NODE_ENV=production if available", () => { + process.env.APP_URL = "test.com"; + // @ts-expect-error + process.env.NODE_ENV = "production"; + + expect( + getCurrentUrl({ + url: "/test", + headers: { + host: "localhost", + }, + } as unknown as Request)?.toString() + ).toEqual("https://test.com/test"); }); it("supports proper url in Request object", () => { - expect(getCurrentUrl(new Request("http://localhost/test"))).toEqual( - new URL("http://localhost/test") - ); + expect( + getCurrentUrl(new Request("http://localhost/test"))?.toString() + ).toEqual("http://localhost/test"); }); }); diff --git a/yarn.lock b/yarn.lock index cbe58a918..1782f060c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2943,6 +2943,11 @@ resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5" integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA== +"@types/cookiejar@^2.1.5": + version "2.1.5" + resolved "https://registry.yarnpkg.com/@types/cookiejar/-/cookiejar-2.1.5.tgz#14a3e83fa641beb169a2dd8422d91c3c345a9a78" + integrity sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q== + "@types/debug@^4.0.0", "@types/debug@^4.1.7": version "4.1.12" resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.12.tgz#a155f21690871953410df4b6b6f53187f0500917" @@ -3080,6 +3085,11 @@ resolved "https://registry.yarnpkg.com/@types/mdx/-/mdx-2.0.11.tgz#21f4c166ed0e0a3a733869ba04cd8daea9834b8e" integrity sha512-HM5bwOaIQJIQbAYfax35HCKxx7a3KrK3nBtIqJgSOitivTD1y3oW9P3rxY9RkXYPUk7y/AjAohfHKmFpGE79zw== +"@types/methods@^1.1.4": + version "1.1.4" + resolved "https://registry.yarnpkg.com/@types/methods/-/methods-1.1.4.tgz#d3b7ac30ac47c91054ea951ce9eed07b1051e547" + integrity sha512-ymXWVrDiCxTBE3+RIrrP533E70eA+9qu7zdWoHuOmGujkYtzf4HQF96b8nwHLqhuf4ykX61IGRIB38CC6/sImQ== + "@types/mime@*": version "3.0.4" resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.4.tgz#2198ac274de6017b44d941e00261d5bc6a0e0a45" @@ -3199,6 +3209,23 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8" integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw== +"@types/superagent@^8.1.0": + version "8.1.6" + resolved "https://registry.yarnpkg.com/@types/superagent/-/superagent-8.1.6.tgz#e660543b1a4b7c7473caec4799de87ff68216270" + integrity sha512-yzBOv+6meEHSzV2NThYYOA6RtqvPr3Hbob9ZLp3i07SH27CrYVfm8CrF7ydTmidtelsFiKx2I4gZAiAOamGgvQ== + dependencies: + "@types/cookiejar" "^2.1.5" + "@types/methods" "^1.1.4" + "@types/node" "*" + +"@types/supertest@^6.0.2": + version "6.0.2" + resolved "https://registry.yarnpkg.com/@types/supertest/-/supertest-6.0.2.tgz#2af1c466456aaf82c7c6106c6b5cbd73a5e86588" + integrity sha512-137ypx2lk/wTQbW6An6safu9hXmajAifU/s7szAHLN/FeIm5w7yR0Wkl9fdJMRSHwOn4HLAI0DaB2TOORuhPDg== + dependencies: + "@types/methods" "^1.1.4" + "@types/superagent" "^8.1.0" + "@types/trusted-types@^2.0.2": version "2.0.7" resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.7.tgz#baccb07a970b91707df3a3e8ba6896c57ead2d11"