Skip to content
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
17 changes: 11 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"env": {
"browser": true,
"es2021": true
"es2021": true,
"jest": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:prettier/recommended"
],
"overrides": [
],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
Expand All @@ -19,7 +19,12 @@
"plugins": [
"@typescript-eslint"
],
"rules": {
},
"ignorePatterns": ["cypress", "examples", "tutorial", "src/plugins/spectrogram*", "scripts"]
"rules": {},
"ignorePatterns": [
"cypress",
"examples",
"tutorial",
"src/plugins/spectrogram*",
"scripts"
]
}
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@
"author": "katspaugh",
"license": "BSD-3-Clause",
"peerDependencies": {
"react": "^18.2.0",
"wavesurfer.js": ">=7.7.14"
"react": "^19.0.0",
"wavesurfer.js": ">=7.8.11"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.2",
"@testing-library/react": "^14.1.2",
"@types/jest": "^29.5.11",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.1.0",
"@types/jest": "^29.5.14",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
Comment on lines +49 to +50
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it said i need to explicitly add these

"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"eslint": "^8.37.0",
Expand All @@ -53,12 +56,12 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "^2.8.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"rollup": "^3.26.2",
"rollup-plugin-inject-process-env": "^1.3.1",
"typescript": "^5.0.4",
"wavesurfer.js": "^7.8.1"
"wavesurfer.js": "^7.8.11"
Copy link
Contributor Author

@dereckquock dereckquock Dec 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i went ahead an updated this as well

},
"jest": {
"transform": {},
Expand Down
6 changes: 3 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type WavesurferProps = PartialWavesurferOptions & OnWavesurferEvents
* Use wavesurfer instance
*/
function useWavesurferInstance(
containerRef: RefObject<HTMLElement>,
containerRef: RefObject<HTMLDivElement | null>,
options: Partial<WaveSurferOptions>,
): WaveSurfer | null {
const [wavesurfer, setWavesurfer] = useState<WaveSurfer | null>(null)
Expand All @@ -43,7 +43,7 @@ function useWavesurferInstance(

// Create a wavesurfer instance
useEffect(() => {
if (!containerRef.current) return
if (!containerRef?.current) return

const ws = WaveSurfer.create({
...options,
Expand Down Expand Up @@ -217,7 +217,7 @@ export default WavesurferPlayer
export function useWavesurfer({
container,
...options
}: Omit<WaveSurferOptions, 'container'> & { container: RefObject<HTMLElement> }): ReturnType<
}: Omit<WaveSurferOptions, 'container'> & { container: RefObject<HTMLDivElement | null> }): ReturnType<
typeof useWavesurferState
> & {
wavesurfer: ReturnType<typeof useWavesurferInstance>
Expand Down
13 changes: 12 additions & 1 deletion tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@ describe('@wavesurfer/react tests', () => {
this.emit('ready')
}

MockWaveSurfer.prototype.destroy = function () {}
MockWaveSurfer.prototype.destroy = function () {
this.listeners = {}
}

return new MockWaveSurfer(...args)
})
})

it('should properly cleanup on unmount', () => {
const { unmount } = render(React.createElement(WavesurferPlayer, { waveColor: 'purple' }))
const mockInstance = WaveSurfer.create.mock.results[0].value
const destroySpy = jest.spyOn(mockInstance, 'destroy')

unmount()
expect(destroySpy).toHaveBeenCalled()
})

it('should render wavesurfer with basic options', () => {
const props = { waveColor: 'purple' }

Expand Down
Loading
Loading