Merge pull request #242 from tidalcycles/example-tests

in source example tests
This commit is contained in:
Felix Roos 2022-11-03 15:16:03 +01:00 committed by GitHub
commit f829f35cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 3223 additions and 4 deletions

View File

@ -4,6 +4,7 @@
"private": true, "private": true,
"description": "Port of tidalcycles to javascript", "description": "Port of tidalcycles to javascript",
"scripts": { "scripts": {
"pretest": "cd tutorial && npm run jsdoc-json",
"test": "vitest run --version", "test": "vitest run --version",
"test-ui": "vitest --ui", "test-ui": "vitest --ui",
"test-coverage": "vitest --coverage", "test-coverage": "vitest --coverage",

View File

@ -21,6 +21,7 @@ import Fraction, { gcd } from './fraction.mjs';
* @example * @example
* const line = drawLine("0 [1 2 3]", 10); // |0--123|0--123 * const line = drawLine("0 [1 2 3]", 10); // |0--123|0--123
* console.log(line); * console.log(line);
* silence;
*/ */
function drawLine(pat, chars = 60) { function drawLine(pat, chars = 60) {
let cycle = 0; let cycle = 0;

View File

@ -15,6 +15,7 @@ export * from './state.mjs';
export * from './timespan.mjs'; export * from './timespan.mjs';
export * from './util.mjs'; export * from './util.mjs';
export * from './speak.mjs'; export * from './speak.mjs';
export { default as drawLine } from './drawLine.mjs';
export { default as gist } from './gist.js'; export { default as gist } from './gist.js';
// below won't work with runtime.mjs (json import fails) // below won't work with runtime.mjs (json import fails)
/* import * as p from './package.json'; /* import * as p from './package.json';

View File

@ -32,8 +32,10 @@ export class Pattern {
* @param {Fraction | number} end to time * @param {Fraction | number} end to time
* @returns Hap[] * @returns Hap[]
* @example * @example
* const pattern = sequence('a', ['b', 'c']); * const pattern = sequence('a', ['b', 'c'])
* const haps = pattern.queryArc(0, 1); * const haps = pattern.queryArc(0, 1)
* console.log(haps)
* silence
*/ */
queryArc(begin, end) { queryArc(begin, end) {
return this.query(new State(new TimeSpan(begin, end))); return this.query(new State(new TimeSpan(begin, end)));
@ -1543,7 +1545,7 @@ export function pure(value) {
export function isPattern(thing) { export function isPattern(thing) {
// thing?.constructor?.name !== 'Pattern' // <- this will fail when code is mangled // thing?.constructor?.name !== 'Pattern' // <- this will fail when code is mangled
const is = thing instanceof Pattern || thing._Pattern; const is = thing instanceof Pattern || thing?._Pattern;
if (!thing instanceof Pattern) { if (!thing instanceof Pattern) {
console.warn( console.warn(
`Found Pattern that fails "instanceof Pattern" check. `Found Pattern that fails "instanceof Pattern" check.

View File

@ -83,7 +83,9 @@ const toneHelpersMocked = {
highpass: mockNode, highpass: mockNode,
}; };
// tone mock strudel.Pattern.prototype.osc = function () {
return this;
};
strudel.Pattern.prototype.tone = function () { strudel.Pattern.prototype.tone = function () {
return this; return this;
}; };

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
import { queryCode } from '../../repl/src/runtime.mjs';
import { describe, it } from 'vitest';
import doc from '../../doc.json';
describe('runs examples', () => {
const { docs } = doc;
docs.forEach(async (doc) => {
doc.examples?.forEach((example, i) => {
it(`example "${doc.name}" example index ${i}`, async ({ expect }) => {
const haps = await queryCode(example, 4);
expect(haps).toMatchSnapshot();
});
});
});
});