Skip to content

Commit 97d6e66

Browse files
committed
changed tests to typescript
1 parent 760a246 commit 97d6e66

13 files changed

+335
-30
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"env": {
33
"browser": true,
4-
"es2021": true
4+
"es2021": true,
5+
"mocha": true
56
},
67
"extends": [
78
"airbnb-base"

package-lock.json

Lines changed: 276 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
"repository": "github:oneai-nlp/oneai-node",
77
"scripts": {
88
"build": "tsc",
9-
"test": "nyc mocha --reporter spec --timeout 50000",
9+
"test": "nyc mocha --reporter spec --require ts-node/register --timeout 50000 test/**/*.ts",
1010
"report": "nyc -r text -r lcov report"
1111
},
1212
"devDependencies": {
13+
"@istanbuljs/nyc-config-typescript": "^1.0.2",
1314
"@types/chai": "^4.3.3",
1415
"@types/mocha": "^9.1.1",
1516
"@types/node": "^17.0.23",
@@ -23,12 +24,16 @@
2324
"eslint-plugin-import": "^2.26.0",
2425
"mocha": "^10.0.0",
2526
"nyc": "^15.1.0",
27+
"ts-node": "^10.9.1",
2628
"typescript": "^4.5.4"
2729
},
2830
"dependencies": {
2931
"axios": "^0.24.0",
3032
"uuid": "^8.3.2"
3133
},
34+
"optionalDependencies": {
35+
"subtitle": "^4.2.1"
36+
},
3237
"keywords": [
3338
"nlp",
3439
"language",
@@ -61,7 +66,19 @@
6166
"analytics"
6267
],
6368
"license": "MIT",
64-
"optionalDependencies": {
65-
"subtitle": "^4.2.1"
69+
"nyc": {
70+
"extends": "@istanbuljs/nyc-config-typescript",
71+
"check-coverage": true,
72+
"all": true,
73+
"include": [
74+
"src/**/*.ts"
75+
],
76+
"reporter": [
77+
"html",
78+
"lcov",
79+
"text",
80+
"text-summary"
81+
],
82+
"report-dir": "coverage"
6683
}
6784
}

src/api/.uuid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7d1e12c120cc4898ab58ad37370520bf

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ class OneAI {
8686

8787
parsing: {
8888
parseConversation: (input: string) => ConversationContent,
89-
toSRT: (output: Output) => string,
89+
toSRT: (
90+
output: Output,
91+
params?: {
92+
maxLengthWords?: number,
93+
maxLengthCharacters?: number,
94+
},
95+
) => string,
9096
} = {
9197
parseConversation,
9298
toSRT,

test/clustering.js renamed to test/clustering.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable no-restricted-syntax */
2-
const { describe, it } = require('mocha');
3-
const { expect } = require('chai');
4-
const oneai = require('./testClient');
2+
import { expect } from 'chai';
3+
import oneai from './testClient';
54

65
describe('Clustering', () => {
76
it('collection', async () => {

test/files.js renamed to test/files.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const { expect } = require('chai');
2-
const { describe, it } = require('mocha');
3-
const constants = require('./constants.json');
4-
const oneai = require('./testClient');
1+
import { expect } from 'chai';
2+
import constants from './constants.json';
3+
import oneai from './testClient';
54

65
describe('audio', () => {
76
const pipeline = new oneai.Pipeline(
@@ -13,7 +12,7 @@ describe('audio', () => {
1312
oneai.skills.emotions(),
1413
);
1514

16-
function testFile(input, sync) {
15+
function testFile(input: string, sync: boolean) {
1716
return async () => {
1817
const output = await pipeline.runFile(input, { sync }); // true by default
1918

test/parsing.js renamed to test/parsing.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* eslint-disable no-unused-expressions */
2-
const { expect } = require('chai');
3-
const { describe, it } = require('mocha');
4-
const { conversationParsingTests } = require('./constants.json');
5-
const transcriptionOutput = require('./transcriptionOutput.json');
6-
const oneai = require('./testClient');
2+
import { expect } from 'chai';
3+
import { describe, it } from 'mocha';
4+
import { conversationParsingTests } from './constants.json';
5+
import transcriptionOutput from './transcriptionOutput.json';
6+
import oneai from './testClient';
77

88
describe('parseConversation', () => {
99
conversationParsingTests.forEach((test, index) => {
1010
it(`test ${index} - ${test.desc}`, () => {
11-
let parsed;
11+
let parsed: any;
1212
try {
1313
parsed = oneai.parsing.parseConversation(test.text);
1414
} catch (e) {
@@ -30,7 +30,7 @@ describe('parseConversation', () => {
3030

3131
describe('subtitle', () => {
3232
it('srt', () => {
33-
const parsed = oneai.parsing.toSRT(transcriptionOutput, { maxLengthCharacters: 30 });
33+
const parsed = oneai.parsing.toSRT(transcriptionOutput as any, { maxLengthCharacters: 30 });
3434
console.log(parsed);
3535
});
3636
});

test/pipeline.js renamed to test/pipeline.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const { expect } = require('chai');
2-
const { describe, it } = require('mocha');
3-
const constants = require('./constants.json');
4-
const oneai = require('./testClient');
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { TextContent } from '../src/classes';
4+
import constants from './constants.json';
5+
import oneai from './testClient';
56

67
describe('Pipeline', () => {
78
const pipeline = new oneai.Pipeline(
@@ -13,7 +14,7 @@ describe('Pipeline', () => {
1314
);
1415

1516
describe('single input', () => {
16-
function testInput(input) {
17+
function testInput(input: TextContent) {
1718
return async () => {
1819
const output = await pipeline.run(input);
1920

test/testClient.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/testClient.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as dotenv from 'dotenv';
2+
import OneAI from '../src/index';
3+
4+
dotenv.config();
5+
export default new OneAI(process.env.API_KEY);

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
"esModuleInterop": true
1313
},
1414
"include": ["src"],
15-
"exclude": ["node_modules", "**/__tests__/*"]
15+
"exclude": ["node_modules", "**/__tests__/*"],
16+
"ts-node": {
17+
"files": true
18+
}
1619
}

0 commit comments

Comments
 (0)