Skip to content

Commit

Permalink
gh-35: Improves test coverage and fine-tunes testem configurations.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinbdclark committed Mar 3, 2023
1 parent 47c3254 commit 148f418
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 49 deletions.
20 changes: 10 additions & 10 deletions src/js/audiocontext-clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ var fluid = fluid || require("infusion"),
"onStart.startAudioContext": {
priority: "after:updateState",
funcName: "berg.clock.autoAudioContext.start",
args: ["{that}"]
args: ["{that}.scriptNode", "{that}.context", "{that}.tick"]
},

"onStop.stopAudioContext": {
priority: "after:updateState",
funcName: "berg.clock.autoAudioContext.stop",
args: ["{that}"]
args: ["{that}.scriptNode", "{that}.context"]
}
}
});
Expand All @@ -107,15 +107,15 @@ var fluid = fluid || require("infusion"),
return scriptNode;
};

berg.clock.autoAudioContext.start = function (that) {
that.scriptNode.connect(that.context.destination);
that.scriptNode.onaudioprocess = that.tick;
that.context.resume();
berg.clock.autoAudioContext.start = function (scriptNode, context, tickFn) {
scriptNode.connect(context.destination);
scriptNode.onaudioprocess = tickFn;
context.resume();
};

berg.clock.autoAudioContext.stop = function (that) {
berg.clock.autoAudioContext.stop = function (scriptNode, context) {
try {
that.scriptNode.disconnect(that.context.destination);
scriptNode.disconnect(context.destination);
} catch (e) {
// Only swallow the error if was thrown because
// the script node wasn't connected,
Expand All @@ -125,7 +125,7 @@ var fluid = fluid || require("infusion"),
}
}

that.scriptNode.onaudioprocess = undefined;
that.context.suspend();
scriptNode.onaudioprocess = undefined;
context.suspend();
};
})();
4 changes: 2 additions & 2 deletions tests/all-tests.html → tests/core-tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>All Bergson Tests</title>
<title>Bergson Core Tests</title>

<link rel="stylesheet" href="../node_modules/infusion/tests/lib/qunit/css/qunit.css" type="text/css" media="screen">
<link rel="stylesheet" href="../node_modules/infusion/tests/lib/qunit/addons/composite/qunit-composite.css">
Expand All @@ -11,7 +11,7 @@
<script src="/testem.js"></script>

<script>
QUnit.testSuites("Bergson Tests", [
QUnit.testSuites("Bergson Core Tests", [
"html/offline-clock-tests.html",
"html/realtime-clock-tests.html",
"html/raf-clock-tests.html",
Expand Down
76 changes: 41 additions & 35 deletions tests/js/audiocontext-clock-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ var fluid = fluid || require("infusion"),

QUnit.module("AudioContext Clock Tests");

fluid.defaults("berg.test.clock.autoAudioContextClockTestSuite", {
gradeNames: ["berg.test.clock.testSuite"],

tests: [
{
name: "Initial state, default options",
initOnly: true,
tester: {
type: "berg.test.clock.tester.audioContext"
}
},

{
name: "tick() time update",
tester: {
type: "berg.test.clock.tester.audioContext"
}
}
]
});

var testSuite = berg.test.clock.autoAudioContextClockTestSuite();
testSuite.run();

QUnit.test("Instantiation", function () {
var clock = berg.clock.autoAudioContext();
QUnit.ok(clock, "Clock was successfully instantiated.");
Expand All @@ -28,9 +52,9 @@ var fluid = fluid || require("infusion"),

try {
clock.start();
QUnit.ok(true, "Clock successfully started.");
QUnit.ok(clock.model.isPlaying, "Clock successfully started.");
} catch (e) {
QUnit.ok(false, "Clock failed to start successfully", e);
QUnit.ok(false, "Clock failed to start successfully: " + e.message);
}
});

Expand All @@ -39,46 +63,28 @@ var fluid = fluid || require("infusion"),

try {
clock.stop();
QUnit.ok(true, "Calling stop() before starting has no effect.");
QUnit.ok(!clock.model.isPlaying, "Calling stop() before starting has no effect.");
} catch (e) {
QUnit.ok(false, "Calling stop() before starting failed: " + e.message);
}
});

QUnit.test("Stop after start", function () {
QUnit.asyncTest("Start, stop, restart, stop sequence", function () {
var clock = berg.clock.autoAudioContext();

try {
clock.start();
clock.stop();
QUnit.ok(true, "Clock successfully stopped after starting.");
} catch (e) {
QUnit.ok(false, "Calling stop() after starting failed.", e);
}
});


fluid.defaults("berg.test.clock.autoAudioContextClockTestSuite", {
gradeNames: ["berg.test.clock.testSuite"],
clock.start();
QUnit.ok(clock.model.isPlaying, "Calling start was successful.");
clock.stop();
QUnit.ok(!clock.model.isPlaying, "Calling stop was successful.");
clock.start();
QUnit.ok(clock.model.isPlaying,
"Calling start after stopping was successful.");

tests: [
{
name: "Initial state, default options",
initOnly: true,
tester: {
type: "berg.test.clock.tester.audioContext"
}
},

{
name: "tick() time update",
tester: {
type: "berg.test.clock.tester.audioContext"
}
}
]
setInterval(function () {
clock.stop();
QUnit.ok(!clock.model.isPlaying,
"Calling stop again after waiting for a bit was successful.");
QUnit.start();
}, 100);
});

var testSuite = berg.test.clock.autoAudioContextClockTestSuite();
testSuite.run();
})();
4 changes: 2 additions & 2 deletions tests/testem.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"test_page": "tests/all-tests.html",
"test_page": "tests/core-tests.html",
"timeout": 300,
"launch": "Firefox,Chrome,Safari"
"skip": "Brave,Chrome Canary,Edge,Headless Brave,Headless Chrome,Headless Firefox,Headless Opera,IE,Opera"
}

0 comments on commit 148f418

Please sign in to comment.