2024-05-03 18:31:14 +00:00
|
|
|
import * as Tone from "./index.js";
|
2019-10-30 18:48:29 +00:00
|
|
|
import { expect } from "chai";
|
2024-05-03 18:31:14 +00:00
|
|
|
import { DestinationClass } from "./core/context/Destination.js";
|
|
|
|
import { Context } from "./core/context/Context.js";
|
|
|
|
import { TransportClass } from "./core/clock/Transport.js";
|
|
|
|
import { DrawClass } from "./core/util/Draw.js";
|
2019-10-30 18:48:29 +00:00
|
|
|
|
|
|
|
describe("Tone", () => {
|
|
|
|
it("has 'now' and 'immediate' methods", () => {
|
|
|
|
expect(Tone.now).to.be.a("function");
|
|
|
|
expect(Tone.now()).to.be.a("number");
|
|
|
|
expect(Tone.immediate).to.be.a("function");
|
|
|
|
expect(Tone.immediate()).to.be.a("number");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("exports the global singletons", () => {
|
2024-04-28 17:05:26 +00:00
|
|
|
expect(Tone.Destination).to.be.an.instanceOf(DestinationClass);
|
|
|
|
expect(Tone.Draw).to.be.an.instanceOf(DrawClass);
|
|
|
|
expect(Tone.Transport).to.be.an.instanceOf(TransportClass);
|
2019-10-30 18:48:29 +00:00
|
|
|
expect(Tone.context).to.be.an.instanceOf(Context);
|
|
|
|
});
|
2019-10-30 23:18:01 +00:00
|
|
|
|
2020-06-17 03:14:34 +00:00
|
|
|
it("exports the global singleton getters", () => {
|
2024-04-28 17:05:26 +00:00
|
|
|
expect(Tone.getDestination()).to.be.an.instanceOf(DestinationClass);
|
|
|
|
expect(Tone.getDraw()).to.be.an.instanceOf(DrawClass);
|
|
|
|
expect(Tone.getTransport()).to.be.an.instanceOf(TransportClass);
|
2020-06-17 03:14:34 +00:00
|
|
|
});
|
|
|
|
|
2019-10-30 23:18:01 +00:00
|
|
|
it("can start the global context", () => {
|
|
|
|
return Tone.start();
|
|
|
|
});
|
|
|
|
|
2019-11-16 21:42:19 +00:00
|
|
|
it("resolves the promise when everything is loaded", () => {
|
|
|
|
return Tone.loaded();
|
|
|
|
});
|
|
|
|
|
2019-10-30 23:18:01 +00:00
|
|
|
it("can set the global context from a raw online context", async () => {
|
|
|
|
const ctx = new AudioContext();
|
|
|
|
const origContext = Tone.getContext();
|
|
|
|
Tone.setContext(ctx);
|
|
|
|
expect(Tone.getContext().rawContext).to.equal(ctx);
|
|
|
|
await ctx.close();
|
|
|
|
Tone.setContext(origContext);
|
|
|
|
});
|
2024-05-03 18:31:14 +00:00
|
|
|
|
2019-10-30 23:18:01 +00:00
|
|
|
it("can set the global context from a raw offline context", async () => {
|
|
|
|
const ctx = new OfflineAudioContext(2, 44100, 44100);
|
|
|
|
const origContext = Tone.getContext();
|
|
|
|
Tone.setContext(ctx);
|
|
|
|
expect(Tone.getContext().rawContext).to.equal(ctx);
|
|
|
|
Tone.setContext(origContext);
|
|
|
|
});
|
2019-10-30 18:48:29 +00:00
|
|
|
});
|