Skip to content

Commit

Permalink
Using web-test-runner for tests, updating import paths (#1242)
Browse files Browse the repository at this point in the history
* WIP moving tests to web-test-runner

* updating thresholds

* Adding file extensions

* Testing integrations

* linting

* fixing dep

* moving back to root dir

* prettier all of the files

* updating eslint rules to use with prettier

* remove import package

* moving tsignore around

* removing unneeded ignores

* all tests run on puppeteer, no need for testing guards

* linting

* import type syntax

* cleaning up

* Update package.json
  • Loading branch information
tambien committed May 3, 2024
1 parent 066e46f commit aaf880c
Show file tree
Hide file tree
Showing 373 changed files with 19,461 additions and 16,387 deletions.
40 changes: 9 additions & 31 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
module.exports = {
parser: "@typescript-eslint/parser",
plugins: ["jsdoc", "html"],
plugins: ["jsdoc", "html", "file-extension-in-import-ts"],
extends: ["plugin:@typescript-eslint/recommended"],
settings: {
"import/extensions": [".js", ".ts"],
"import/resolver": {
typescript: true,
},
},
rules: {
"prefer-rest-params": "off",
"@typescript-eslint/ban-ts-ignore": "off",
Expand All @@ -23,7 +29,7 @@ module.exports = {
"no-useless-call": ["error"],
"no-unmodified-loop-condition": ["error"],
"quote-props": ["error", "as-needed"],
quotes: ["error", "double"],
quotes: ["error", "double", { avoidEscape: true }],
"no-shadow": "error",
"no-console": ["error", { allow: ["warn"] }],
"@typescript-eslint/no-object-literal-type-assertion": "off",
Expand All @@ -38,25 +44,11 @@ module.exports = {
},
],
"no-lonely-if": ["error"],
semi: ["error", "always"],
"no-cond-assign": ["error", "always"],
indent: "off",
"no-var": "error",
"prefer-arrow-callback": "error",
"@typescript-eslint/indent": [
"error",
"tab",
{ SwitchCase: 1, MemberExpression: 2 },
],
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"no-multi-spaces": ["error"],
"array-bracket-spacing": ["error", "never"],
"block-spacing": ["error", "always"],
"func-call-spacing": ["error", "never"],
"key-spacing": ["error", { beforeColon: false, afterColon: true }],
"brace-style": ["error", "1tbs"],
"space-in-parens": ["error", "never"],
"eol-last": ["error", "always"],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-use-before-define": "off",
Expand All @@ -70,21 +62,7 @@ module.exports = {
},
],
"lines-between-class-members": "off",
"no-multiple-empty-lines": ["error", { max: 1, maxEOF: 1, maxBOF: 0 }],
"no-unneeded-ternary": ["error"],
"object-curly-spacing": ["error", "always"],
"space-unary-ops": ["error", { words: true, nonwords: false }],
"block-spacing": ["error", "always"],
"keyword-spacing": ["error", { before: true }],
"space-before-function-paren": [
"error",
{ anonymous: "never", named: "never", asyncArrow: "always" },
],
"comma-spacing": ["error", { before: false, after: true }],
"arrow-spacing": ["error", { before: true, after: true }],
"space-before-blocks": [
"error",
{ functions: "always", keywords: "always", classes: "always" },
],
"file-extension-in-import-ts/file-extension-in-import-ts": "error",
},
};
36 changes: 27 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ jobs:
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version: 18.12.0
node-version: 18.18.0
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: All tests
run: npm run test
- name: Upload coverage
Expand All @@ -52,7 +50,7 @@ jobs:
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version: 18.12.0
node-version: 18.18.0
cache: 'npm'
- name: Install dependencies
run: npm install
Expand All @@ -72,7 +70,7 @@ jobs:
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version: 18.12.0
node-version: 18.18.0
cache: 'npm'
- name: Install dependencies
run: npm install
Expand All @@ -92,7 +90,7 @@ jobs:
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version: 18.12.0
node-version: 18.18.0
cache: 'npm'
- name: Install dependencies
run: npm install
Expand All @@ -110,18 +108,38 @@ jobs:
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version: 18.12.0
node-version: 18.18.0
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Test
run: npm run test:readme
test-integrations:
name: Test integrations
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version: 18.18.0
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Test
run: npm run test:integrations
publish:
runs-on: ubuntu-latest
# make sure all the tests pass first
needs: [run-tests, test-code-examples, test-html-examples, test-lint, test-readme]
needs: [run-tests, test-code-examples, test-html-examples, test-lint, test-readme, test-integrations]
# not on PRs
if: github.event_name != 'pull_request'
env:
Expand All @@ -132,7 +150,7 @@ jobs:
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: 18.12.0
node-version: 18.18.0
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm install
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test/supports.html
coverage/

