-
-
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: requireAndTranspileModule support ESM (#11232)
- Loading branch information
Showing
19 changed files
with
247 additions
and
130 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
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 |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
* | ||
*/ | ||
'use strict'; | ||
/* eslint-env browser*/ | ||
|
||
test('setup', () => { | ||
expect(global.setup).toBe('setup'); | ||
|
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,7 @@ | ||
{ | ||
"type": "module", | ||
"jest": { | ||
"rootDir": "./", | ||
"runner": "<rootDir>/runner.mjs" | ||
} | ||
} |
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,48 @@ | ||
/** | ||
* 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 testResult from '@jest/test-result'; | ||
|
||
const {createEmptyTestResult} = testResult; | ||
|
||
export default class BaseTestRunner { | ||
constructor(globalConfig, context) { | ||
this._globalConfig = globalConfig; | ||
this._context = context || {}; | ||
} | ||
|
||
async runTests(tests, watcher, onStart, onResult, onFailure) { | ||
return tests.reduce( | ||
(promise, test) => | ||
promise | ||
.then(async () => { | ||
await onStart(test); | ||
return { | ||
...createEmptyTestResult(), | ||
numPassingTests: 1, | ||
testFilePath: test.path, | ||
testResults: [ | ||
{ | ||
ancestorTitles: [], | ||
duration: 2, | ||
failureDetails: [], | ||
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(), | ||
); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
e2e/transform/transform-esm-testrunner/__tests__/add.test.js
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,7 @@ | ||
{ | ||
"type": "module", | ||
"jest": { | ||
"rootDir": "./", | ||
"testRunner": "<rootDir>/test-runner.mjs" | ||
} | ||
} |
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,35 @@ | ||
/** | ||
* 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 testResult from '@jest/test-result'; | ||
|
||
const {createEmptyTestResult} = testResult; | ||
|
||
export default async function testRunner( | ||
globalConfig, | ||
config, | ||
environment, | ||
runtime, | ||
testPath, | ||
) { | ||
return { | ||
...createEmptyTestResult(), | ||
numPassingTests: 1, | ||
testFilePath: testPath, | ||
testResults: [ | ||
{ | ||
ancestorTitles: [], | ||
duration: 2, | ||
failureMessages: [], | ||
fullName: 'sample test', | ||
location: null, | ||
numPassingAsserts: 1, | ||
status: 'passed', | ||
title: 'sample test', | ||
}, | ||
], | ||
}; | ||
} |
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
Oops, something went wrong.