forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement
--shard
option (jestjs#12546)
- Loading branch information
Showing
27 changed files
with
592 additions
and
79 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
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,86 @@ | ||
/** | ||
* 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 * as path from 'path'; | ||
import runJest from '../runJest'; | ||
|
||
test('--shard=1/1', () => { | ||
const result = runJest('shard', ['--shard=1/1', '--listTests']); | ||
|
||
const paths = result.stdout | ||
.split('\n') | ||
.filter(Boolean) | ||
.map(file => path.basename(file)) | ||
.sort(); | ||
|
||
expect(paths).toEqual(['1.test.js', '2.test.js', '3.test.js']); | ||
}); | ||
|
||
test('--shard=1/2', () => { | ||
const result = runJest('shard', ['--shard=1/2', '--listTests']); | ||
|
||
const paths = result.stdout | ||
.split('\n') | ||
.filter(Boolean) | ||
.map(file => path.basename(file)) | ||
.sort(); | ||
|
||
expect(paths).toEqual(['1.test.js', '3.test.js']); | ||
}); | ||
|
||
test('--shard=2/2', () => { | ||
const result = runJest('shard', ['--shard=2/2', '--listTests']); | ||
|
||
const paths = result.stdout | ||
.split('\n') | ||
.filter(Boolean) | ||
.map(file => path.basename(file)); | ||
|
||
expect(paths).toEqual(['2.test.js']); | ||
}); | ||
|
||
test('--shard=4/4', () => { | ||
const result = runJest('shard', ['--shard=4/4', '--listTests']); | ||
|
||
const paths = result.stdout | ||
.split('\n') | ||
.filter(Boolean) | ||
.map(file => path.basename(file)); | ||
|
||
// project only has 3 files | ||
// shards > 3 are empty | ||
expect(paths).toEqual([]); | ||
}); | ||
|
||
test('--shard=1/2 custom non-sharding test sequencer', () => { | ||
const result = runJest('shard', [ | ||
'--shard=1/2', | ||
'--listTests', | ||
'--testSequencer=./no-sharding-test-sequencer.js', | ||
]); | ||
|
||
expect(result).toMatchObject({ | ||
failed: true, | ||
stderr: expect.stringMatching( | ||
/Shard (.*) requested, but test sequencer (.*) in (.*) has no shard method./, | ||
), | ||
}); | ||
}); | ||
|
||
test('--shard=1/2 custom sharding test sequencer', () => { | ||
const result = runJest('shard', [ | ||
'--shard=1/2', | ||
'--listTests', | ||
'--testSequencer=./sharding-test-sequencer.js', | ||
]); | ||
|
||
const paths = result.stdout | ||
.split('\n') | ||
.filter(Boolean) | ||
.map(file => path.basename(file)); | ||
|
||
expect(paths).toEqual(['3.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,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. | ||
*/ | ||
'use strict'; | ||
|
||
test('1-1', () => expect(2).toBe(2)); | ||
|
||
test('1-2', () => expect(2).toBe(2)); | ||
|
||
test('1-3', () => expect(2).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. | ||
*/ | ||
'use strict'; | ||
|
||
test('2-1', () => expect(2).toBe(2)); | ||
|
||
test('2-2', () => expect(2).toBe(2)); | ||
|
||
test('2-3', () => expect(2).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. | ||
*/ | ||
'use strict'; | ||
|
||
test('3-1', () => expect(2).toBe(2)); | ||
|
||
test('3-2', () => expect(2).toBe(2)); | ||
|
||
test('3-3', () => expect(2).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,11 @@ | ||
/** | ||
* 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 = class NoShardingSequencer { | ||
sort(tests) { | ||
return tests; | ||
} | ||
}; |
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,5 @@ | ||
{ | ||
"jest": { | ||
"testEnvironment": "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,18 @@ | ||
/** | ||
* 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 = class NoShardingSequencer { | ||
shard(tests) { | ||
return [ | ||
Array.from(tests).sort((a, b) => | ||
a.path < b.path ? -1 : a.path > b.path ? 1 : 0, | ||
)[2], | ||
]; | ||
} | ||
sort(tests) { | ||
return tests; | ||
} | ||
}; |
Oops, something went wrong.