@@ -1904,6 +1904,55 @@ if (requestedVersion === 'latest' &&
19041904 } )
19051905 } )
19061906
1907+ describe ( 'manual plugin' , ( ) => {
1908+ it ( 'runs the latest after:screenshot handler after user handlers' , async ( ) => {
1909+ const projectRoot = createProjectRoot ( )
1910+ const userHandler = sinon . stub ( ) . returns ( { path : 'updated.png' } )
1911+ const datadogHandler = sinon . stub ( )
1912+ const taskHandler = {
1913+ 'dd:testSuiteStart' : sinon . stub ( ) ,
1914+ 'dd:beforeEach' : sinon . stub ( ) ,
1915+ 'dd:afterEach' : sinon . stub ( ) ,
1916+ 'dd:addTags' : sinon . stub ( ) ,
1917+ }
1918+ const config = {
1919+ e2e : {
1920+ /**
1921+ * @param {Function } on Cypress event registration function
1922+ * @returns {void }
1923+ */
1924+ setupNodeEvents ( on ) {
1925+ on ( 'after:screenshot' , userHandler )
1926+ on ( 'after:screenshot' , datadogHandler )
1927+ on ( 'task' , taskHandler )
1928+ } ,
1929+ } ,
1930+ }
1931+ const handlers = { }
1932+ const { cypressConfig } = loadCypressConfig ( )
1933+
1934+ cypressConfig . wrapConfig ( config )
1935+ config . e2e . setupNodeEvents (
1936+ /**
1937+ * @param {string } event Cypress event name
1938+ * @param {Function } handler Cypress event handler
1939+ * @returns {void }
1940+ */
1941+ ( event , handler ) => {
1942+ handlers [ event ] = handler
1943+ } ,
1944+ { projectRoot, supportFile : false }
1945+ )
1946+
1947+ const details = { path : 'original.png' }
1948+ await handlers [ 'after:screenshot' ] ( details )
1949+ await handlers [ 'after:run' ] ( { } )
1950+
1951+ assert . strictEqual ( userHandler . calledOnceWithExactly ( details ) , true )
1952+ assert . strictEqual ( datadogHandler . calledOnceWithExactly ( { path : 'updated.png' } ) , true )
1953+ } )
1954+ } )
1955+
19071956 describe ( 'configuration wrapper' , ( ) => {
19081957 it ( 'falls back to the project root when the config directory is not writable' , ( ) => {
19091958 const projectRoot = createProjectRoot ( )
0 commit comments