diff --git a/tests/scaffold.js b/tests/scaffold.js index 3979a214..9cf12d4d 100644 --- a/tests/scaffold.js +++ b/tests/scaffold.js @@ -6,12 +6,39 @@ /* eslint-env jest, node */ -jest.autoMockOff(); +const resetToBase = function () { + const fileSystem = require( 'fs' ); + const basePageHtml = fileSystem.readFileSync( './tests/test-frame.html' ).toString(); + // Set the base document content using jsdom + document.documentElement.innerHtml = basePageHtml; + AFCH = undefined; + $ = require( 'jquery' ); + jQuery = $; +}; -const fs = require( 'fs' ); +const setPageTitle = function ( title ) { + mw.config.get.mockImplementation( ( requested ) => { + if ( requested === 'wgPageName' ) { + return title; + } else if ( requested === 'wgNamespaceNumber' ) { + if ( title.indexOf( 'Draft:' ) === 0 ) { + return 118; + } + } + } ); +}; + +resetToAFCApplicablePage = function () { + resetToBase(); + setPageTitle( 'Draft:Foo' ); + require( './../src/afch.js' ); +}; + +jest.autoMockOff(); // Mocked later -mediaWiki = mw = {}; +mw = {}; +mediaWiki = {}; // We're always mocking this, what the heck mw.config = { @@ -32,31 +59,4 @@ mw.loader = { } }; -const basePageHtml = fs.readFileSync( './tests/test-frame.html' ).toString(); - -const setPageTitle = function ( title ) { - mw.config.get.mockImplementation( ( requested ) => { - if ( requested === 'wgPageName' ) { - return title; - } else if ( requested === 'wgNamespaceNumber' ) { - if ( title.indexOf( 'Draft:' ) === 0 ) { - return 118; - } - } - } ); -}; - -const resetToBase = function () { - // Set the base document content using jsdom - document.documentElement.innerHtml = basePageHtml; - AFCH = undefined; - jQuery = $ = require( 'jquery' ); -}; - resetToBase(); - -resetToAFCApplicablePage = function () { - resetToBase(); - setPageTitle( 'Draft:Foo' ); - require( './../src/afch.js' ); -};