-
-
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(jest-core): add support for
watchPlugins
written in ESM (#11315)
- Loading branch information
Showing
17 changed files
with
220 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* 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 {onNodeVersions} from '@jest/test-utils'; | ||
import {runContinuous} from '../runJest'; | ||
|
||
const testCompletedRE = /Ran all test suites./g; | ||
const numberOfTestRuns = (stderr: string): number => { | ||
const matches = stderr.match(testCompletedRE); | ||
return matches ? matches.length : 0; | ||
}; | ||
|
||
test.each(['js', 'cjs'])('supports %s watch plugins', async watchPluginDir => { | ||
const testRun = runContinuous(`watch-plugins/${watchPluginDir}`, [ | ||
'--watchAll', | ||
'--no-watchman', | ||
]); | ||
|
||
await testRun.waitUntil(({stderr}) => numberOfTestRuns(stderr) === 1); | ||
|
||
expect(testRun.getCurrentOutput().stdout.trim()).toBe('getUsageInfo'); | ||
|
||
await testRun.end(); | ||
}); | ||
|
||
onNodeVersions('^12.17.0 || >=13.2.0', () => { | ||
test.each(['mjs', 'js-type-module'])( | ||
'supports %s watch plugins', | ||
async watchPluginDir => { | ||
const testRun = runContinuous(`watch-plugins/${watchPluginDir}`, [ | ||
'--watchAll', | ||
'--no-watchman', | ||
]); | ||
|
||
await testRun.waitUntil(({stderr}) => numberOfTestRuns(stderr) === 1); | ||
|
||
expect(testRun.getCurrentOutput().stdout.trim()).toBe('getUsageInfo'); | ||
|
||
await testRun.end(); | ||
}, | ||
); | ||
}); |
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. | ||
*/ | ||
'use strict'; | ||
|
||
test('load watch plugin cjs', () => { | ||
expect(42).toEqual(42); | ||
}); |
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,22 @@ | ||
/** | ||
* 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. | ||
*/ | ||
class MyWatchPlugin { | ||
// Add hooks to Jest lifecycle events | ||
apply(jestHooks) { | ||
} | ||
|
||
// Get the prompt information for interactive plugins | ||
getUsageInfo(globalConfig) { | ||
console.log('getUsageInfo'); | ||
} | ||
|
||
// Executed when the key from `getUsageInfo` is input | ||
run(globalConfig, updateConfigAndRun) { | ||
} | ||
} | ||
|
||
module.exports = MyWatchPlugin; |
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": { | ||
"watchPlugins": ["./my-watch-plugin.cjs"] | ||
} | ||
} |
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. | ||
*/ | ||
'use strict'; | ||
|
||
test('load watch plugin js type module', () => { | ||
expect(42).toEqual(42); | ||
}); |
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,20 @@ | ||
/** | ||
* 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. | ||
*/ | ||
class MyWatchPlugin { | ||
// Add hooks to Jest lifecycle events | ||
apply(jestHooks) {} | ||
|
||
// Get the prompt information for interactive plugins | ||
getUsageInfo(globalConfig) { | ||
console.log('getUsageInfo'); | ||
} | ||
|
||
// Executed when the key from `getUsageInfo` is input | ||
run(globalConfig, updateConfigAndRun) {} | ||
} | ||
|
||
export default MyWatchPlugin; |
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 @@ | ||
{ | ||
"type": "module", | ||
"jest": { | ||
"watchPlugins": ["./my-watch-plugin.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,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. | ||
*/ | ||
'use strict'; | ||
|
||
test('load watch plugin js', () => { | ||
expect(42).toEqual(42); | ||
}); |
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,20 @@ | ||
/** | ||
* 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. | ||
*/ | ||
class MyWatchPlugin { | ||
// Add hooks to Jest lifecycle events | ||
apply(jestHooks) {} | ||
|
||
// Get the prompt information for interactive plugins | ||
getUsageInfo(globalConfig) { | ||
console.log('getUsageInfo'); | ||
} | ||
|
||
// Executed when the key from `getUsageInfo` is input | ||
run(globalConfig, updateConfigAndRun) {} | ||
} | ||
|
||
module.exports = MyWatchPlugin; |
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": { | ||
"watchPlugins": ["./my-watch-plugin.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,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. | ||
*/ | ||
'use strict'; | ||
|
||
test('load watch plugin mjs', () => { | ||
expect(42).toEqual(42); | ||
}); |
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,22 @@ | ||
/** | ||
* 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. | ||
*/ | ||
class MyWatchPlugin { | ||
// Add hooks to Jest lifecycle events | ||
apply(jestHooks) { | ||
} | ||
|
||
// Get the prompt information for interactive plugins | ||
getUsageInfo(globalConfig) { | ||
console.log('getUsageInfo'); | ||
} | ||
|
||
// Executed when the key from `getUsageInfo` is input | ||
run(globalConfig, updateConfigAndRun) { | ||
} | ||
} | ||
|
||
export default MyWatchPlugin; |
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": { | ||
"watchPlugins": ["./my-watch-plugin.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
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