2019-04-12 14:37:47 +00:00
|
|
|
import { expect } from "chai";
|
2019-07-23 17:12:41 +00:00
|
|
|
import "Tone/core/clock/Transport";
|
2019-07-23 17:51:22 +00:00
|
|
|
import "Tone/core/context/Destination";
|
2019-05-23 18:00:49 +00:00
|
|
|
import { OfflineContext } from "Tone/core/context/OfflineContext";
|
|
|
|
import { ToneWithContext } from "Tone/core/context/ToneWithContext";
|
|
|
|
import { Tone } from "Tone/core/Tone";
|
2019-08-04 14:07:19 +00:00
|
|
|
import { ConnectTest } from "./Connect";
|
2019-04-12 14:37:47 +00:00
|
|
|
|
2019-05-23 18:00:49 +00:00
|
|
|
export const testAudioContext = new OfflineContext(1, 1, 11025);
|
2019-06-23 18:59:49 +00:00
|
|
|
testAudioContext.initialize();
|
2019-04-12 14:37:47 +00:00
|
|
|
|
2019-06-23 10:53:57 +00:00
|
|
|
// tslint:disable-next-line
|
2019-05-23 18:00:49 +00:00
|
|
|
export function BasicTests(Constr, ...args: any[]): void {
|
2019-04-12 14:37:47 +00:00
|
|
|
|
|
|
|
context("Basic", () => {
|
|
|
|
|
|
|
|
it("can be created and disposed", () => {
|
|
|
|
const instance = new Constr(...args);
|
|
|
|
instance.dispose();
|
2019-07-23 16:12:11 +00:00
|
|
|
// check that all of the attributes were disposed
|
|
|
|
expect(instance.disposed).to.equal(true);
|
|
|
|
// also check all of it's attributes to see if they also have the right context
|
|
|
|
for (const member in instance) {
|
|
|
|
if (instance[member] instanceof Tone && member !== "context") {
|
|
|
|
expect(instance[member].disposed, `member ${member}`).to.equal(true);
|
|
|
|
}
|
|
|
|
}
|
2019-04-12 14:37:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("extends Tone", () => {
|
|
|
|
const instance = new Constr(...args);
|
|
|
|
expect(instance).to.be.an.instanceof(Tone);
|
|
|
|
instance.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("can specify the AudioContext", () => {
|
|
|
|
const instance = new Constr(Object.assign({
|
|
|
|
context: testAudioContext,
|
|
|
|
}, ...args));
|
2019-05-23 18:00:49 +00:00
|
|
|
if (instance instanceof ToneWithContext) {
|
2019-04-12 14:37:47 +00:00
|
|
|
expect(instance.context).to.equal(testAudioContext);
|
|
|
|
// also check all of it's attributes to see if they also have the right context
|
|
|
|
for (const member in instance) {
|
2019-05-23 18:00:49 +00:00
|
|
|
if (instance[member] instanceof ToneWithContext) {
|
2019-07-18 18:04:39 +00:00
|
|
|
expect(instance[member].context, `member: ${member}`).to.equal(testAudioContext);
|
2019-04-12 14:37:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
instance.dispose();
|
|
|
|
});
|
2019-08-04 14:07:19 +00:00
|
|
|
|
|
|
|
ConnectTest(Constr, ...args);
|
2019-04-12 14:37:47 +00:00
|
|
|
});
|
|
|
|
}
|