@@ -1771,53 +1771,145 @@ QUnit.test( "html(Function)", function( assert ) {
17711771 testHtml ( manipulationFunctionReturningObj , assert ) ;
17721772} ) ;
17731773
1774- // Support: IE 9 - 11+
1775- // IE doesn't support modules.
1776- QUnit . testUnlessIE ( "html(script type module)" , function ( assert ) {
1777- assert . expect ( 4 ) ;
1778- var done = assert . async ( ) ,
1779- $fixture = jQuery ( "#qunit-fixture" ) ;
1774+ ( function ( ) {
1775+ function setup ( options ) {
1776+ var timeoutId ,
1777+ assert = options . assert ,
1778+ done = options . done ,
1779+ expectedCount = options . expectedCount == null ? 1 : options . expectedCount ,
1780+ timeout = options . timeout ,
1781+ verified = false ,
1782+ calls = {
1783+ outerExternal : 0 ,
1784+ innerExternal : 0 ,
1785+ outerInline : 0 ,
1786+ innerInline : 0
1787+ } ;
17801788
1781- $fixture . html (
1782- [
1783- "<script type='module'>QUnit.assert.ok( true, 'evaluated: module' );</script>" ,
1784- "<script type='module' src='" + url ( "module.js" ) + "'></script>" ,
1785- "<div>" ,
1786- "<script type='module'>QUnit.assert.ok( true, 'evaluated: inner module' );</script>" ,
1787- "<script type='module' src='" + url ( "inner_module.js" ) + "'></script>" ,
1788- "</div>"
1789- ] . join ( "" )
1790- ) ;
1789+ function verify ( force ) {
1790+ var i ;
1791+ if ( verified ) {
1792+ return ;
1793+ }
17911794
1792- // Allow asynchronous script execution to generate assertions
1793- setTimeout ( function ( ) {
1794- done ( ) ;
1795- } , 1000 ) ;
1796- } ) ;
1795+ if ( ! force ) {
1796+ for ( i in calls ) {
17971797
1798- QUnit . test ( "html(script nomodule)" , function ( assert ) {
1798+ // Not ready yet, we'll check later.
1799+ // If we're checking for 0, we don't know when to check, so
1800+ // wait until we force it.
1801+ if ( calls [ i ] !== expectedCount || calls [ i ] === 0 ) {
1802+ return ;
1803+ }
1804+ }
1805+ }
17991806
1800- // `nomodule` scripts should be executed by legacy browsers only.
1801- assert . expect ( QUnit . isIE ? 4 : 0 ) ;
1802- var done = assert . async ( ) ,
1803- $fixture = jQuery ( "#qunit-fixture" ) ;
1807+ verified = true ;
18041808
1805- $fixture . html (
1806- [
1807- "<script nomodule>QUnit.assert.ok( QUnit.isIE, 'evaluated: nomodule script' );</script>" ,
1808- "<script nomodule src='" + url ( "nomodule.js" ) + "'></script>" ,
1809- "<div>" ,
1810- "<script nomodule>QUnit.assert.ok( QUnit.isIE, 'evaluated: inner nomodule script' );</script>" ,
1811- "<script nomodule src='" + url ( "inner_nomodule.js" ) + "'></script>" ,
1812- "</div>"
1813- ] . join ( "" )
1814- ) ;
1809+ assert . strictEqual ( calls . outerExternal , expectedCount ,
1810+ "Expected number of outer external calls: " + expectedCount ) ;
1811+ assert . strictEqual ( calls . innerExternal , expectedCount ,
1812+ "Expected number of inner external calls: " + expectedCount ) ;
1813+ assert . strictEqual ( calls . outerInline , expectedCount ,
1814+ "Expected number of outer inline calls: " + expectedCount ) ;
1815+ assert . strictEqual ( calls . innerInline , expectedCount ,
1816+ "Expected number of inner inline calls: " + expectedCount ) ;
18151817
1816- // Allow asynchronous script execution to generate assertions
1817- setTimeout ( function ( ) {
1818- done ( ) ;
1819- } , 1000 ) ;
1820- } ) ;
1818+ clearInterval ( timeoutId ) ;
1819+ done ( ) ;
1820+ }
1821+
1822+ Globals . register ( "outerExternalCallback" ) ;
1823+ Globals . register ( "innerExternalCallback" ) ;
1824+ Globals . register ( "outerInlineCallback" ) ;
1825+ Globals . register ( "innerInlineCallback" ) ;
1826+
1827+ window . outerExternalCallback = function ( message ) {
1828+ if ( message ) {
1829+ assert . ok ( true , message ) ;
1830+ }
1831+ calls . outerExternal ++ ;
1832+ verify ( ) ;
1833+ } ;
1834+ window . innerExternalCallback = function ( message ) {
1835+ if ( message ) {
1836+ assert . ok ( true , message ) ;
1837+ }
1838+ calls . innerExternal ++ ;
1839+ verify ( ) ;
1840+ } ;
1841+ window . outerInlineCallback = function ( message ) {
1842+ if ( message ) {
1843+ assert . ok ( true , message ) ;
1844+ }
1845+ calls . outerInline ++ ;
1846+ verify ( ) ;
1847+ } ;
1848+ window . innerInlineCallback = function ( message ) {
1849+ if ( message ) {
1850+ assert . ok ( true , message ) ;
1851+ }
1852+ calls . innerInline ++ ;
1853+ verify ( ) ;
1854+ } ;
1855+
1856+ // Give some time for async script execution before forcing verification.
1857+ timeoutId = setTimeout ( function ( ) {
1858+ verify ( true ) ;
1859+ } , timeout ) ;
1860+ }
1861+
1862+ // Support: IE 9 - 11+
1863+ // IE doesn't support modules.
1864+ QUnit . testUnlessIE ( "html(script type module)" , function ( assert ) {
1865+ assert . expect ( 8 ) ;
1866+ var done = assert . async ( ) ,
1867+ $fixture = jQuery ( "#qunit-fixture" ) ;
1868+
1869+ setup ( {
1870+ assert : assert ,
1871+ done : done ,
1872+ timeout : 5000
1873+ } ) ;
1874+
1875+ $fixture . html (
1876+ [
1877+ "<script type='module'>outerInlineCallback( 'evaluated: module' );</script>" ,
1878+ "<script type='module' src='" + url ( "module.js" ) + "'></script>" ,
1879+ "<div>" ,
1880+ "<script type='module'>innerInlineCallback( 'evaluated: inner module' );</script>" ,
1881+ "<script type='module' src='" + url ( "inner_module.js" ) + "'></script>" ,
1882+ "</div>"
1883+ ] . join ( "" )
1884+ ) ;
1885+ } ) ;
1886+
1887+ QUnit . test ( "html(script nomodule)" , function ( assert ) {
1888+
1889+ // `nomodule` scripts should be executed by legacy browsers only.
1890+ assert . expect ( QUnit . isIE ? 8 : 4 ) ;
1891+ var done = assert . async ( ) ,
1892+ $fixture = jQuery ( "#qunit-fixture" ) ;
1893+
1894+ setup ( {
1895+ assert : assert ,
1896+ done : done ,
1897+ timeout : 1000 ,
1898+ expectedCount : QUnit . isIE ? 1 : 0
1899+ } ) ;
1900+
1901+ $fixture . html (
1902+ [
1903+ "<script nomodule>outerInlineCallback( 'evaluated: nomodule script' );</script>" ,
1904+ "<script nomodule src='" + url ( "nomodule.js" ) + "'></script>" ,
1905+ "<div>" ,
1906+ "<script nomodule>innerInlineCallback( 'evaluated: inner nomodule script' );</script>" ,
1907+ "<script nomodule src='" + url ( "inner_nomodule.js" ) + "'></script>" ,
1908+ "</div>"
1909+ ] . join ( "" )
1910+ ) ;
1911+ } ) ;
1912+ } ) ( ) ;
18211913
18221914QUnit . test ( "html(self-removing script) (gh-5377)" , function ( assert ) {
18231915 assert . expect ( 2 ) ;
0 commit comments