Skip to content

Commit eb6d5c8

Browse files
committed
Fix createFile documentation and loadFile tests
1 parent c1cc373 commit eb6d5c8

5 files changed

Lines changed: 15 additions & 13 deletions

File tree

‎dist/Chuck.d.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default class Chuck extends window.AudioWorkletNode {
104104
* @param filename Name of file to create
105105
* @param data Data to write to the file
106106
*/
107-
createFile(directory: string, filename: string, data: string | ArrayBuffer): void;
107+
createFile(directory: string, filename: string, data: string | Uint8Array): void;
108108
/**
109109
* Create a virtual directory in ChucK's filesystem.
110110
* @param parent Virtual directory to create the new directory in
@@ -272,7 +272,8 @@ export default class Chuck extends window.AudioWorkletNode {
272272
/**
273273
* Remove a shred from ChucK VM by ID
274274
* @param shred Shred ID to be removed
275-
* @returns Promise to shred ID if removed successfully, otherwise "removing code failed"
275+
* @returns Promise to shred ID if removed successfully, otherwise rejects
276+
* with "Removing code failed"
276277
*/
277278
removeShred(shred: number | string): Promise<number>;
278279
/**

‎dist/Chuck.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export default class Chuck extends window.AudioWorkletNode {
208208
this.createFile("", filename, data);
209209
}
210210
else {
211-
this.createFile("", filename, data);
211+
this.createFile("", filename, new Uint8Array(data));
212212
}
213213
})
214214
.catch((err) => {
@@ -454,7 +454,8 @@ export default class Chuck extends window.AudioWorkletNode {
454454
/**
455455
* Remove a shred from ChucK VM by ID
456456
* @param shred Shred ID to be removed
457-
* @returns Promise to shred ID if removed successfully, otherwise "removing code failed"
457+
* @returns Promise to shred ID if removed successfully, otherwise rejects
458+
* with "Removing code failed"
458459
*/
459460
removeShred(shred) {
460461
const callbackID = this.nextDeferID();

‎src/Chuck.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export default class Chuck extends window.AudioWorkletNode {
197197
* @param filename Name of file to create
198198
* @param data Data to write to the file
199199
*/
200-
public createFile(directory: string, filename: string, data: string | ArrayBuffer) {
200+
public createFile(directory: string, filename: string, data: string | Uint8Array) {
201201
this.sendMessage(OutMessage.CREATE_FILE, {
202202
directory,
203203
filename,
@@ -239,7 +239,7 @@ export default class Chuck extends window.AudioWorkletNode {
239239
if (isText) {
240240
this.createFile("", filename, data as string);
241241
} else {
242-
this.createFile("", filename, data as ArrayBuffer);
242+
this.createFile("", filename, new Uint8Array(data as ArrayBuffer));
243243
}
244244
})
245245
.catch((err) => {

‎src/wc-bundle.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class Chuck extends window.AudioWorkletNode {
372372
this.createFile("", filename, data);
373373
}
374374
else {
375-
this.createFile("", filename, data);
375+
this.createFile("", filename, new Uint8Array(data));
376376
}
377377
})
378378
.catch((err) => {
@@ -618,7 +618,8 @@ class Chuck extends window.AudioWorkletNode {
618618
/**
619619
* Remove a shred from ChucK VM by ID
620620
* @param shred Shred ID to be removed
621-
* @returns Promise to shred ID if removed successfully, otherwise "removing code failed"
621+
* @returns Promise to shred ID if removed successfully, otherwise rejects
622+
* with "Removing code failed"
622623
*/
623624
removeShred(shred) {
624625
const callbackID = this.nextDeferID();

‎test/chuckTest.js‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ TestSuite.test("[sound] Dynamic load in a kick wav file from URL", async (t) =>
284284
() => {
285285
aChuck.runCode(code);
286286
},
287-
(output) => output === "KICKED",
287+
(output) => output.includes("KICKED"),
288288
2000,
289289
);
290290
t.assert(passed, "Should have printed KICKED");
@@ -351,10 +351,8 @@ TestSuite.test("Test shred management, add, remove, replace", async (t) => {
351351

352352
t.assert((await aChuck.removeLastCode()) === shred2, "removeLastCode should return shred2");
353353

354-
const { oldShred, newShred } = await aChuck.replaceCode(`
355-
<<< "REPLACE Shred 1 with a new program", "" >>>;
356-
1::week => now;
357-
`,
354+
const { oldShred, newShred } = await aChuck.replaceCode(
355+
`<<< "REPLACE Shred 1 with a new program", "" >>>; 1::week => now;`,
358356
shred1,
359357
);
360358
t.assert(
@@ -487,6 +485,7 @@ TestSuite.test("WebChucK get deferred Promise<type> returns", async (t) => {
487485
});
488486

489487
TestSuite.test("[sound] WebChugin Test, ABSaturator", async (t) => {
488+
Chuck.loadChugin("./testFiles/ABSaturator.chug.wasm");
490489
const aChuck = await setupChuck(t);
491490
const code = `SinOsc osc => Delay d => ABSaturator sat => dac;
492491
20 => sat.drive;

0 commit comments

Comments
 (0)