Skip to content

Commit

Permalink
Add tests for browser
Browse files Browse the repository at this point in the history
  • Loading branch information
GhostWalker562 committed Nov 11, 2024
1 parent 932ed12 commit d630410
Show file tree
Hide file tree
Showing 8 changed files with 1,526 additions and 845 deletions.
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

0 comments on commit d630410

Please sign in to comment.