-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Programmatic API): Add programmatic API
Add a documented programmatic API to run jest. It allows this use case: ```ts import { run, readConfigs } from 'jest'; const { globalConfig, configs } = await readConfigs(process.argv, [process.cwd()]); // change globalConfig or configs as you see fit const results = await run(globalConfig, configs); console.log(results); ```
- Loading branch information
Showing
4 changed files
with
93 additions
and
39 deletions.
There are no files selected for viewing
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,36 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {tmpdir} from 'os'; | ||
import {resolve} from 'path'; | ||
import {makeGlobalConfig, makeProjectConfig} from '@jest/test-utils'; | ||
import {runCore} from '../'; | ||
import runJest from '../runJest'; | ||
|
||
jest.mock('jest-runtime', () => ({ | ||
createHasteMap: () => ({ | ||
build: jest.fn(), | ||
}), | ||
})); | ||
jest.mock('../lib/createContext', () => jest.fn()); | ||
jest.mock('../runJest', () => | ||
jest.fn(({onComplete}) => { | ||
onComplete({results: {success: true}}); | ||
}), | ||
); | ||
|
||
describe(runCore, () => { | ||
it('should run once and provide the result', async () => { | ||
const actualResult = await runCore(makeGlobalConfig(), [ | ||
makeProjectConfig({ | ||
cacheDirectory: resolve(tmpdir(), 'jest_runCore_test'), | ||
}), | ||
]); | ||
expect(jest.mocked(runJest)).toHaveBeenCalled(); | ||
expect(actualResult).toEqual({results: {success: true}}); | ||
}); | ||
}); |
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
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