Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: lint, typecheck and test code #246

Merged
merged 6 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('jest').Config} */
module.exports = {
projects: ["<rootDir>/packages/frames.js/jest.config.js"],
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -36,4 +38,4 @@
"packages/*"
],
"version": "0.3.0-canary.0"
}
}
1 change: 1 addition & 0 deletions packages/frames.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
68 changes: 61 additions & 7 deletions packages/frames.js/src/next/getCurrentUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
/* 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({
url: "/test",
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", () => {
Expand All @@ -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");
});
});
27 changes: 27 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading