-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: os api availability issue (#764)
* fix: os api availability issue * test: add compatibility test * build: upgrade dependencies
- Loading branch information
Showing
4 changed files
with
219 additions
and
165 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
__tests__/unit/lib/service/diffLineInterpreter-compatibility.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict' | ||
|
||
import { expect, jest, describe, it } from '@jest/globals' | ||
import { getGlobalMetadata, getWork } from '../../../__utils__/globalTestHelper' | ||
import DiffLineInterpreter from '../../../../src/service/diffLineInterpreter' | ||
import { Work } from '../../../../src/types/work' | ||
import { MetadataRepository } from '../../../../src/metadata/MetadataRepository' | ||
|
||
jest.mock('os', () => ({ | ||
availableParallelism: null, | ||
})) | ||
|
||
const mockHandle = jest.fn() | ||
jest.mock('../../../../src/service/typeHandlerFactory', () => { | ||
return jest.fn().mockImplementation(() => { | ||
return { | ||
getTypeHandler: jest | ||
.fn() | ||
.mockImplementation(() => ({ handle: mockHandle })), | ||
} | ||
}) | ||
}) | ||
|
||
let work: Work | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
work = getWork() | ||
}) | ||
|
||
describe('DiffLineInterpreter', () => { | ||
let sut: DiffLineInterpreter | ||
let globalMetadata: MetadataRepository | ||
beforeAll(async () => { | ||
// eslint-disable-next-line no-undef | ||
globalMetadata = await getGlobalMetadata() | ||
}) | ||
|
||
describe('compatibility test', () => { | ||
beforeEach(() => { | ||
sut = new DiffLineInterpreter(work, globalMetadata) | ||
}) | ||
describe('when `availableParallelism` is not defined', () => { | ||
it('fallback gracefully', async () => { | ||
// Arrange | ||
const lines = ['test'] | ||
|
||
// Act | ||
await sut.process(lines) | ||
|
||
// Assert | ||
expect(mockHandle).toBeCalledTimes(lines.length) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.