Skip to content

Commit 17e5b69

Browse files
authored
Add unit tests for GUI and fix some small bugs (#956)
1 parent e965149 commit 17e5b69

File tree

21 files changed

+2295
-4
lines changed

21 files changed

+2295
-4
lines changed

.github/workflows/gh-pages.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ jobs:
3333
uses: coverallsapp/github-action@master
3434
with:
3535
github-token: ${{ secrets.GITHUB_TOKEN }}
36+
test-js:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Test js
41+
run: yarn test:js --bail
3642
test-gui:
3743
runs-on: ubuntu-latest
3844
steps:

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ jobs:
1818
uses: coverallsapp/github-action@master
1919
with:
2020
github-token: ${{ secrets.GITHUB_TOKEN }}
21+
test-js:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Test js
26+
run: yarn test:js --bail
2127
test-gui:
2228
runs-on: ubuntu-latest
2329
steps:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
node_modules
33
docs
44
coverage
5+
coverage-js
56
lib/**/*.d.ts

js/data/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class MultiDimensionalData extends BaseData {
228228
this._originalY = this._y
229229
this._y = this._y.map(v => this._output_category_names.indexOf(v) + 1)
230230
if (infos[i].labels) {
231-
this._output_category_names[k] = this._output_category_names[k].map(v =>
231+
this._output_category_names = this._output_category_names.map(v =>
232232
Object.hasOwn(infos[i].labels, v) ? infos[i].labels[v] : v
233233
)
234234
}

js/data/loader/csv.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default class CSV {
2525
if (this._header > 0) {
2626
return this._data[0]
2727
}
28-
return Array.from(this._data[0], (_, i) => i)
28+
return Array.from(this._data[0], (_, i) => '' + i)
2929
}
3030

3131
/**

js/expression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const uops = {
1818

1919
const bops = {
2020
'||': new OP('||', -2, (a, b) => (a || b ? 1 : 0)),
21-
'&&': new OP('&&', -1, (a, b) => (a || b ? 1 : 0)),
21+
'&&': new OP('&&', -1, (a, b) => (a && b ? 1 : 0)),
2222
'==': new OP('==', 0, (a, b) => (a === b ? 1 : 0)),
2323
'!=': new OP('!=', 0, (a, b) => (a !== b ? 1 : 0)),
2424
'<': new OP('<', 0, (a, b) => (a < b ? 1 : 0)),

js/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class EventEmitter {
122122
return
123123
}
124124
for (let i = listeners.length - 1; i >= 0; i--) {
125-
if (listeners[i] === listener) {
125+
if (listeners[i].cb === listener) {
126126
listeners.splice(i, 1)
127127
}
128128
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"lint": "eslint ./lib ./tests",
2121
"check-types": "npm run create-entry && tsc ./lib/**.js ./lib/**/*.js --allowJs --checkJs --target esnext --noEmit --skipLibCheck",
2222
"test:lib": "npm run create-entry && NODE_OPTIONS=--experimental-vm-modules npx jest --testMatch '**/lib/**/?(*.)+(spec|test).[jt]s?(x)' --coverage --coveragePathIgnorePatterns '/node_modules/' 'onnx/onnx_pb.js' --reporters default ./tests/retry-test.js ./tests/slow-test.js --maxWorkers=100% --workerIdleMemoryLimit=100MB",
23+
"test:js": "NODE_OPTIONS=--experimental-vm-modules npx jest --config ./tests/jest-js.config.js",
2324
"test:gui": "NODE_OPTIONS=--experimental-vm-modules npx jest --testMatch '**/gui/**/?(*.)+(spec|test).[jt]s?(x)' --coveragePathIgnorePatterns '/node_modules/' 'onnx/onnx_pb.js' --reporters default ./tests/retry-test.js ./tests/slow-test.js ./tests/gui-coverage-reporter.js --testTimeout=20000 --maxWorkers=100% --workerIdleMemoryLimit=100MB",
2425
"types": "npm run create-entry && find lib -name \\*.d.ts -delete && tsc ./lib/**.js ./lib/**/*.js --declaration --allowJs --emitDeclarationOnly",
2526
"document": "npm run types && typedoc --skipErrorChecking ./lib/**.d.ts",

tests/jest-js.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default {
2+
testMatch: ['**/js/**/?(*.)+(spec|test).[jt]s?(x)'],
3+
reporters: ['default', '<rootDir>/retry-test.js', '<rootDir>/slow-test.js'],
4+
moduleNameMapper: {
5+
'^https://cdn\\.jsdelivr\\.net/npm/pdfjs-dist@[0-9.]+/build/pdf\\.min\\.mjs$':
6+
'<rootDir>/js/__mock__/pdf.min.js',
7+
'^https://cdnjs\\.cloudflare\\.com/ajax/libs/encoding-japanese/[0-9.]+/encoding\\.min\\.js$':
8+
'<rootDir>/js/__mock__/encoding.min.js',
9+
},
10+
collectCoverage: true,
11+
coverageDirectory: '../coverage-js',
12+
coveragePathIgnorePatterns: ['/node_modules/', 'onnx/onnx_pb.js'],
13+
maxWorkers: '100%',
14+
workerIdleMemoryLimit: '100MB',
15+
}

tests/js/__mock__/encoding.min.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {}

0 commit comments

Comments
 (0)