Skip to content

Commit

Permalink
scaffold: refactor (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae authored Oct 20, 2024
1 parent efce891 commit a76e7f2
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions tests/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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' );
};

0 comments on commit a76e7f2

Please sign in to comment.