-
Notifications
You must be signed in to change notification settings - Fork 2k
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
ci(e2e): Migrate tests to Jest #53702
Closed
Closed
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
7a0237b
Debug test capture
scinos 174d21b
Fix path
scinos 4692b5b
Use sync
scinos 4569673
Move eslint config to test/e2e
scinos ea469c7
Migrate Calypso e2e tests to Jest
scinos d5e526e
Run jest test instead of magellan
scinos 59712ea
Add script to update chromedriver
scinos 86682f9
Do not use this.
scinos 215bde8
Run tests in verbose mode
scinos 802081a
Use jest-circus and custom environment to implement fail fast
scinos bfd96f6
Restore missing tests
scinos aaf2109
Restore skipped test
scinos f31b7cf
Run Mobile tests using jest as well
scinos 056bf1d
Drop noisy log
scinos df2e814
Add TEAMCITY_VERSION env var
scinos 3178b92
Use hooks
scinos b81a2f7
Fix typo in push
scinos c471950
Add missing imports
scinos 88395b8
Save logs in test directory
scinos 8aa5e3d
Fix prettier errors
scinos 92a1c25
Fix more eslint errors
scinos a5b4965
Fix typo in parameters
scinos 1f0d5ba
Move config files
scinos 81d103d
USe hyphen for file names
scinos 2695b51
Save test status and name in the global scope
scinos db37a23
Harden closing ffVideo
scinos a3ba2ff
Add more debug options
scinos 3d61c18
Get test name from expect state
scinos 511a5a9
Create results dir
scinos 6f4e443
Use APIs correctly
scinos 95641b9
Make takeScreenshot more robust
scinos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module.exports = { | ||
env: { | ||
node: true, | ||
mocha: false, | ||
}, | ||
overrides: [ | ||
{ | ||
plugins: [ 'mocha' ], | ||
files: [ | ||
'test/e2e/specs/specs-jetpack/*', | ||
'test/e2e/specs/specs-playwright/*', | ||
'test/e2e/specs/specs-wpcom/*', | ||
], | ||
rules: { | ||
'mocha/no-exclusive-tests': 'error', | ||
'mocha/handle-done-callback': [ 'error', { ignoreSkipped: true } ], | ||
'mocha/no-global-tests': 'error', | ||
'mocha/no-async-describe': 'error', | ||
'mocha/no-top-level-hooks': 'error', | ||
'mocha/max-top-level-suites': [ 'error', { limit: 1 } ], | ||
// Disable all rules from "plugin:jest/recommended", as e2e tests use mocha | ||
...Object.keys( require( 'eslint-plugin-jest' ).configs.recommended.rules ).reduce( | ||
( disabledRules, key ) => ( { ...disabledRules, [ key ]: 'off' } ), | ||
{} | ||
), | ||
}, | ||
globals: { | ||
step: false, | ||
}, | ||
}, | ||
], | ||
rules: { | ||
'import/no-nodejs-modules': 'off', | ||
'no-console': 'off', | ||
|
||
// We have many tests that don't make an explicit `expect`, but instead puts the browser | ||
// in certain state that will be used by the next test, or asserted by WebDriver | ||
'jest/expect-expect': 'off', | ||
}, | ||
}; |
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,12 @@ | ||
module.exports = { | ||
cacheDirectory: '<rootDir>/../../.cache/jest', | ||
testMatch: [ '<rootDir>/specs/**/*.js' ], | ||
globalSetup: '<rootDir>/lib/jest/jest-global-setup.js', | ||
setupFilesAfterEnv: [ '<rootDir>/lib/jest/jest-setup.js', '<rootDir>/lib/hooks/jest.js' ], | ||
verbose: true, | ||
transform: { | ||
'\\.[jt]sx?$': [ 'babel-jest', { configFile: '../../babel.config.js' } ], | ||
}, | ||
testRunner: 'jest-circus/runner', | ||
testEnvironment: '<rootDir>/lib/jest/jest-environment-e2e.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
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,60 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import config from 'config'; | ||
import path from 'path'; | ||
import { mkdtemp, mkdir } from 'fs/promises'; | ||
import { getState } from 'expect'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { buildHooks as buildVideoHooks, isVideoEnabled } from './video'; | ||
import { buildHooks as buildBrowserHooks } from './browser'; | ||
|
||
let tempDir; | ||
let driver; | ||
const startBrowserTimeoutMS = config.get( 'startBrowserTimeoutMS' ); | ||
const browserHooks = buildBrowserHooks(); | ||
const videoHooks = isVideoEnabled() ? buildVideoHooks() : null; | ||
|
||
beforeAll( async () => { | ||
const { testPath } = getState(); | ||
|
||
const sanitizedTestFilename = path.basename( testPath, path.extname( testPath ) ); | ||
const resultsPath = path.join( __dirname, '../../results' ); | ||
await mkdir( resultsPath, { recursive: true } ); | ||
tempDir = await mkdtemp( path.join( resultsPath, sanitizedTestFilename + '-' ) ); | ||
|
||
if ( isVideoEnabled() ) { | ||
await videoHooks.startFramebuffer(); | ||
await videoHooks.startVideoRecording( { tempDir } ); | ||
} | ||
|
||
driver = await browserHooks.createBrowser( { tempDir } ); | ||
global.__BROWSER__ = driver; | ||
}, startBrowserTimeoutMS ); | ||
|
||
afterAll( async () => { | ||
if ( isVideoEnabled() ) { | ||
if ( global.__CURRENT_TEST_FAILED__ ) { | ||
// Sometimes chrome crashes mid test. By wraping `takeScreenshot` in a try/catch we ensure | ||
// we at least get a video recording | ||
try { | ||
videoHooks.takeScreenshot( { | ||
tempDir, | ||
testName: global.__CURRENT_TEST_NAME__, | ||
driver: driver, | ||
} ); | ||
} catch {} | ||
|
||
await videoHooks.saveVideoRecording( { tempDir, testName: global.__CURRENT_TEST_NAME__ } ); | ||
} | ||
|
||
await videoHooks.stopFramebuffer(); | ||
await videoHooks.stopVideoRecording(); | ||
} | ||
|
||
await browserHooks.saveBrowserLogs( { tempDir } ); | ||
await browserHooks.closeBrowser(); | ||
} ); |
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,34 @@ | ||
const JestEnvironmentNode = require( 'jest-environment-node' ); | ||
|
||
class JestEnvironmentE2E extends JestEnvironmentNode { | ||
testFailed = false; | ||
|
||
async handleTestEvent( event ) { | ||
// Top describe (event.describeBlock.name) | ||
// event.type=="run_describe_start" && event.describeBlock.parent.name === "ROOT_DESCRIBE_BLOCK" | ||
|
||
// Test (event.test.name) | ||
// | ||
|
||
// Save reference to current test | ||
if ( event.name === 'test_start' ) { | ||
this.global.__CURRENT_TEST_NAME__ = event.test.name; | ||
return; | ||
} | ||
|
||
// If a hook or a test fails, enter in "failed mode" | ||
if ( event.name === 'hook_failure' || event.name === 'test_fn_failure' ) { | ||
this.global.__CURRENT_TEST_FAILED__ = true; | ||
this.testFailed = true; | ||
return; | ||
} | ||
|
||
// If a test starts after a test has already failed, skip it | ||
if ( this.testFailed && event.name === 'test_start' ) { | ||
event.test.mode = 'skip'; | ||
return; | ||
} | ||
} | ||
} | ||
|
||
module.exports = JestEnvironmentE2E; |
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,17 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { node } from 'execa'; | ||
|
||
module.exports = async () => { | ||
// Update chromedriver | ||
const subprocess = node( require.resolve( 'chromedriver/install.js' ), { | ||
env: { | ||
CHROMEDRIVER_SKIP_DOWNLOAD: false, | ||
DETECT_CHROMEDRIVER_VERSION: true, | ||
}, | ||
} ); | ||
subprocess.stdout.pipe( process.stdout ); | ||
subprocess.stderr.pipe( process.stderr ); | ||
await subprocess; | ||
}; |
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 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import config from 'config'; | ||
|
||
// Default timeout | ||
jest.setTimeout( config.get( 'jestTimeoutMS' ) ); |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Enable
mocha
and disablejest
plugin & rules for these paths