UNPKG

1.83 kBPlain TextView Raw
1import * as Tone from "./index.js";
2import { expect } from "chai";
3import { DestinationClass } from "./core/context/Destination.js";
4import { Context } from "./core/context/Context.js";
5import { TransportClass } from "./core/clock/Transport.js";
6import { DrawClass } from "./core/util/Draw.js";
7
8describe("Tone", () => {
9 it("has 'now' and 'immediate' methods", () => {
10 expect(Tone.now).to.be.a("function");
11 expect(Tone.now()).to.be.a("number");
12 expect(Tone.immediate).to.be.a("function");
13 expect(Tone.immediate()).to.be.a("number");
14 });
15
16 it("exports the global singletons", () => {
17 expect(Tone.Destination).to.be.an.instanceOf(DestinationClass);
18 expect(Tone.Draw).to.be.an.instanceOf(DrawClass);
19 expect(Tone.Transport).to.be.an.instanceOf(TransportClass);
20 expect(Tone.context).to.be.an.instanceOf(Context);
21 });
22
23 it("exports the global singleton getters", () => {
24 expect(Tone.getDestination()).to.be.an.instanceOf(DestinationClass);
25 expect(Tone.getDraw()).to.be.an.instanceOf(DrawClass);
26 expect(Tone.getTransport()).to.be.an.instanceOf(TransportClass);
27 });
28
29 it("can start the global context", () => {
30 return Tone.start();
31 });
32
33 it("resolves the promise when everything is loaded", () => {
34 return Tone.loaded();
35 });
36
37 it("can set the global context from a raw online context", async () => {
38 const ctx = new AudioContext();
39 const origContext = Tone.getContext();
40 Tone.setContext(ctx);
41 expect(Tone.getContext().rawContext).to.equal(ctx);
42 await ctx.close();
43 Tone.setContext(origContext);
44 });
45
46 it("can set the global context from a raw offline context", async () => {
47 const ctx = new OfflineAudioContext(2, 44100, 44100);
48 const origContext = Tone.getContext();
49 Tone.setContext(ctx);
50 expect(Tone.getContext().rawContext).to.equal(ctx);
51 Tone.setContext(origContext);
52 });
53});