Question: Jest + Typescript + threads.js how can it work together ?
- Langage dominant
- TypeScript
- Étoiles
- 3.5k
- Forks
- 173
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
I have implemented threads.js in my "vue + typescript + electron" project and it works, but my test now fails with the error:
```
pinguSync\src\backend\controller\main-list-manager\worker\main-list-search-id-worker.ts:1
import { expose } from 'threads/worker';
^^^^^^
SyntaxError: Cannot use import statement outside a moduleJest
```
"worker.ts":
```
import { expose } from 'threads/worker';
import Series from '../../objects/series';
const worker = function findSeriesById(buffer: Series[], id: string): Series | null {
return buffer.find(x => x.id === id) ?? null;
};
export type MainListSearchIdWorker = typeof worker;
expose(worker);
```
"main":
```
public static async findSeriesById(id: string): Promise {
const worker = await spawn(new Worker('./worker/main-list-search-id-worker.ts'));
return worker(MainListManager.getMainList(), id);
}
```
"test":
```
describe('test fn: findSeriesById', () => {
test('should find Series by Id', async () => {
const series = new Series();
MainListManager['mainList'].push(series);
const result = await MainListSearcher.findSeriesById(series.id);
expect(result?.id).toBe(series.id);
});
test('should return on no result', async () => {
const result = await MainListSearcher.findSeriesById('id');
expect(result).toBeNull();
});
});
```
(You can turn Series to a object with just a id for reproducing):
`{id:''}
`
JestConfig:
```
'use strict';
module.exports = {
'roots': [
''
],
'testMatch': [
'**/test/**/*-(test|tests).+(ts|tsx|js)',
],
'transform': {
'\\.(gql|graphql)$': '@jagi/jest-transform-graphql',
'^.+\\.(ts|tsx)$': 'ts-jest'
},
'reporters': [
'default',
['jest-html-reporters', {
'publicPath': './html-report',
'filename': 'report.html',
'expand': true
}]
],
'testTimeout': 3500,
'verbose': false,
'globals': {
'ts-jest': {
babelConfig: true,
}
},
'testEnvironment': 'node',
'setupFilesAfterEnv': ['/test/test-helper.ts'],
'maxWorkers': 6
};
```
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Évaluation
Cette issue n'a pas encore été évaluée.