Skip to content

Commit

Permalink
Merge pull request #115 from mattyg/build/fix-tests-replace-jest
Browse files Browse the repository at this point in the history
Fix test runner setup and fix failing tests
  • Loading branch information
robbiecarlton authored Mar 26, 2024
2 parents 8aa0d00 + 685b643 commit 467a989
Show file tree
Hide file tree
Showing 8 changed files with 682 additions and 1,951 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## Changed
- Replace jest with vitest

## Fixed
- Test suite now runs properly
- Mocking browser globals in tests
- Failing tests

## [0.6.18-prerelease] - 2023-11-1
### Changed
- bumped comb version to 0.3.2
Expand Down
6 changes: 0 additions & 6 deletions jest.config.js

This file was deleted.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"build": "npm run bundle",
"bundle": "npx webpack --mode production --output-filename holo_hosting_web_sdk.js",
"test": "yarn jest",
"test": "npx vitest",
"prepublish": "npm run build"
},
"author": "Holo Ltd.",
Expand All @@ -34,18 +34,15 @@
"@babel/preset-env": "^7.9.5",
"@babel/preset-typescript": "^7.21.0",
"@holo-host/chaperone": "^8.0.1",
"@jest/globals": "^29.4.3",
"@types/jest": "^29.4.0",
"@types/node": "^12.20.55",
"@whi/stdlog": "^0.3.0",
"babel-loader": "^8.1.0",
"babel-polyfill": "^6.26.0",
"jest": "^27.1.3",
"jest-canvas-mock": "^2.4.0",
"jsdom": "^22.1.0",
"puppeteer": "^2.1.1",
"ts-jest": "^27.1.3",
"ts-loader": "^9.4.1",
"typescript": "^4.9.3",
"vitest": "^0.34.6",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class WebSdkApi implements AppAgentClient {
const { agentState, uiState } = chaperone_state

webSdkApi.agentState = agentState
webSdkApi.myPubKey = decodeHashFromBase64(agentState.id)
webSdkApi.myPubKey = agentState ? decodeHashFromBase64(agentState.id) : undefined
webSdkApi.uiState = uiState
webSdkApi.chaperoneState = chaperone_state
webSdkApi.happId = happ_id
Expand Down
15 changes: 8 additions & 7 deletions tests/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import {describe, expect, test} from '@jest/globals';
import {beforeEach, afterEach, expect, describe, it } from 'vitest'

const path = require('path')
const log = require('@whi/stdlog')(path.basename(__filename), {
level: process.env.LOG_LEVEL || 'fatal'
})

require("./mock_browser")
const mock_comb = require("./mock_comb")
import "./mock_browser"
import mock_comb from "./mock_comb"
import WebSdkApi from "../src/index"

let WebSdkApi
WebSdkApi = require("../src/index").default
import { JSDOM } from "jsdom"
const dom = new JSDOM()
global.document = dom.window.document
global.window = dom.window

describe('test API endpoints', () => {
let holo
Expand Down Expand Up @@ -132,8 +135,6 @@ describe("test comb error", () => {
throw new Error(expectedError)
}
}

WebSdkApi = require("../src/index").default
})

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

(<any>global.window) = {
export default (<any>global.window) = {
"location": {
"hostname": "https://localhost",
}
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_comb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let event_listeners = {}
}
}

module.exports = {
export default {
nextResponse(value) {
next_response = value;
},
Expand Down
2,589 changes: 660 additions & 1,929 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 467a989

Please sign in to comment.