Skip to content

Commit

Permalink
Add actions and move tests to cypress (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 authored Jul 17, 2023
1 parent b0061d8 commit ad0e701
Show file tree
Hide file tree
Showing 35 changed files with 1,635 additions and 592 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ module.exports = {
],
'@typescript-eslint/no-shadow': ["error"]
}
},
{
files: ['test/**/*.ts', 'cypress/**/*.ts'],
extends: ['plugin:cypress/recommended'],
rules: {
'no-unused-expressions': 0,
'no-unused-vars': 0
}
}
],

Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Codestyle

on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- '**/src/*.js'
- '**/src/*.ts'
- '.github/workflows/codestyle.yml'
pull_request:
branches: [ master, 'v[0-9]+.[0-9]+' ]
paths:
- '**/src/*.js'
- '**/src/*.ts'
- '.github/workflows/codestyle.yml'

jobs:
check-web-codestyle:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node.js LTS
uses: actions/setup-node@v3
with:
node-version: lts/*

- name: Pre-build dependencies
run: npm install yarn

- name: Run Binding Linter
run: yarn && yarn lint
34 changes: 34 additions & 0 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Package-build

on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- "demo/**"
- '.github/workflows/demo.yml'
pull_request:
branches: [ master, 'v[0-9]+.[0-9]+' ]
paths:
- "demo/**"
- '.github/workflows/demo.yml'

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [ 14.x, 16.x, 18.x, 20.x ]

steps:
- uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3

- name: Pre-build dependencies
run: npm install yarn

- name: Install dependencies
run: yarn install
18 changes: 18 additions & 0 deletions .github/workflows/link-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Check Markdown links

on:
workflow_dispatch:
push:
branches: [ master ]
pull_request:
branches: [ master, 'v[0-9]+.[0-9]+' ]

jobs:
markdown-link-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: gaurav-nelson/[email protected]
with:
use-quiet-mode: 'yes'
use-verbose-mode: 'yes'
24 changes: 11 additions & 13 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,33 @@ name: Package-build
on:
workflow_dispatch:
push:
branches: [master]
branches: [ master ]
paths:
- "audio/**"
- "src/**"
- "lib/**"
- '.github/workflows/package.yml'
pull_request:
branches: [master]
branches: [ master, 'v[0-9]+.[0-9]+' ]
paths:
- "audio/**"
- "src/**"
- "lib/**"
- '.github/workflows/package.yml'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
strategy:
matrix:
node-version: [ 14.x, 16.x, 18.x, 20.x ]

- name: Set up Python
uses: actions/setup-python@v2
steps:
- uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v2

- name: Install system dependencies
run: |
pip install selenium
pip install webdriver-manager
uses: actions/setup-node@v3

- name: Pre-build dependencies
run: npm install yarn
Expand All @@ -46,4 +44,4 @@ jobs:
run: yarn && yarn build

- name: Test
run: python3 test/selenium_test.py
run: yarn test
25 changes: 25 additions & 0 deletions .github/workflows/spell-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: SpellCheck

on:
workflow_dispatch:
push:
branches: [ master ]
pull_request:
branches: [ master, 'v[0-9]+.[0-9]+' ]

jobs:
markdown:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Install CSpell
run: npm install -g cspell

- name: Run CSpell
run: cspell --config resources/.lint/spell-check/.cspell.json "**/*"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
node_modules
.DS_Store
dist
package-lock.json
package-lock.json
cypress/downloads
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Web Voice Processor

