Tone.js/test/core/Offline.js

84 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-05-18 16:07:20 +00:00
define(["helper/Test", "Tone/core/Offline", "Tone/core/Transport", "Tone/source/Oscillator",
"Tone/core/Tone", "Tone/core/Buffer", "helper/BufferTest"],
2018-05-18 16:07:20 +00:00
function(Test, Offline, Transport, Oscillator, Tone, AudioBuffer, BufferTest){
2017-02-19 16:52:46 +00:00
describe("Offline", function(){
2017-12-30 16:26:29 +00:00
it("exists", function(){
2017-02-19 16:52:46 +00:00
expect(Offline).to.exist;
expect(Tone.Offline).to.exist;
});
2017-12-30 16:26:29 +00:00
it("accepts a callback and a duration", function(){
2017-02-19 16:52:46 +00:00
Offline(function(){}, 0.01);
});
2017-12-30 16:26:29 +00:00
it("returns a promise", function(){
expect(Offline(function(){}, 0.01)).to.have.property("then");
2017-02-19 16:52:46 +00:00
});
2017-12-30 16:26:29 +00:00
it("generates a buffer", function(done){
2017-02-19 16:52:46 +00:00
Offline(function(){}, 0.01).then(function(buffer){
expect(buffer).to.be.instanceOf(AudioBuffer);
done();
});
});
2017-12-30 16:26:29 +00:00
it("silent by default", function(done){
2017-02-19 16:52:46 +00:00
Offline(function(){}, 0.01).then(function(buffer){
2017-02-20 03:50:39 +00:00
BufferTest(buffer);
expect(buffer.isSilent()).to.be.true;
2017-02-19 16:52:46 +00:00
done();
});
});
2017-12-30 16:26:29 +00:00
it("records the master output", function(){
2017-02-19 16:52:46 +00:00
return Offline(function(){
new Oscillator().toMaster().start();
}, 0.01).then(function(buffer){
2017-02-20 03:50:39 +00:00
BufferTest(buffer);
expect(buffer.isSilent()).to.be.false;
2017-02-19 16:52:46 +00:00
});
});
it("returning a promise defers the rendering till the promise resolves", function(){
var wasInvoked = false;
return Offline(function(){
new Oscillator().toMaster().start();
return new Promise(function(done){
setTimeout(done, 100);
}).then(function(){
wasInvoked = true;
});
}, 0.01).then(function(buffer){
BufferTest(buffer);
expect(wasInvoked).to.be.true;
expect(buffer.isSilent()).to.be.false;
});
});
2017-12-30 16:26:29 +00:00
it("can schedule specific timing outputs", function(){
2017-02-19 16:52:46 +00:00
return Offline(function(){
new Oscillator().toMaster().start(0.05);
}, 0.1).then(function(buffer){
2017-02-20 03:50:39 +00:00
BufferTest(buffer);
expect(buffer.getFirstSoundTime()).to.be.closeTo(0.05, 0.0001);
2017-02-19 16:52:46 +00:00
});
});
2017-12-30 16:26:29 +00:00
it("can schedule Transport events", function(){
2017-02-19 16:52:46 +00:00
return Offline(function(Transport){
var osc = new Oscillator().toMaster();
Transport.schedule(function(time){
osc.start(time);
}, 0.05);
Transport.start(0);
}, 0.1).then(function(buffer){
2017-02-20 03:50:39 +00:00
BufferTest(buffer);
expect(buffer.getFirstSoundTime()).to.be.closeTo(0.05, 0.001);
2017-02-19 16:52:46 +00:00
});
});
});
2017-12-30 16:26:29 +00:00
});