mirror of
https://github.com/Tonejs/Tone.js
synced 2025-01-13 20:39:06 +00:00
adding gulp task for running tests
This commit is contained in:
parent
7272269964
commit
771a1a8f63
7 changed files with 155 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -40,3 +40,5 @@ examples/style/examples.scss
|
|||
examples/deps/Tone.dat.gui.js
|
||||
|
||||
examples/deps/dat.gui.js
|
||||
|
||||
test/mainTest.js
|
||||
|
|
10
gulp/fragments/test.frag
Normal file
10
gulp/fragments/test.frag
Normal file
|
@ -0,0 +1,10 @@
|
|||
require.config({
|
||||
baseUrl:"./",
|
||||
paths : {
|
||||
"Tone" : "../Tone",
|
||||
},
|
||||
});
|
||||
|
||||
require({FILES}, function(Test){
|
||||
Test.run();
|
||||
});
|
|
@ -12,7 +12,7 @@ var uglify = require("gulp-uglify");
|
|||
var rename = require("gulp-rename");
|
||||
var sass = require("gulp-ruby-sass");
|
||||
var prefix = require("gulp-autoprefixer");
|
||||
var concatCss = require("gulp-concat-css");
|
||||
var open = require("gulp-open");
|
||||
|
||||
/**
|
||||
* BUILDING
|
||||
|
@ -110,3 +110,30 @@ gulp.task("sass", function () {
|
|||
gulp.task("example", function() {
|
||||
gulp.watch(["../examples/style/examples.scss"], ["sass"]);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Test Runners
|
||||
*/
|
||||
gulp.task("test", ["collectTests"], function(){
|
||||
gulp.src("../test/test.html")
|
||||
.pipe(open());
|
||||
});
|
||||
|
||||
gulp.task("collectTests", function(done){
|
||||
var allFiles = [];
|
||||
var task = gulp.src(["../test/Test/*/*.js"])
|
||||
.pipe(tap(function(file){
|
||||
var fileName = path.relative("../test/", file.path);
|
||||
allFiles.push(fileName.substring(0, fileName.length - 3));
|
||||
}));
|
||||
task.on("end", function(){
|
||||
//build a require string
|
||||
allFiles.unshift("Test");
|
||||
var innerTask = gulp.src("./fragments/test.frag")
|
||||
.pipe(replace("{FILES}", JSON.stringify(allFiles)))
|
||||
.pipe(rename("mainTest.js"))
|
||||
.pipe(gulp.dest("../test/"));
|
||||
innerTask.on("end", done);
|
||||
});
|
||||
});
|
|
@ -27,5 +27,8 @@
|
|||
"Tone.js"
|
||||
],
|
||||
"author": "Yotam Mann",
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"gulp-open": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<script src="./deps/mocha.js"></script>
|
||||
<script src="./deps/chai.js"></script>
|
||||
<!-- TESTS -->
|
||||
<script data-main="Main.js" src="./deps/require.js"></script>
|
||||
<script data-main="mainTest.js" src="./deps/require.js"></script>
|
||||
<!-- STYLE -->
|
||||
<link rel="stylesheet" href="./deps/mocha.css" />
|
||||
</head>
|
||||
|
|
43
test/test.js
Normal file
43
test/test.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* global mocha, chai*/
|
||||
|
||||
define(["Tone/core/Tone"], function (Tone) {
|
||||
|
||||
//testing setup
|
||||
window.expect = chai.expect;
|
||||
mocha.setup("bdd");
|
||||
|
||||
|
||||
/**
|
||||
* The Test object
|
||||
*/
|
||||
var Test = {
|
||||
input : Tone.context.createGain()
|
||||
};
|
||||
|
||||
Test.run = function(){
|
||||
mocha.run();
|
||||
};
|
||||
|
||||
Test.wasDisposed = function(obj){
|
||||
for (var prop in obj){
|
||||
var member = obj[prop];
|
||||
if (typeof member !== "function" &&
|
||||
typeof member !== "string" &&
|
||||
typeof member !== "number" &&
|
||||
typeof member !== "boolean" &&
|
||||
prop !== "preset" &&
|
||||
!(member instanceof AudioContext)){
|
||||
if (member !== null){
|
||||
throw Error("property was not completely disposed: "+prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Test.connect = function(node, inputNumber){
|
||||
this.input.connect(node, 0, inputNumber);
|
||||
this.input.disconnect();
|
||||
};
|
||||
|
||||
return Test;
|
||||
});
|
67
test/tests/Core.js
Normal file
67
test/tests/Core.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
/* global it, describe, after */
|
||||
|
||||
define(["chai", "Tone/core/Tone", "Tone/core/Master", "Tone/core/Bus",
|
||||
"Tone/core/Note", "tests/Common", "Tone/core/Buffer", "Tone/source/Oscillator", "Tone/instrument/SimpleSynth"],
|
||||
function(chai, Tone, Master, Bus, Note, Test, Buffer, Oscillator, SimpleSynth){
|
||||
var expect = chai.expect;
|
||||
|
||||
describe("Tone.Buffer", function(){
|
||||
it ("can be created and disposed", function(){
|
||||
var buff = new Tone.Buffer("./testAudio/kick.mp3");
|
||||
buff.dispose();
|
||||
Test.wasDisposed(buff);
|
||||
});
|
||||
|
||||
it("loads a file from a url string", function(done){
|
||||
var buffer = new Buffer("./testAudio/kick.mp3", function(buff){
|
||||
expect(buff).to.be.instanceof(Buffer);
|
||||
buffer.dispose();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("has a duration", function(done){
|
||||
var buffer = new Buffer("./testAudio/kick.mp3", function(){
|
||||
expect(buffer.duration).to.be.closeTo(0.23, 0.01);
|
||||
buffer.dispose();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("the static onload method is invoked", function(done){
|
||||
var buffer = new Buffer("./testAudio/hh.mp3");
|
||||
Buffer.onload = function(){
|
||||
buffer.dispose();
|
||||
done();
|
||||
//reset this method for the next one
|
||||
Buffer.onload = function(){};
|
||||
};
|
||||
});
|
||||
|
||||
it("the static onprogress method is invoked", function(done){
|
||||
var progressWasInvoked = false;
|
||||
var buffer = new Buffer("./testAudio/hh.mp3", function(){
|
||||
buffer.dispose();
|
||||
expect(progressWasInvoked).to.be.true;
|
||||
done();
|
||||
});
|
||||
Buffer.onprogress = function(){
|
||||
progressWasInvoked = true;
|
||||
//reset this method for the next one
|
||||
Buffer.onprogress = function(){};
|
||||
};
|
||||
});
|
||||
|
||||
it("can reverse a buffer", function(done){
|
||||
var buffer = new Buffer("./testAudio/kick.mp3", function(){
|
||||
var buffArray = buffer.get();
|
||||
var lastSample = buffArray[buffArray.length - 1];
|
||||
buffer.reverse = true;
|
||||
expect(buffer.get()[0]).to.equal(lastSample);
|
||||
buffer.dispose();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in a new issue