-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: requireAndTranspileModule support ESM #11232
Changes from all commits
28b88d8
adf5307
6469e42
2ef8e02
9a394bd
5c0f7f3
2f5098d
409340e
8910f9d
99ce250
ed3b8c3
739a122
02a697a
7b721f1
a80b820
884c7e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'); | ||
|
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); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "module", | ||
"jest": { | ||
"rootDir": "./", | ||
"runner": "<rootDir>/runner.mjs" | ||
} | ||
} |
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; | ||||||||||
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
does this work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested. It worked. |
||||||||||
|
||||||||||
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(), | ||||||||||
); | ||||||||||
} | ||||||||||
} |
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); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "module", | ||
"jest": { | ||
"rootDir": "./", | ||
"testRunner": "<rootDir>/test-runner.mjs" | ||
} | ||
} |
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', | ||
}, | ||
], | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this (and the one in teardown) used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the directory is created in setup file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, but what is that directory used for? In the test it looks like it's created and deleted but never used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GlobalSetup/Teardown will read this directory and do some assertion.
If we don't clean directory before testing, it will failed in second round.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even after
884c7e0
(#11232)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
It fix #11267 globalSetup/globalTeardown e2e test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, gotcha!