[![GitHub release](https://img.shields.io/github/release/Picovoice/web-voice-processor.svg)](https://github.com/Picovoice/web-voice-processor/releases)
[![GitHub](https://img.shields.io/github/license/Picovoice/web-voice-processor)](https://github.com/Picovoice/web-voice-processor/releases)
[![npm](https://img.shields.io/npm/v/@picovoice/web-voice-processor?label=npm%20%5Bweb%5D)](https://www.npmjs.com/package/@picovoice/web-voice-processor)

Made in Vancouver, Canada by [Picovoice](https://picovoice.ai)

Expand All @@ -14,10 +16,9 @@ A library for real-time voice processing in web browsers.
- [Web Voice Processor](#web-voice-processor)
- [Browser compatibility](#browser-compatibility)
- [Browser features](#browser-features)
- [AudioWorklet & Safari](#audioworklet---safari)
- [Installation](#installation)
- [How to use](#how-to-use)
- [Via ES Modules (Create React App, Angular, Webpack, etc.)](#via-es-modules--create-react-app--angular--webpack--etc-)
- [Via ES Modules (Create React App, Angular, Webpack, etc.)](#via-es-modules-create-react-app-angular-webpack-etc)
- [Via HTML script tag](#via-html-script-tag)
- [Start listening](#start-listening)
- [Stop listening](#stop-listening)
Expand Down Expand Up @@ -104,7 +105,7 @@ await WebVoiceProcessor.subscribe(worker);
await WebVoiceProcessor.subscribe([engine, worker]);
```

An `engine` is either a [Web Workers](<(https://developer.mozilla.org/en-US/docs/Web/API/Worker)>) or an object
An `engine` is either a [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Worker) or an object
implementing the following interface within their `onmessage` method:

```javascript
Expand All @@ -119,7 +120,7 @@ onmessage = function (e) {

where `e.data.inputFrame` is an `Int16Array` of `frameLength` audio samples.

For examples of using engines, look at [src/engines](/package/src/engines).
For examples of using engines, look at [src/engines](src/engines).

This is async due to its [Web Audio API microphone request](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia). The promise will be rejected if the user refuses permission, no suitable devices are found, etc. Your calling code should anticipate the possibility of rejection. When the promise resolves, the WebVoiceProcessor is running.

Expand Down
14 changes: 14 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from "cypress";

export default defineConfig({
env: {
"DEBUG": false,
},
e2e: {
defaultCommandTimeout: 30000,
supportFile: "cypress/support/index.ts",
specPattern: "test/*.test.{js,jsx,ts,tsx}",
video: false,
screenshotOnRunFailure: false,
}
});
Empty file added cypress/fixtures/.gitkeep
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

Cypress.Commands.add("getFramesFromFile", (path: string) => {
cy.fixture(path, 'base64').then(Cypress.Blob.base64StringToBlob).then(async blob => {
return new Int16Array(await blob.arrayBuffer());
});
});
12 changes: 12 additions & 0 deletions cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Components App</title>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
9 changes: 9 additions & 0 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "./commands";

declare global {
namespace Cypress {
interface Chainable {
getFramesFromFile(path: string): Chainable<Int16Array>;
}
}
}
11 changes: 11 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["cypress"]
},
"include": [
"../test/**/*.ts",
"./**/*.ts"
],
"exclude": []
}
35 changes: 20 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"prepack": "npm-run-all build",
"start": "cross-env TARGET='debug' rollup --config --watch",
"watch": "rollup --config --watch",
"format": "prettier --write \"**/*.{js,ts,json}\""
"format": "prettier --write \"**/*.{js,ts,json}\"",
"test": "cypress run"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -43,28 +44,32 @@
"url": "https://github.com/Picovoice/web-voice-processor/issues"
},
"homepage": "https://github.com/Picovoice/web-voice-processor#readme",
"dependencies": {
"@picovoice/web-utils": "=1.3.1"
},
"devDependencies": {
"@babel/core": "^7.18.10",
"@babel/plugin-transform-runtime": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/runtime": "^7.18.3",
"@picovoice/web-utils": "=1.2.9",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^18.1.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-terser": "^0.3.0",
"@rollup/pluginutils": "^4.2.1",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
"async-mutex": "^0.3.2",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/pluginutils": "^5.0.2",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"async-mutex": "^0.4.0",
"cross-env": "^7.0.3",
"cypress": "~12.8.1",
"eslint": "^8.13.0",
"eslint-plugin-cypress": "^2.12.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.6.2",
"rollup": "^2.70.1",
"rollup-plugin-typescript2": "^0.31.2",
"prettier": "^2.8.3",
"rollup": "^2.79.1",
"rollup-plugin-typescript2": "^0.34.1",
"rollup-plugin-web-worker-loader": "^1.6.1",
"tslib": "^2.3.1",
"typescript": "^4.6.3"
"tslib": "^2.5.0",
"typescript": "^4.9.5"
}
}
23 changes: 23 additions & 0 deletions resources/.lint/spell-check/.cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"language": "en",
"dictionaries": [
"dict"
],
"dictionaryDefinitions": [
{
"name": "dict",
"path": "./dict.txt",
"addWords": true
}
],
"ignorePaths": [
"**/package.json",
"**/packages-lock.json",
"**/tsconfig.json",
"**/tslint.json",
"**/node_modules/*",
"**/dist/*",
"**/lib/*",
"**/resources/audio/*"
]
}
14 changes: 14 additions & 0 deletions resources/.lint/spell-check/dict.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
camelcase
downsampled
fdstat
filestat
iife
oneoff
picovoice
pread
prestat
pwrite
resampler
sched
wavefile
worklet
2 changes: 1 addition & 1 deletion src/engines/vu_meter_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class VuMeterEngine {
};
}

get worker() {
get worker(): Worker {
return this._worker;
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Resampler.setWasm(resamplerWasm);
ResamplerWorker.setWasm(resamplerWasm);

export {
Resampler,
ResamplerWorker,
VuMeterEngine,
WvpError,
Expand Down
Loading

0 comments on commit ad0e701

Please sign in to comment.