andywer / andywer/threads.js

Question: Jest + Typescript + threads.js how can it work together ?

Aberta
#269 15 comentários 1 reação 0 responsáveis Ver no GitHub
question
Linguagem predominante
TypeScript
Estrelas
3.5k
Forks
173
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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
};

```

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.