build/*
dist/*
**/dist/*

examples/scratch.js
examples/scratch.ts
Expand All @@ -34,3 +34,4 @@ docs
.vscode
tone.d.ts
examples/scratch.ts
test/integration/*/package-lock.json
14 changes: 7 additions & 7 deletions Tone/classes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from "./core/index";
export * from "./source/index";
export * from "./signal/index";
export * from "./instrument/index";
export * from "./event/index";
export * from "./effect/index";
export * from "./component/index";
export * from "./core/index.js";
export * from "./source/index.js";
export * from "./signal/index.js";
export * from "./instrument/index.js";
export * from "./event/index.js";
export * from "./effect/index.js";
export * from "./component/index.js";
12 changes: 5 additions & 7 deletions Tone/component/analysis/Analyser.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { expect } from "chai";
import { BasicTests } from "test/helper/Basic";
import { Noise } from "../../source/Noise";
import { Analyser } from "./Analyser";
import { BasicTests } from "../../../test/helper/Basic.js";
import { Noise } from "../../source/Noise.js";
import { Analyser } from "./Analyser.js";

describe("Analyser", () => {

BasicTests(Analyser);

it("can get and set properties", () => {
Expand All @@ -31,7 +30,7 @@ describe("Analyser", () => {
const anl = new Analyser("fft", 512);
const analysis = anl.getValue();
expect(analysis.length).to.equal(512);
analysis.forEach(val => {
analysis.forEach((val) => {
expect(val).is.lessThan(0);
});
anl.dispose();
Expand All @@ -46,7 +45,7 @@ describe("Analyser", () => {
setTimeout(() => {
const analysis = anl.getValue();
expect(analysis.length).to.equal(256);
analysis.forEach(val => {
analysis.forEach((val) => {
expect(val).is.within(-1, 1);
});
anl.dispose();
Expand Down Expand Up @@ -74,5 +73,4 @@ describe("Analyser", () => {
expect((anl.getValue()[0] as Float32Array).length).to.equal(512);
anl.dispose();
});

});
51 changes: 35 additions & 16 deletions Tone/component/analysis/Analyser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { InputNode, OutputNode, ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode";
import { NormalRange, PowerOfTwo } from "../../core/type/Units";
import { optionsFromArguments } from "../../core/util/Defaults";
import { Split } from "../channel/Split";
import { Gain } from "../../core/context/Gain";
import { assert, assertRange } from "../../core/util/Debug";
import {
InputNode,
OutputNode,
ToneAudioNode,
ToneAudioNodeOptions,
} from "../../core/context/ToneAudioNode.js";
import { NormalRange, PowerOfTwo } from "../../core/type/Units.js";
import { optionsFromArguments } from "../../core/util/Defaults.js";
import { Split } from "../channel/Split.js";
import { Gain } from "../../core/context/Gain.js";
import { assert, assertRange } from "../../core/util/Debug.js";

export type AnalyserType = "fft" | "waveform";

Expand All @@ -20,7 +25,6 @@ export interface AnalyserOptions extends ToneAudioNodeOptions {
* @category Component
*/
export class Analyser extends ToneAudioNode<AnalyserOptions> {

readonly name: string = "Analyser";

readonly input: InputNode;
Expand Down Expand Up @@ -58,18 +62,30 @@ export class Analyser extends ToneAudioNode<AnalyserOptions> {
constructor(type?: AnalyserType, size?: number);
constructor(options?: Partial<AnalyserOptions>);
constructor() {
super(optionsFromArguments(Analyser.getDefaults(), arguments, ["type", "size"]));
const options = optionsFromArguments(Analyser.getDefaults(), arguments, ["type", "size"]);

this.input = this.output = this._gain = new Gain({ context: this.context });
super(
optionsFromArguments(Analyser.getDefaults(), arguments, [
"type",
"size",
])
);
const options = optionsFromArguments(
Analyser.getDefaults(),
arguments,
["type", "size"]
);

this.input =
this.output =
this._gain =
new Gain({ context: this.context });
this._split = new Split({
context: this.context,
channels: options.channels,
});
this.input.connect(this._split);

assertRange(options.channels, 1);

// create the analysers
for (let channel = 0; channel < options.channels; channel++) {
this._analysers[channel] = this.context.createAnalyser();
Expand Down Expand Up @@ -141,7 +157,10 @@ export class Analyser extends ToneAudioNode<AnalyserOptions> {
return this._type;
}
set type(type: AnalyserType) {
assert(type === "waveform" || type === "fft", `Analyser: invalid type: ${type}`);
assert(
type === "waveform" || type === "fft",
`Analyser: invalid type: ${type}`
);
this._type = type;
}

Expand All @@ -152,15 +171,15 @@ export class Analyser extends ToneAudioNode<AnalyserOptions> {
return this._analysers[0].smoothingTimeConstant;
}
set smoothing(val: NormalRange) {
this._analysers.forEach(a => a.smoothingTimeConstant = val);
this._analysers.forEach((a) => (a.smoothingTimeConstant = val));
}

/**
* Clean up.
*/
dispose(): this {
super.dispose();
this._analysers.forEach(a => a.disconnect());
this._analysers.forEach((a) => a.disconnect());
this._split.dispose();
this._gain.dispose();
return this;
Expand Down
33 changes: 14 additions & 19 deletions Tone/component/analysis/DCMeter.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
import { expect } from "chai";
import { BasicTests, warns } from "test/helper/Basic";
import { PassAudio } from "test/helper/PassAudio";
import { ONLINE_TESTING } from "test/helper/Supports";
import { Signal } from "Tone/signal/Signal";
import { DCMeter } from "./DCMeter";
import { BasicTests, warns } from "../../../test/helper/Basic.js";
import { PassAudio } from "../../../test/helper/PassAudio.js";
import { Signal } from "../../signal/Signal.js";
import { DCMeter } from "./DCMeter.js";

describe("DCMeter", () => {

BasicTests(DCMeter);

context("DCMetering", () => {

it("passes the audio through", () => {
return PassAudio((input) => {
const meter = new DCMeter().toDestination();
input.connect(meter);
});
});

if (ONLINE_TESTING) {
it("can get the rms level of the incoming signal", (done) => {
const meter = new DCMeter();
const osc = new Signal(2).connect(meter);
setTimeout(() => {
expect(meter.getValue()).to.be.closeTo(2, 0.1);
meter.dispose();
osc.dispose();
done();
}, 400);
});
}
it("can get the rms level of the incoming signal", (done) => {
const meter = new DCMeter();
const osc = new Signal(2).connect(meter);
setTimeout(() => {
expect(meter.getValue()).to.be.closeTo(2, 0.1);
meter.dispose();
osc.dispose();
done();
}, 400);
});
});
});
7 changes: 3 additions & 4 deletions Tone/component/analysis/DCMeter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { optionsFromArguments } from "../../core/util/Defaults";
import { MeterBase, MeterBaseOptions } from "./MeterBase";
import { optionsFromArguments } from "../../core/util/Defaults.js";
import { MeterBase, MeterBaseOptions } from "./MeterBase.js";

export type DCMeterOptions = MeterBaseOptions;

/**
* DCMeter gets the raw value of the input signal at the current time.
* DCMeter gets the raw value of the input signal at the current time.
* @see {@link Meter}.
*
* @example
Expand All @@ -18,7 +18,6 @@ export type DCMeterOptions = MeterBaseOptions;
* @category Component
*/
export class DCMeter extends MeterBase<DCMeterOptions> {

readonly name: string = "DCMeter";

constructor(options?: Partial<DCMeterOptions>);
Expand Down
Loading

0 comments on commit aaf880c

Please sign in to comment.