-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f13d30
commit ca7fc2d
Showing
4 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Mocha Tests</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" /> | ||
</head> | ||
<body> | ||
<div id="mocha"></div> | ||
|
||
<script src="https://unpkg.com/chai/chai.js"></script> | ||
<script src="https://unpkg.com/mocha/mocha.js"></script> | ||
|
||
<script class="mocha-init"> | ||
mocha.setup('bdd'); | ||
mocha.checkLeaks(); | ||
</script> | ||
|
||
<script src="vfs.js" type="module"></script> | ||
<script class="mocha-exec"> | ||
mocha.run(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import WebRenderer from '../dist/index.js'; | ||
import { el } from '@elemaudio/core'; | ||
|
||
|
||
const audioContext = (typeof window !== 'undefined') && new (window.AudioContext || window.webkitAudioContext)(); | ||
|
||
|
||
describe('Virtual File System', function () { | ||
describe('list', function () { | ||
it('should show registered entries', async function() { | ||
const core = new WebRenderer(); | ||
const node = await core.initialize(audioContext, { | ||
numberOfInputs: 0, | ||
numberOfOutputs: 1, | ||
outputChannelCount: [2], | ||
processorOptions: { | ||
virtualFileSystem: { | ||
'test': Float32Array.from([1, 2, 3, 4, 5]), | ||
}, | ||
}, | ||
}); | ||
|
||
node.connect(audioContext.destination); | ||
chai.assert.deepEqual(await core.listVirtualFileSystem(), ['test']); | ||
|
||
// We haven't rendered anything that holds a reference to the test entry | ||
core.pruneVirtualFileSystem(); | ||
chai.assert.deepEqual(await core.listVirtualFileSystem(), []); | ||
|
||
// Now we put something back in | ||
core.updateVirtualFileSystem({ | ||
'test2': Float32Array.from([2, 3, 4, 5]), | ||
}); | ||
|
||
// After we render something referencing the test2 entry, prune shouldn't touch it | ||
chai.assert.deepEqual(await core.listVirtualFileSystem(), ['test2']); | ||
chai.assert.include(core.render(el.table({key: 'a', path: 'test2'}, 0.5)), { | ||
nodesAdded: 3, | ||
edgesAdded: 2, | ||
propsWritten: 4, | ||
});; | ||
|
||
core.pruneVirtualFileSystem(); | ||
chai.assert.deepEqual(await core.listVirtualFileSystem(), ['test2']); | ||
|
||
// Now we'll put test3 in and remove our reference to test2 | ||
// | ||
// TODO: It's hard to actually test this in an automated fashion in the web context | ||
// because we need the audio context to avoid a suspended state, which it defaults to | ||
// before any user interaction. We need samples flowing through the table node in order | ||
// for it to take/drop its references to resources. Commenting this one out for now. | ||
// | ||
// core.updateVirtualFileSystem({ | ||
// 'test3': Float32Array.from([2, 3, 4]), | ||
// }); | ||
|
||
// chai.assert.include(core.render(el.table({key: 'a', path: 'test3'}, 0.5)), { | ||
// nodesAdded: 0, | ||
// edgesAdded: 0, | ||
// propsWritten: 1, | ||
// });; | ||
|
||
// core.pruneVirtualFileSystem(); | ||
// chai.assert.deepEqual(await core.listVirtualFileSystem(), ['test3']); | ||
|
||
node.disconnect(); | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
optimizeDeps: { | ||
include: ['@elemaudio/core'], | ||
}, | ||
}) |