-
-
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: support for transforming runner (#8854)
- Loading branch information
Showing
10 changed files
with
139 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
it('should add two numbers', () => { | ||
expect(1 + 1).toBe(2); | ||
}); |
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,13 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', {targets: {node: 'current'}}], | ||
'@babel/preset-typescript', | ||
], | ||
}; |
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,11 @@ | ||
{ | ||
"jest": { | ||
"rootDir": "./", | ||
"runner": "<rootDir>/runner.ts" | ||
}, | ||
"dependencies": { | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/preset-typescript": "^7.0.0", | ||
"jest-environment-node": "file:../../../packages/jest-environment-node" | ||
} | ||
} |
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,69 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import throat from 'throat'; | ||
import {TestResult, createEmptyTestResult} from '@jest/test-result'; | ||
import type {Config} from '@jest/types'; | ||
import { | ||
OnTestFailure, | ||
OnTestStart, | ||
OnTestSuccess, | ||
Test, | ||
TestRunnerContext, | ||
TestWatcher, | ||
} from 'jest-runner'; | ||
|
||
export default class BaseTestRunner { | ||
private _globalConfig: Config.GlobalConfig; | ||
private _context: TestRunnerContext; | ||
|
||
constructor(globalConfig: Config.GlobalConfig, context?: TestRunnerContext) { | ||
this._globalConfig = globalConfig; | ||
this._context = context || {}; | ||
} | ||
|
||
async runTests( | ||
tests: Array<Test>, | ||
watcher: TestWatcher, | ||
onStart: OnTestStart, | ||
onResult: OnTestSuccess, | ||
onFailure: OnTestFailure, | ||
): Promise<void> { | ||
const mutex = throat(1); | ||
return tests.reduce( | ||
(promise, test) => | ||
mutex(() => | ||
promise | ||
.then( | ||
async (): Promise<TestResult> => { | ||
await onStart(test); | ||
return { | ||
...createEmptyTestResult(), | ||
numPassingTests: 1, | ||
testFilePath: test.path, | ||
testResults: [ | ||
{ | ||
ancestorTitles: [], | ||
duration: 2, | ||
failureMessages: [], | ||
fullName: 'sample test', | ||
location: null, | ||
numPassingAsserts: 1, | ||
status: 'passed', | ||
title: 'sample test', | ||
}, | ||
], | ||
}; | ||
}, | ||
) | ||
.then(result => onResult(test, result)) | ||
.catch(err => onFailure(test, err)), | ||
), | ||
Promise.resolve(), | ||
); | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"module": "commonjs", | ||
} | ||
} |
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