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

[tests] Add tests for browser environment #568

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions .github/actions/run-tests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,22 @@ runs:
shell: bash
if: failure()
run: cat ${{ runner.temp }}/local-testnet-logs.txt

# Run the TS SDK tests for browser
- uses: nick-fields/retry@7f8f3d9f0f62fe5925341be21c2e8314fd4f7c7c # pin@v2
name: sdk-pnpm-test-browswer
env:
# This is important, it ensures that the tempdir we create for cloning the ANS
# repo and mounting it into the CLI container is created in a location that
# actually supports mounting. Learn more here: https://stackoverflow.com/a/76523941/3846032.
TMPDIR: ${{ runner.temp }}
with:
max_attempts: 3
timeout_minutes: 25
# This runs all the tests, both unit and e2e.
command: pnpm run test:browser

- name: Print local testnet logs on failure
shell: bash
if: failure()
run: cat ${{ runner.temp }}/local-testnet-logs.txt
8 changes: 5 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/** @type {import("ts-jest/dist/types").InitialOptionsTsJest} */
const isBrowserEnvironment = process.env.BROWSER_ENV === "1";

/** @type {import("ts-jest").JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
testEnvironment: "node",
testEnvironment: isBrowserEnvironment ? "jsdom" : "node",
coveragePathIgnorePatterns: [
"./src/internal/queries/",
"./src/types/generated",
"./tests/e2e/ans/publishANSContracts.ts",
],
testPathIgnorePatterns: ["dist/*", "examples/*"],
collectCoverage: true,
setupFiles: ["dotenv/config"],
setupFiles: ["dotenv/config", ...(isBrowserEnvironment ? ["./tests/setupBrowser.js"] : [])],
coverageThreshold: {
global: {
branches: 50, // 90,
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"fmt": "pnpm _fmt --write",
"lint": "eslint 'src/**/*.ts' 'tests/**/*.ts' 'examples/**/*.ts'",
"test": "pnpm jest",
"test:browser": "BROWSER_ENV=1 pnpm jest",
"unit-test": "pnpm jest tests/unit",
"e2e-test": "pnpm jest tests/e2e",
"indexer-codegen": "graphql-codegen --config ./src/types/codegen.yaml && pnpm fmt",
Expand Down Expand Up @@ -86,6 +87,7 @@
"graphql": "^16.9.0",
"graphql-request": "^6.1.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jsonwebtoken": "^9.0.2",
"prettier": "^3.3.3",
"tree-kill": "^1.2.2",
Expand All @@ -95,7 +97,9 @@
"tsup": "^8.3.0",
"typedoc": "^0.26.8",
"typedoc-plugin-missing-exports": "^3.0.0",
"typescript": "^5.6.2"
"typescript": "^5.6.2",
"whatwg-fetch": "^3.6.20",
"xhr2": "^0.2.1"
},
"version": "1.31.0"
}
Loading
Loading