Skip to content

Commit 43d8bc7

Browse files
[test optimization][STV-59] Fix jest.mock for multi worker setups (#6729)
* fix listener * add integration test * add stdout check
1 parent 78dd563 commit 43d8bc7

File tree

12 files changed

+107
-1
lines changed

12 files changed

+107
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict'
2+
3+
// This is to check that the actual package is loaded, to make sure
4+
// that the scenario is the same as the one that was failing.
5+
// Doing it in one of the test suites is enough, as the failure was
6+
// when calling jest.mock('some-package')
7+
const hello = jest.requireActual('some-package')
8+
9+
test('hello function returns correct greeting', () => {
10+
expect(hello()).toBe('Hello, world!')
11+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict'
2+
3+
const hello = require('some-package')
4+
5+
test('hello function returns correct greeting', () => {
6+
expect(hello()).toBe('Hello, mocked world!')
7+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict'
2+
3+
const hello = require('some-package')
4+
5+
test('hello function returns correct greeting', () => {
6+
expect(hello()).toBe('Hello, mocked world!')
7+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict'
2+
3+
const hello = require('some-package')
4+
5+
test('hello function returns correct greeting', () => {
6+
expect(hello()).toBe('Hello, mocked world!')
7+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict'
2+
3+
const hello = require('some-package')
4+
5+
test('hello function returns correct greeting', () => {
6+
expect(hello()).toBe('Hello, mocked world!')
7+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict'
2+
3+
const hello = require('some-package')
4+
5+
test('hello function returns correct greeting', () => {
6+
expect(hello()).toBe('Hello, mocked world!')
7+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
jest.mock('some-package', () => {
4+
return jest.fn(() => 'Hello, mocked world!')
5+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
module.exports = function () {
4+
return 'Hello, world!'
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "some-package",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT"
6+
}

integration-tests/ci-visibility/run-jest.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const options = {
99
testRegex: process.env.TESTS_TO_RUN ? new RegExp(process.env.TESTS_TO_RUN) : /test\/ci-visibility-test/,
1010
coverage: !!process.env.ENABLE_CODE_COVERAGE,
1111
runInBand: true,
12-
shard: process.env.TEST_SHARD || undefined
12+
shard: process.env.TEST_SHARD || undefined,
13+
setupFilesAfterEnv: process.env.SETUP_FILES_AFTER_ENV ? process.env.SETUP_FILES_AFTER_ENV.split(',') : []
1314
}
1415

1516
if (process.env.RUN_IN_PARALLEL) {

0 commit comments

Comments
 (0)