mirror of
https://github.com/zoriya/srt-webvtt.git
synced 2025-12-06 05:56:10 +00:00
chore(): add test cases and adjust ci
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "5"
|
||||
- "12.14.1"
|
||||
script:
|
||||
- npm run lint
|
||||
- npm test
|
||||
- npm run build
|
||||
|
||||
36
index.spec.ts
Normal file
36
index.spec.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { TextDecoder } from 'util'
|
||||
import { default as WebVTT, moduleName } from './index'
|
||||
|
||||
describe('WebVTT', () => {
|
||||
let file: Blob;
|
||||
|
||||
beforeEach(() => {
|
||||
file = new Blob([new Uint8Array([])], { type: 'text/plain' });
|
||||
(global as any).TextDecoder = TextDecoder;
|
||||
(global.URL as any).createObjectURL = jest.fn().mockImplementation((text) => 'blob:some-valid-url');
|
||||
})
|
||||
|
||||
it('should return a promise', () => {
|
||||
expect(WebVTT(file)).toBeInstanceOf(Promise);
|
||||
});
|
||||
it('should return a valid return', async () => {
|
||||
expect(await WebVTT(file)).toBe('blob:some-valid-url');
|
||||
});
|
||||
it('should throw if undefined or wrong resource provided', async () => {
|
||||
try {
|
||||
const webVtt = await WebVTT(undefined as any);
|
||||
} catch (e: any) {
|
||||
expect(e.message).toContain(moduleName);
|
||||
expect(e.message).toContain('Blob');
|
||||
}
|
||||
});
|
||||
it('should throw TextDecoder is not defined', async () => {
|
||||
(global as any).TextDecoder = undefined;
|
||||
try {
|
||||
const webVtt = await WebVTT(file);
|
||||
} catch (e: any) {
|
||||
expect(e.message).toContain(moduleName);
|
||||
expect(e.message).toContain('TextDecoder');
|
||||
}
|
||||
});
|
||||
});
|
||||
4
index.ts
4
index.ts
@@ -1,4 +1,4 @@
|
||||
const moduleName = 'toWebVTT';
|
||||
export const moduleName = 'toWebVTT';
|
||||
|
||||
const blobToBufferOrString = (blob: Blob, readAs: 'string' | 'buffer'): Promise<Uint8Array | String> =>
|
||||
new Promise((resolve, reject) => {
|
||||
@@ -42,7 +42,7 @@ const toWebVTT = async (resource: Blob): Promise<string> => {
|
||||
throw (new Error(`${moduleName}: No TextDecoder constructor found`));
|
||||
}
|
||||
if (!(resource instanceof Blob)) {
|
||||
throw (new Error(`${moduleName}: Expecting resource to be a Blob but something else found.`));
|
||||
throw new Error(`${moduleName}: Expecting resource to be a Blob but something else found.`);
|
||||
}
|
||||
let text;
|
||||
const vttString = 'WEBVTT FILE\r\n\r\n';
|
||||
|
||||
4
jest.config.js
Normal file
4
jest.config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'jsdom',
|
||||
};
|
||||
6257
package-lock.json
generated
Normal file
6257
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,8 @@
|
||||
"lib/index.d.ts"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "./node_modules/.bin/eslint ./index.js",
|
||||
"test": "./node_modules/.bin/jest",
|
||||
"lint": "./node_modules/.bin/eslint ./index.js",
|
||||
"build": "rm -rf lib && tsc",
|
||||
"minor": "npm version minor && npm publish",
|
||||
"major": "npm version major && npm publish",
|
||||
@@ -45,11 +46,14 @@
|
||||
},
|
||||
"homepage": "https://github.com/imshaikot/srt-webvtt#readme",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.2",
|
||||
"eslint": "^4.15.0",
|
||||
"eslint-config-airbnb": "^16.1.0",
|
||||
"eslint-plugin-import": "^2.8.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.0.3",
|
||||
"eslint-plugin-react": "^7.5.1",
|
||||
"jest": "^27.3.1",
|
||||
"ts-jest": "^27.0.7",
|
||||
"typescript": "^4.4.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist"
|
||||
"lib"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user